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":""}]