Page 1 of 2
MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 06 January 2023 16:22
by ChrisVH1982
Hello,
Hello,
##########
I know that this topic was raised in viewtopic.php?p=296694#p296694 already, but I am expecting the below to work since the creator of the Shelly MQTT Phyton plugin says that MQTT Auto Discovery will work.
##########
I’ve been using Shelly devices for years with the Shelly MQTT Phyton Plugin created by Alexander Nagy.
When I noticed that the 2nd generation devices won’t connect, I checked on
https://github.com/enesbcs/Shelly_MQTT for a more recent version of the plugin. I noticed that he stopped development of the plugin because he’s now using the Domoticz MQTT Auto Discovery hardware instead.
So, I temporarily disabled my MQTT Phyton Plugin device, configured MQTT Auto Discovery Client Gateway with LAN Interface and… neither existing nor new Shelly devices connected ☹. Because do not want to mess up my current environment I setup another Raspberry running for running a test lab. It is running Domoticz 2022.2 with Mosquitto version 2.0.11.
I then configured the MQTT Phyton Plugin first making sure that my Shelly1 will successfully be added to Domoticz. Because this worked out like a charm, I did the following:
1. Disabled hardware “MQTT Phyton Plugin”
2. Deleted Shelly devices
3. Enabled hardware “MQTT Auto Discovery”
4. Verified in log that MQTT Auto Discovery can connect to MQTT Broker:
Message in log: “MQTT Auto Discovery: connected to: 127.0.0.1:1883”
5. Rebooted Shelly
Unfortunately, this time the Shelly was not added. Is there anything for me to do in addition for the Gen1 and hopefully also Gen2 Shellies to become detected?
I am btw. successfully running Mosquitto with Zigbee2MQTT and MQTT Auto Discovery on the production instance So MQTT Auto Discovery in general should work.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 06 January 2023 17:49
by waltervl
Shelly is NOT compatible with MQTT AD. The plugin author says: I may publish a script which teaches shellies to AD in the future.
So he uses some kind of script to convert shellyMQTT into MQTT AD.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Saturday 07 January 2023 9:11
by HarryB
@chrisvh1982
I have exactly the same issue, the MQTT Autodiscovery plugin, never worked with these devices.
I still did not moved to the zwavejs2mqtt because I did not see any device being auto created,
except for a German plugin that flooded my environment.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 03 February 2023 18:28
by lwolf
waltervl wrote: ↑Friday 06 January 2023 17:49
Shelly is NOT compatible with MQTT AD. The plugin author says: I may publish a script which teaches shellies to AD in the future.
So he uses some kind of script to convert shellyMQTT into MQTT AD.
https://github.com/enesbcs/shellyteacher4domo
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 03 February 2023 19:19
by waltervl
lwolf wrote: ↑Friday 03 February 2023 18:28
waltervl wrote: ↑Friday 06 January 2023 17:49
Shelly is NOT compatible with MQTT AD. The plugin author says: I may publish a script which teaches shellies to AD in the future.
So he uses some kind of script to convert shellyMQTT into MQTT AD.
https://github.com/enesbcs/shellyteacher4domo
That is a nice solution to get Domoticz MQTT AD communicate with non Autodiscover devices.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 03 February 2023 19:51
by lwolf
waltervl wrote: ↑Friday 03 February 2023 19:19
lwolf wrote: ↑Friday 03 February 2023 18:28
waltervl wrote: ↑Friday 06 January 2023 17:49
Shelly is NOT compatible with MQTT AD. The plugin author says: I may publish a script which teaches shellies to AD in the future.
So he uses some kind of script to convert shellyMQTT into MQTT AD.
https://github.com/enesbcs/shellyteacher4domo
That is a nice solution to get Domoticz MQTT AD communicate with non Autodiscover devices.
Thanks, i thought it is better to let Domoticz deal with the Shelly devices directly, just say it to how, instead of struggling with a python plugin.
I hope there will be some experienced users who knows this HA config templates better than us and will help. (currently there are only 2 contributors)
Simple on/off devices, temperature sensor integrations, power sensors, etc. are easy to configure, but we are struggling more complex devices such as RGBW. After several days of trial and error Shelly Duo white finally seems to work, at least partially.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Thursday 18 January 2024 22:18
by sincze
waltervl wrote: ↑Friday 03 February 2023 19:19
lwolf wrote: ↑Friday 03 February 2023 18:28
waltervl wrote: ↑Friday 06 January 2023 17:49
Shelly is NOT compatible with MQTT AD. The plugin author says: I may publish a script which teaches shellies to AD in the future.
So he uses some kind of script to convert shellyMQTT into MQTT AD.
https://github.com/enesbcs/shellyteacher4domo
That is a nice solution to get Domoticz MQTT AD communicate with non Autodiscover devices.
Nice. Created a Docker for it and worked. Shellys were found and domoticz created the devices.
https://hub.docker.com/r/sincze/shellyteacher4domo
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Thursday 18 January 2024 22:51
by waltervl
Why a docker for this? The script or windows executable needs to run once after each new Shelly device implementation in your network. No need to run this script continuously.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 19 January 2024 8:30
by sincze
waltervl wrote: ↑Thursday 18 January 2024 22:51
Why a docker for this? The script or windows executable needs to run once after each new Shelly device implementation in your network. No need to run this script continuously.
Djeez that's it??
I indeed thought it needs to run continuously to do translations. (MQTT)
Easy test... shutdown docker and see if it still works.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 19 January 2024 9:41
by thomasbaetge
I have (and always will) integrated every shelly device manually via Node-Red MQTT.
I got a flow template for the types I'm using (PLug S, Shelly 1, Shelly 1PM, Shelly flood, Shelly button) and every new device takes me about 2 minutes to set up.
This has been working ever since my first one and I never encounter any issues in operation. Additionally, this will easily let me integrate them into any other home automation system I may move to (I will for sure, testing various options at the moment).
I always stay clear of 'Auto'-whatever plugins and try to integrate via MQTT myself.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 19 January 2024 10:08
by sincze
thomasbaetge wrote: ↑Friday 19 January 2024 9:41
I have (and always will) integrated every shelly device manually via Node-Red MQTT.
I got a flow template for the types I'm using (PLug S, Shelly 1, Shelly 1PM, Shelly flood, Shelly button) and every new device takes me about 2 minutes to set up.
This has been working ever since my first one and I never encounter any issues in operation. Additionally, this will easily let me integrate them into any other home automation system I may move to (I will for sure, testing various options at the moment).
I always stay clear of 'Auto'-whatever plugins and try to integrate via MQTT myself.
Tnx @thomasbaetge for the input. can you point me in the direction of your work so I can learn something from it?
(Tasmota kicked out auto discovery (setoption19 1) since version 11 or 12 and implemented their own.
Although i do like the auto discovery as I have many devices ZWAVE / ZIGBEE / MILIGHT / SHELLY / TASMOTA and spin up Docker instances of several autmation systems quite often. Autodiscovery allows me to quickly integrate my devices without that much manual work.
@waltervl is one of my high valued Walking Wiki Domoticz Gurus. I just disabled the docker and indeed what he states (of course) is correct. It still works.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 19 January 2024 10:16
by thomasbaetge
Happy to help.
For a shelly Plug S, the NR integration looks as simple as the pic below. All it really does, is 'translating' MQTT from Shelly to MQTT for Domoticz. The devices I create manually (one Switch and one Smart Meter).
For shelly 1 it's even easier, because it doesn't measure power / energy.
If you want to give it a go, I'd be happy to post the flow here, so you can try yourself.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 19 January 2024 11:30
by sincze
thomasbaetge wrote: ↑Friday 19 January 2024 10:16
Happy to help.
For a shelly Plug S, the NR integration looks as simple as the pic below. All it really does, is 'translating' MQTT from Shelly to MQTT for Domoticz. The devices I create manually (one Switch and one Smart Meter).
For shelly 1 it's even easier, because it doesn't measure power / energy.
If you want to give it a go, I'd be happy to post the flow here, so you can try yourself.
Yes if you can add the flow (export) I can import it in my test system and start playing around with it.
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 19 January 2024 11:57
by thomasbaetge
sure thing, here you go

Please note, the bottom portion that ends in the node labelled 'test' is an integration to InfluxDB to record energy consumption.
If you don't have that, you can just delete that part.
It goes without saying trhat you will need to adapt the flow to your system (Shelly ID, broker connection, etc)
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 19 January 2024 12:12
by thomasbaetge
As for the architecture approach:
I used to have one generic flow per device typ (shelly). This was accomplished by setting the topic prefix in the shelly device to the corresponding Domoticz IDX (in MQTT settings of the shelly device).
So it was (example): shellies/IDX/relay/0/command. This way I could route dynamically and had just one flow for each type.
However, it makes sense to add automation tasks directly in node red (example: swith a light from a motion sensor).
This is why I split it up into flows per single device, since I have different automations for almost every device.
I generally am moving all logic and automation toward NR, so I will be able to migrate from Domoticz to a different system (currently testing)
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Friday 19 January 2024 18:42
by pikassent
sincze wrote: ↑Friday 19 January 2024 10:08
.... can you point me in the direction of your work so I can learn something from it?
(Tasmota kicked out auto discovery (setoption19 1) since version 11 or 12 and implemented their own.
.....
Let me share how I deal with thus you still can use MQTT-AD after Tasmota versions 11.1.0 with a little manual work (maybe less than NodeRed):
+ Example of Tasmota Socket Switch with Power monitoring
- Configure your Tasmota device as always (SetOption19 is not needed anymore)
- Create (for better debugging) a new Hardware "MQTT Auto Discovery Client Gatewat with LAN Interface" pointing to your MQTT broker and put the Autodiscovery Topic of your election (Tasmota12 in this case)
- Use MQTT-Explorer tool to publish following (retained!!) autodiscovery payloads (remember to change "switch1" with your Tasmota device mqtt topic):
- topic for switch device => tasmota12/switch/123456789ABC_relay/config
Code: Select all
{
"name": "switch1",
"stat_t": "stat/switch1/POWER",
"avty_t": "tele/switch1/LWT",
"pl_avail": "Online",
"pl_not_avail": "Offline",
"cmd_t": "cmnd/switch1/POWER",
"pl_off": "OFF",
"pl_on": "ON",
"val_tpl": "{{value_json.POWER}}",
"uniq_id": "123456789ABC-Switch",
"dev": {
"ids": [
"123456789ABC"
]
}
}
- topic for power device => tasmota12/sensor/123456789ABC_power/config
Code: Select all
{
"name": "switch1",
"stat_t": "tele/switch1/SENSOR",
"avty_t": "tele/switch1/LWT",
"pl_avail": "Online",
"pl_not_avail": "Offline",
"enabled_by_default": false,
"uniq_id": "123456789ABC-Power",
"dev": {
"ids": [
"123456789ABC"
]
},
"unit_of_meas": "W",
"dev_cla": "power",
"frc_upd": true,
"val_tpl": "{{value_json['ENERGY']['Power']}}"
}
- topic for energy device => tasmota12/sensor/123456789ABC_total/config
Code: Select all
{
"name": "switch1",
"stat_t": "tele/switch1/SENSOR",
"avty_t": "tele/switch1/LWT",
"pl_avail": "Online",
"pl_not_avail": "Offline",
"enabled_by_default": false,
"uniq_id": "123456789ABC-Total",
"dev": {
"ids": [
"123456789ABC"
]
},
"unit_of_meas": "kWh",
"dev_cla": "energy",
"stat_cla": "total_increasing",
"frc_upd": true,
"val_tpl": "{{value_json['ENERGY']['Total']}}"
}
You must also change"123456789ABC" with a unique id like MAC address of device
Hope it helps

Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Saturday 20 January 2024 11:07
by sincze
While trying to copy paste your examples I get:

- strange.png (5.34 KiB) Viewed 3265 times
I first thought this code needs to go somewhere in the Tasmota rules part, however based on what I learned in a different forum topic it could just as well be a one-off trick in mqtt-explorer indeed to 'teach' domoticz the device. Am i right ?
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Saturday 20 January 2024 12:23
by pikassent
You are right. It will "teach" domoticz to discover your Tasmota v11+ device
Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Saturday 20 January 2024 16:23
by sincze
pikassent wrote: ↑Saturday 20 January 2024 12:23
You are right. It will "teach" domoticz to discover your Tasmota v11+ device
Great same idea as shellyteacher4domo
Would be nice if we could modify
https://github.com/enesbcs/shellyteacher4domo to tasmotateacher4domo.
UPDATE: 18:18
I managed to create my first device

ON/OFF switch.

Re: MQTT Auto Discovery with Mosquitto and Shelly1
Posted: Sunday 21 January 2024 9:54
by pikassent
It was my idea but my python skills are not good enough
sincze wrote: ↑Saturday 20 January 2024 16:23
UPDATE: 18:18
I managed to create my first device

ON/OFF switch.
Cheers!