Shelly integration via MQTT/Node-RED

Others (MiLight, Hue, Toon etc...)

Moderator: leecollings

krisha
Posts: 11
Joined: Monday 21 August 2017 16:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Shelly integration via MQTT/Node-RED

Post by krisha »

I created a small Node-RED flow to integrate Shelly switches to domoticz.

For a new shelly you just need to modify the idx <-> shelly table in Node-RED and add a new virtual switch in domoticz.

I would have created a wiki page for it, but don't know how I can register an account there :(

Shelly dimmer will probably not work without modification. Will add this when I installed one ;)

Requirements:
- Node-RED
- MQTT (setup in domoticz already)
- Shelly 1, Shelly 2.5 (not tested yet) or Shelly-Plug

Instructions:
1. Add the attached flow to Node-RED (just needed once for all shellies)
2. Setup the Shelly (wifi + MQTT)
2. a. Power the Shelly, connect to the new wifi and open address http://192.168.33.1
2. b. Enable Wifi-Client
2. c. Connect to the Shelly again (lookup IP address in router or use Shelly finder tool)
2. d. Update firmware
2. e. Connect to your MQTT broker (under advanced - developer settings tab, just server and credentials needed)
2. f. Disable periodic annoucement of the Shelly to prevent log flooding by calling http://IP/settings?mqtt_update_period=0
3. In domoticz use the dummy hardware to create a virtual sensor (switch in this case)
4. In domoticz find the new device IDX under devices and note it.
5. In Node-RED look in the debug log to find the shelly_id and relay.
6. In Node-RED add a new line to the idx <-> shelly function with idx, shelly_id, relay (and remove the sample with idx 193)
7. In Node-RED click deploy

Flow:

Code: Select all

[{"id":"9562a8b.d6f1a58","type":"tab","label":"shelly generic","disabled":false,"info":""},{"id":"f4a7195b.072778","type":"json","z":"9562a8b.d6f1a58","name":"","property":"payload","action":"","pretty":false,"x":290,"y":180,"wires":[["8cf95531.b00988"]]},{"id":"703cdd1.f58b824","type":"mqtt in","z":"9562a8b.d6f1a58","name":"","topic":"domoticz/out","qos":"2","broker":"c6f4c5a6.743d78","x":130,"y":180,"wires":[["f4a7195b.072778"]]},{"id":"c36aa261.d8b3d","type":"mqtt in","z":"9562a8b.d6f1a58","name":"","topic":"shellies/+/relay/+","qos":"2","broker":"c6f4c5a6.743d78","x":140,"y":260,"wires":[["c7632d39.66f0b","84a354a.4c1aca8"]]},{"id":"d70d7c26.f1d5a","type":"function","z":"9562a8b.d6f1a58","name":"idx <-> shelly","func":"var idx_shelly_table = [\n    //[ domoticz idx, shelly name topic, relay ],   // syntax\n    [193, \"shellyplug-s-B864C9\", 0],    // shelly plug 2\n];\n\nif ( msg.src == 'shelly' ) {\n    //todo: support second relays\n    var matches = msg.topic.match( /shellies\\/(.*)\\/relay\\/(\\d)/ );\n    if ( matches.length == 3 ) {\n        var shelly_id = matches[1];\n        var shelly_relay = parseInt( matches[2] );\n        \n        for ( var i = 0; i < idx_shelly_table.length; i++ ) {\n            if ( idx_shelly_table[i][1] == shelly_id && idx_shelly_table[i][2] == shelly_relay ) {\n                // convert to domoticz stuff\n                var val = msg.payload == \"on\" ? 1 : 0;\n\n                msg = {\n                    payload:\n                    {\n                        nvalue: val,\n                        command: \"udevice\",\n                        idx: idx_shelly_table[i][0],\n                    }\n                }\n                \n                return [msg, null, null];\n            }\n        }\n        \n        // shelly not found in table\n        msg.shelly_id = shelly_id;\n        msg.relay = shelly_relay;\n        return [null, null, msg];\n    }\n}\n\nif ( msg.src == 'domoticz' ) {\n    for ( var i = 0; i < idx_shelly_table.length; i++ ) {\n        if ( idx_shelly_table[i][0] == parseInt(msg.payload.idx) ) {\n            if ( msg.payload.nvalue == 1)\n                msg.payload = \"on\";\n            else\n                msg.payload = \"off\";\n                \n            msg.topic = \"shellies/\" + idx_shelly_table[i][1] + \"/relay/\" + idx_shelly_table[i][2] + \"/command\";\n            return [null, msg, null ];\n        }\n    }\n}\n\n// dismiss\nreturn [null, null, null];","outputs":3,"noerr":0,"x":676,"y":189,"wires":[["bd05aded.82da8","a470a99d.717ca8"],["b66b6398.65514","7c1de4a6.afd08c"],["1a8b3224.b1685e"]]},{"id":"8cf95531.b00988","type":"function","z":"9562a8b.d6f1a58","name":"add src","func":"msg.src = 'domoticz';\n\nreturn msg;","outputs":1,"noerr":0,"x":440,"y":180,"wires":[["d70d7c26.f1d5a"]]},{"id":"c7632d39.66f0b","type":"function","z":"9562a8b.d6f1a58","name":"add src","func":"msg.src = 'shelly';\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":260,"wires":[["d70d7c26.f1d5a"]]},{"id":"bd05aded.82da8","type":"debug","z":"9562a8b.d6f1a58","name":"from shelly","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":950,"y":160,"wires":[]},{"id":"b66b6398.65514","type":"debug","z":"9562a8b.d6f1a58","name":"from domoticz","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":940,"y":300,"wires":[]},{"id":"1a8b3224.b1685e","type":"debug","z":"9562a8b.d6f1a58","name":"unlinked shelly","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":940,"y":360,"wires":[]},{"id":"84a354a.4c1aca8","type":"debug","z":"9562a8b.d6f1a58","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":256,"y":449,"wires":[]},{"id":"a470a99d.717ca8","type":"mqtt out","z":"9562a8b.d6f1a58","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"c6f4c5a6.743d78","x":950,"y":100,"wires":[]},{"id":"7c1de4a6.afd08c","type":"mqtt out","z":"9562a8b.d6f1a58","name":"","topic":"","qos":"","retain":"","broker":"c6f4c5a6.743d78","x":910,"y":240,"wires":[]},{"id":"30e1b8ec.db2538","type":"comment","z":"9562a8b.d6f1a58","name":"disable shelly announce!","info":"http://IP/settings?mqtt_update_period=0\n\nit fills the log of domoticz rapidly","x":170,"y":80,"wires":[]},{"id":"c6f4c5a6.743d78","type":"mqtt-broker","z":"","name":"mqtt home","broker":"localhost","port":"1883","clientid":"node-red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Attachments
debug window.png
debug window.png (19.19 KiB) Viewed 12892 times
shelly flow.png
shelly flow.png (47.1 KiB) Viewed 12892 times
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

Hero!!!!!
Just what i was looking for..
Shelly working out of the box with mqtt.
Do not lik the plugin options in Domoticz

Please some explane.
Is this for a shelly 1 or can i use this for the 2.5 also..

Only create some idx?
And chage the id form the sghelly device? B864C9 to my id?

And the power measuring?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
krisha
Posts: 11
Joined: Monday 21 August 2017 16:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by krisha »

Derik wrote: Tuesday 31 December 2019 23:25 Is this for a shelly 1 or can i use this for the 2.5 also..

Only create some idx?
And chage the id form the sghelly device? B864C9 to my id?

And the power measuring?
I tested it with shelly 1 and the shelly plug.

For shelly 2.5 you probably have to create two entries and two idx in domoticz (one for each channel), like this:

Code: Select all

[181, "shelly2.5-xxxxxx", 0],    // first channel; domoticz idx 181
[182, "shelly2.5-xxxxxx", 1],    // second channel; domoticz idx 182
Shelly 1 publishes to topic shelly1-xxxxxx (where xxxxxx is your shelly serial). Shelly Plug S to topic shellyplug-s-xxxxxx.

About the shelly topics for shelly 2.5 I'm not totally sure. But they are reported in the debug console of node-red if you toggle the shelly manually and it's not already linked through the code.

Power measurement is not included yet, but is a good idea ;)
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

Shelly plug?
Do i need to install a plugin?
Or can i direct switch?


Hope you can make the whole switches working incl power and voltage int Domoticz
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
krisha
Posts: 11
Joined: Monday 21 August 2017 16:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by krisha »

Shelly plug is another product from shelly: https://shelly.cloud/shelly-plug-s/

You only need node-red and mqtt, plus 1 line of code for each relay in node-red to link domoticz and shelly together ;) no extra plugin needed.

I attached a picture where the linking between domoticz idx and shelly id has to be placed.
Attachments
shelly-nodered.png
shelly-nodered.png (110.13 KiB) Viewed 12835 times
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

krisha wrote: Thursday 02 January 2020 17:23 Shelly plug is another product from shelly: https://shelly.cloud/shelly-plug-s/

You only need node-red and mqtt, plus 1 line of code for each relay in node-red to link domoticz and shelly together ;) no extra plugin needed.

I attached a picture where the linking between domoticz idx and shelly id has to be placed.

Great.
They are working ok
ScreenShot444.png
ScreenShot444.png (167.11 KiB) Viewed 12832 times
What are here the settings for?

And do you think you get the powerusage etc also working?


And how can i check this?
ScreenShot445.png
ScreenShot445.png (44.58 KiB) Viewed 12830 times
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
krisha
Posts: 11
Joined: Monday 21 August 2017 16:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by krisha »

I don't use any custom settings on the shellies. I just add the MQTT server. I don't know what happens with the MQTT prefix.


You can check the settings by calling http://IP/settings - replace IP with your shelly IP. If you attach a query like ?mqtt_update_period=0 you change that value.

You can leave the value at default, but it might flood the domoticz logs, because it sends a packet each 30 seconds by default. For power measurement this might be ok.

Power measurement might take some time until I implement it ;)
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

Other problem...
When i switch the switch off, on the shelly itself
There is no message back to Domoticz
So there is only a working switch with the Domoticz ui.. With the hardware switch there is no 2 way message
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
krisha
Posts: 11
Joined: Monday 21 August 2017 16:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by krisha »

Derik wrote: Thursday 02 January 2020 19:13 Other problem...
When i switch the switch off, on the shelly itself
There is no message back to Domoticz
So there is only a working switch with the Domoticz ui.. With the hardware switch there is no 2 way message
For shelly 1 this is working. Does this occur on all your shellies?
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

krisha wrote: Thursday 02 January 2020 19:26
Derik wrote: Thursday 02 January 2020 19:13 Other problem...
When i switch the switch off, on the shelly itself
There is no message back to Domoticz
So there is only a working switch with the Domoticz ui.. With the hardware switch there is no 2 way message
For shelly 1 this is working. Does this occur on all your shellies?
i do have two shelly's
a 1 that is working in to a wall without switch
And this two
So no other options to test them

i buy some more ..
Only they are not here in 1 or 2 days...
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

Have 2 new shelly 2.5 @ home :roll: :roll:

So perhaps this evening i test the option with the switches

Just give the Domoticz idx, and the uniek mqtt id in your node red

Code: Select all

  [12635, "25-C4FB16", 0],    // Aanrecht
 [12636, "25-C4FB16", 1],   // Nis 
and functioning:-)
when i use the webui from shelly, domoticz switch
And when i switch domoticz the webui from shelly also switch

Only the manual switch i have to test

Edit:
WORKS!!!
1 setting has to be changed...
Buttontype on Edged

Make this switch first working so i can remove my F*&^king Zwave devices..
And then try the second in the samen Node-red..


Hope you get the power reading working als a time..:-)


This was a part of the flow i find on git:

Code: Select all

[{"id":"2239b354.cd845c","type":"tab","label":"Franks","disabled":false,"info":""},{"id":"1557247.82275dc","type":"debug","z":"2239b354.cd845c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":750,"y":280,"wires":[]},{"id":"b909921b.93acf","type":"function","z":"2239b354.cd845c","name":"0 on","func":"msg.payload = {\n    relay:0,\n    on:true\n    };\nreturn msg;","outputs":1,"noerr":0,"x":340.00586891174316,"y":305.5371084213257,"wires":[["751cc733.6530f8"]]},{"id":"984f7c40.8f30b","type":"function","z":"2239b354.cd845c","name":"0 off","func":"msg.payload = {\n    relay:0, \n    on:false\n    };\nreturn msg;","outputs":1,"noerr":0,"x":333.12890625,"y":394.75391960144043,"wires":[["751cc733.6530f8"]]},{"id":"e72ffd8c.ead6a","type":"inject","z":"2239b354.cd845c","name":"Turn On","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":195,"y":305.7304677963257,"wires":[["b909921b.93acf"]]},{"id":"8ea693e3.fdb4b","type":"inject","z":"2239b354.cd845c","name":"Turn Off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":192.11914825439453,"y":393.73046588897705,"wires":[["984f7c40.8f30b"]]},{"id":"62d70417.59e62c","type":"inject","z":"2239b354.cd845c","name":"Poll Status","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":199.00586700439453,"y":464.7343816757202,"wires":[["751cc733.6530f8"]]},{"id":"751cc733.6530f8","type":"shelly-switch","z":"2239b354.cd845c","hostname":"192.168.5.132","description":"standard lamp","x":556.0058670043945,"y":360.826171875,"wires":[["1557247.82275dc"]]}]
Perhaps that give you ...


Or:
https://flows.nodered.org/node/node-red-contrib-shelly
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

Kick..
No one have this working?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
krisha
Posts: 11
Joined: Monday 21 August 2017 16:43
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by krisha »

didn't find the time yet to install my shellys underwall - might still take 1-3 months :)
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

I do have time [ i hope ]

Only the plugins i do not like to use..
So your NR looks great
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by thomasbaetge »

Hi,

just in case this is still an open point, this is my flow to report energy back from Shelly Plug S (Shelly 1 does NOT report energy back) into an 'energy (instant and counter)' device.

of course you need to adjust to your values.

Code: Select all

[{"id":"fd5174ea.ff98f8","type":"tab","label":"Shelly Plug (Heizung Bad)","disabled":false,"info":"http://192.168.2.50/"},{"id":"8bd8a9b8.4338a8","type":"mqtt in","z":"fd5174ea.ff98f8","name":"","topic":"domoticz/out","qos":"0","datatype":"json","broker":"f80d8629.7db0e8","x":160,"y":140,"wires":[["721aaa91.51b3e4","8589789e.698cb8"]]},{"id":"e897544e.257808","type":"mqtt out","z":"fd5174ea.ff98f8","name":"","topic":"shellies/shellyplug-s-041C71/relay/0/command","qos":"0","retain":"false","broker":"f80d8629.7db0e8","x":700,"y":240,"wires":[]},{"id":"e283864d.f0f888","type":"mqtt in","z":"fd5174ea.ff98f8","name":"","topic":"shellies/shellyplug-s-041C71/relay/0","qos":"2","datatype":"auto","broker":"f80d8629.7db0e8","x":180,"y":460,"wires":[["138e4ba1.e5c5d4","6e88c619.f5f5b8"]]},{"id":"138e4ba1.e5c5d4","type":"debug","z":"fd5174ea.ff98f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":410,"y":380,"wires":[]},{"id":"da6be463.2c9788","type":"mqtt in","z":"fd5174ea.ff98f8","name":"","topic":"shellies/shellyplug-s-041C71/relay/0/power","qos":"2","datatype":"json","broker":"f80d8629.7db0e8","x":180,"y":600,"wires":[["d1f54faf.4eac5"]]},{"id":"55384de2.ca40c4","type":"debug","z":"fd5174ea.ff98f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":850,"y":680,"wires":[]},{"id":"721aaa91.51b3e4","type":"function","z":"fd5174ea.ff98f8","name":"","func":"if(msg.payload.id == \"00014159\"){\n    if (msg.payload.nvalue == 1){\n        msg.payload = \"on\";\n    } else {\n        msg.payload = \"off\";\n    }\n    \n}\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":240,"wires":[["e897544e.257808"]]},{"id":"63e3dc74.a1b0b4","type":"mqtt out","z":"fd5174ea.ff98f8","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"f80d8629.7db0e8","x":790,"y":400,"wires":[]},{"id":"8589789e.698cb8","type":"debug","z":"fd5174ea.ff98f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":480,"y":140,"wires":[]},{"id":"6e88c619.f5f5b8","type":"function","z":"fd5174ea.ff98f8","name":"","func":"msg.payload = { \n    \"idx\" :265,\n     \"nvalue\" :msg.payload == \"on\"\n     ? 1 : 0\n    \n};\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":460,"wires":[["661eed2a.34a8b4"]]},{"id":"6678465d.1307a8","type":"mqtt in","z":"fd5174ea.ff98f8","name":"","topic":"shellies/shellyplug-s-041C71/relay/0/energy","qos":"2","datatype":"json","broker":"f80d8629.7db0e8","x":190,"y":540,"wires":[["9fa20928.573488"]]},{"id":"661eed2a.34a8b4","type":"rbe","z":"fd5174ea.ff98f8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":550,"y":460,"wires":[["63e3dc74.a1b0b4"]]},{"id":"6505cdcf.797ae4","type":"function","z":"fd5174ea.ff98f8","name":"","func":"var watt = parseInt(msg.payload.power)\n\nvar kw = msg.payload.energy / 60\nvar sval = watt.toString() + \";\" + kw.toString()\n\nmsg.payload = { \n    \"idx\" :276,\n    \"nvalue\" :0,\n    \"svalue\" :sval\n     \n}\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":580,"wires":[["55384de2.ca40c4","41878f8d.a4a28"]]},{"id":"34a067e7.a2f5c8","type":"join","z":"fd5174ea.ff98f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":600,"y":580,"wires":[["6505cdcf.797ae4"]]},{"id":"9fa20928.573488","type":"function","z":"fd5174ea.ff98f8","name":"","func":"msg.topic = \"energy\"\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":540,"wires":[["34a067e7.a2f5c8"]]},{"id":"d1f54faf.4eac5","type":"function","z":"fd5174ea.ff98f8","name":"","func":"msg.topic = \"power\"\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":600,"wires":[["34a067e7.a2f5c8"]]},{"id":"41878f8d.a4a28","type":"rbe","z":"fd5174ea.ff98f8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":580,"wires":[["63e3dc74.a1b0b4"]]},{"id":"f80d8629.7db0e8","type":"mqtt-broker","z":"","name":"Controlberry","broker":"192.168.2.40","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
Last edited by thomasbaetge on Saturday 23 May 2020 10:41, edited 1 time in total.
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by Derik »

thomasbaetge wrote: Friday 15 May 2020 15:39 Hi,

just in case this is still an open point, this is my flow to report energy back from Shelly Plug S (Shelly 1 does NOT report energy back) into an 'energy (instant and counter)' device.

of course you need to adjust to your values.

Code: Select all

[{"id":"fa9bf872.435f98","type":"tab","label":"Shelly plug 2 (Lavalampe)","disabled":false,"info":"192.168.2.55\n"},{"id":"44aab089.dd333","type":"mqtt in","z":"fa9bf872.435f98","name":"","topic":"domoticz/out","qos":"0","datatype":"json","broker":"f80d8629.7db0e8","x":130,"y":40,"wires":[["7784681c.b96d18","e59b032a.2d49c"]]},{"id":"84bb2e75.8fb7d","type":"mqtt out","z":"fa9bf872.435f98","name":"","topic":"shellies/shellyplug-s-7A3535/relay/0/command","qos":"0","retain":"false","broker":"f80d8629.7db0e8","x":670,"y":140,"wires":[]},{"id":"4ae37916.9a2c08","type":"mqtt in","z":"fa9bf872.435f98","name":"","topic":"shellies/shellyplug-s-7A3535/relay/0","qos":"2","datatype":"auto","broker":"f80d8629.7db0e8","x":200,"y":260,"wires":[["c71ef1e6.3c1af"]]},{"id":"316903c5.50e28c","type":"mqtt in","z":"fa9bf872.435f98","name":"","topic":"shellies/shellyplug-s-7A3535/relay/0/power","qos":"2","datatype":"json","broker":"f80d8629.7db0e8","x":190,"y":420,"wires":[["3a5d8fe6.aee38"]]},{"id":"48f52fc1.65a8b","type":"debug","z":"fa9bf872.435f98","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":910,"y":500,"wires":[]},{"id":"7784681c.b96d18","type":"function","z":"fa9bf872.435f98","name":"","func":"if(msg.payload.id == \"00014165\"){\n    if (msg.payload.nvalue == 1){\n        msg.payload = \"on\";\n    } else {\n        msg.payload = \"off\";\n    }\n    \n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":140,"wires":[["84bb2e75.8fb7d"]]},{"id":"d184740e.5b1018","type":"mqtt out","z":"fa9bf872.435f98","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"f80d8629.7db0e8","x":900,"y":260,"wires":[]},{"id":"e59b032a.2d49c","type":"debug","z":"fa9bf872.435f98","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":40,"wires":[]},{"id":"c71ef1e6.3c1af","type":"function","z":"fa9bf872.435f98","name":"","func":"msg.payload = { \n    \"idx\" :277,\n     \"nvalue\" :msg.payload == \"on\"\n     ? 1 : 0\n    \n};\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":260,"wires":[["2a96e66d.7eb8fa"]]},{"id":"4f23fcdb.fd1ac4","type":"mqtt in","z":"fa9bf872.435f98","name":"","topic":"shellies/shellyplug-s-7A3535/relay/0/energy","qos":"2","datatype":"json","broker":"f80d8629.7db0e8","x":200,"y":340,"wires":[["31421779.b5d0c8"]]},{"id":"2a96e66d.7eb8fa","type":"rbe","z":"fa9bf872.435f98","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":660,"y":260,"wires":[["d184740e.5b1018"]]},{"id":"74da84e5.0b484c","type":"function","z":"fa9bf872.435f98","name":"","func":"var watt = parseInt(msg.payload.power)\n\nvar kw = msg.payload.energy / 1000\nvar sval = watt.toString() + \";\" + kw.toString()\n\nmsg.payload = { \n    \"idx\" :279,\n    \"nvalue\" :0,\n    \"svalue\" :sval\n     \n}\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":400,"wires":[["9ee0eb7b.829608"]]},{"id":"f9eb5c49.2d774","type":"join","z":"fa9bf872.435f98","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":620,"y":400,"wires":[["74da84e5.0b484c"]]},{"id":"31421779.b5d0c8","type":"function","z":"fa9bf872.435f98","name":"","func":"msg.topic = \"energy\"\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":340,"wires":[["f9eb5c49.2d774"]]},{"id":"3a5d8fe6.aee38","type":"function","z":"fa9bf872.435f98","name":"","func":"msg.topic = \"power\"\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":420,"wires":[["f9eb5c49.2d774"]]},{"id":"9ee0eb7b.829608","type":"rbe","z":"fa9bf872.435f98","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":910,"y":400,"wires":[["d184740e.5b1018","48f52fc1.65a8b"]]},{"id":"f80d8629.7db0e8","type":"mqtt-broker","z":"","name":"Controlberry","broker":"192.168.2.40","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]


Thanks.!!!!!!

I got the power and usage working as test..
ScreenShot147.png
ScreenShot147.png (65.44 KiB) Viewed 11495 times
So not now time to change everything..
Only when i fill in the other nodes i can switch te shelly i think? [ for the future.. ]

Only do know perhaps also how i can read out the tasmota usage and poer?
ScreenShot148.png
ScreenShot148.png (194.34 KiB) Viewed 11495 times
I see a lot of data, only not on the same structure like a shelly..

Thanks!!!
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by thomasbaetge »

happy to help, you're very welcome :D

the deactivated nodes will switch the shelly from Domoticz, (you need to adjust device ID , etc.)
the second strain will report on/off status to Domoticz, which is useful, if you you switch from the shelly web interface or manually.

For Tasmota I don't know, since I don't have any devices. but I assume they have a specified API, just like Shelly.
I found this one:
https://tasmota.github.io/docs/MQTT/

edit: I looked a bit deeper into your screenshot, I think the required data should be easy to extract from that payload. you probably just need th change the coding in the function node(s) to parse the values you need.
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by thomasbaetge »

For those using my flow, there's a conversion error in the consumption calculation.
I'll post an update next week.
Sorry...

Gesendet von meinem Pixel 4 XL mit Tapatalk

thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by thomasbaetge »

I updated the original flow I posted above to reflect, that Shellys report energy in Wmin (instead of Wh).
Should be fine now, but I can not test at the moment.
hoeby
Posts: 531
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: Shelly integration via MQTT/Node-RED

Post by hoeby »

Thanks Krisha for this flow

I used it for a start to make a different flow.
i am using a shelly 2.5 with tasmota firmware and setup as shutter.
The control works both ways, between tasmota and domoticz.

Your flow was the start and my first experience with node-red.
Thanks for your hard work.

My flow is in a separte thread, see undernead if interested:
https://www.domoticz.com/forum/viewtopi ... 77#p249077
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest