MQTT Auto Discovery with Mosquitto and Shelly1

For devices supporting the Auto Discovery feature. Like ZWaveJS2MQTT, Zigbee2MQTT.

Moderator: leecollings

ChrisVH1982
Posts: 23
Joined: Friday 16 November 2018 17:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HarryB
Posts: 16
Joined: Tuesday 27 December 2016 18:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022-2
Location: Netherlands
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
lwolf
Posts: 216
Joined: Saturday 10 November 2018 18:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Hungary
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
Attachments
plugs.png
plugs.png (88.75 KiB) Viewed 2344 times
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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.
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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)
Attachments
flows.txt
(9.94 KiB) Downloaded 58 times
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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)
pikassent
Posts: 16
Joined: Saturday 03 December 2022 16:26
Target OS: Linux
Domoticz version: 2024.4b
Location: Spain
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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
  1. Configure your Tasmota device as always (SetOption19 is not needed anymore)
  2. 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)
  3. Use MQTT-Explorer tool to publish following (retained!!) autodiscovery payloads (remember to change "switch1" with your Tasmota device mqtt topic):
    1. 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"
          ]
        }
      }
    2. 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']}}"
      }
    3. 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 :)
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post by sincze »

While trying to copy paste your examples I get:
strange.png
strange.png (5.34 KiB) Viewed 2243 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 ?
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
pikassent
Posts: 16
Joined: Saturday 03 December 2022 16:26
Target OS: Linux
Domoticz version: 2024.4b
Location: Spain
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post by pikassent »

You are right. It will "teach" domoticz to discover your Tasmota v11+ device
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post 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. :D

UPDATE: 18:18
I managed to create my first device ;-) ON/OFF switch. :D
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
pikassent
Posts: 16
Joined: Saturday 03 December 2022 16:26
Target OS: Linux
Domoticz version: 2024.4b
Location: Spain
Contact:

Re: MQTT Auto Discovery with Mosquitto and Shelly1

Post by pikassent »

sincze wrote: Saturday 20 January 2024 16:23 Great same idea as shellyteacher4domo
Would be nice if we could modify https://github.com/enesbcs/shellyteacher4domo to tasmotateacher4domo. :D
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. :D
Cheers!
Post Reply

Who is online

Users browsing this forum: teo1966 and 1 guest