Here is, another take how to integrate Shelly devices with HA (gen2 and newer)
You know me I prefer MQTT way, but I’m getting older and lazier to write and maintain manually configured MQTT entities.
At the same time I wanted to dive into Shelly scripting.
I’ve started with the overhaul of one of the example scripts provided by Shelly, registering BLE devices proxied by AC-powered Shellys using MQTT discovery. I have described it over here.
BTW: did you know you can use buttons available in DW BLE as a regular button?
Then, I came up with the idea of a complementary script, which will register hosting devices to MQTT discovery. And here is. So far, limited to following components:
- switch (can be reported as a light)
- cover (incl. position and slat if enabled)
- pm1
- wifi
- em, em1
- emdata, em1data
- temperature
- humidity
- voltmeter (incl. custom formula and units)
- input (incl. custom formula and units)
I’ve tested the models I own:
- Shelly 1 gen3
- Shelly Mini PM gen3
- Shelly Plus 1PM (gen2)
- Shelly Plus 2PM (gen2) - as switch, light, cover incl. position and slat support
- Shelly Pro EM3 (gen2) - both triphase and monophase profiles
- Addon Plus - with 4xDS18B20, DHT22, binary, analog and voltimeter inputs
However, it will create sensors out of all the Shelies that utilize the components listed above. Here is a compatibility list: shelly-scripts/scripts/mqtt-discovery-self.md at main · michalk-k/shelly-scripts · GitHub
The biggest challenge was to write it in a way not exceeding resources: memory, MQTT queue, CPU stack, etc. Side effects were really unexpected. I was desperate, close to throwing this project into the bin. Finally, I found a way to generate a relatively high amount of data and publish it, keeping the memory footprint low (about 10kB), and mainly not overloading the MQTT component.
See: GitHub - michalk-k/shelly-scripts
for a more detailed description, screenshots, and scripts, of course.