A little Home Assistant Mqtt integration using mqtt_as

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
rguillon
Posts: 8
Joined: Thu Aug 04, 2016 2:19 pm

A little Home Assistant Mqtt integration using mqtt_as

Post by rguillon » Mon Feb 08, 2021 7:47 pm

Hi all,

I've made a little library allowing me to interface a esp32 with home assistant using Peter Hinch's mqtt_as.

I have implemented switches, basic lights, lights with brightness and RGB lights. Devices are automatically registered into home assistant with mqtt discovery, allowing to create automations.

I tried to make something easy to extend, allowing to implement other kind devices. I use it to drive the lights of my fish-tanks, I plan to add temperature sensors next.

The code quality is questionable as I'm still new to python, but it works.

https://github.com/rguillon/hatank

kevinkk525
Posts: 868
Joined: Sat Feb 03, 2018 7:02 pm

Re: A little Home Assistant Mqtt integration using mqtt_as

Post by kevinkk525 » Tue Feb 09, 2021 6:09 am

That is a very nice first version!

By the way: I actually created a framework over the last few years with the exact same goal, integrating devices with home-assistant using mqtt_as with mqtt autodiscovery. It is more complex and powerful than yours, so maybe you can find some inspiration or some components you can reuse (e.g. I created climate components but have no lights, etc).
https://github.com/kevinkk525/pysmartnode
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

rguillon
Posts: 8
Joined: Thu Aug 04, 2016 2:19 pm

Re: A little Home Assistant Mqtt integration using mqtt_as

Post by rguillon » Tue Feb 09, 2021 7:42 pm

Thanks, that looks way more advanced than mine, I will definitely have a look.

rguillon
Posts: 8
Joined: Thu Aug 04, 2016 2:19 pm

Re: A little Home Assistant Mqtt integration using mqtt_as

Post by rguillon » Fri Feb 19, 2021 5:13 pm

I'm now using pysmartnode, thanks.

I ported my code into a new ComponentBase that was pretty easy to understand.

https://github.com/rguillon/pysmarttank

kevinkk525
Posts: 868
Joined: Sat Feb 03, 2018 7:02 pm

Re: A little Home Assistant Mqtt integration using mqtt_as

Post by kevinkk525 » Fri Feb 19, 2021 7:15 pm

That code looks great!
I'm glad you found the process to implement your component easy.

I'm currently waiting for my adafruit dotstar (chinese clone) and your code is a great starting point for integrating a light component properly, which I haven't done before.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply