The original post was an eyeopener for me. NodeRed is pretty cool, did not know it existed.
Did some tweaks on the original post, because I wanted the power reading not every x minutes, but faster.
I have 9 plugwise circles and also want to switch them on and off. Not only reading the energy values.
But then I needed also some scripts, completely in my comfort zone as a unix guy... But then again... another way to switch the devices while everything is already at hand.
So I added some NodeRed stuff to also switch them on and off.
What I basically did is to allow a http request in NodeRed that can be called from domoticz. This switches the circles via the MQTT broker.
It seems a bit slow from time-to-time, but that might be the raspberry.
The only problem now is when I switch a circle with the Plugwise2py interface, Domoticz is unaware of that. That could be solved with the MQTT thing in domoticz. ( working on that )
Code: Select all
[{"id":"81785a4a.7e87a8","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"e5050a22.1afaf8","type":"mqtt in","name":"","topic":"plugwise2py/state/power/#","broker":"81785a4a.7e87a8","x":123,"y":104,"z":"4fcfe3e2.b0301c","wires":[["97654dde.689ab"]]},{"id":"c3de3125.3c21d","type":"http request","name":"Domoticz","method":"use","ret":"txt","url":"","x":697,"y":103,"z":"4fcfe3e2.b0301c","wires":[["6f9f1ac2.6815dc"]]},{"id":"97654dde.689ab","type":"function","name":"Power&Energy 2 Domoticz","func":"//\n// Plugwise JSON MQTT bericht vertalen naar Domoticz HTTP\n//\nnode.log (\"Converteer Plugwise MQTT bericht naar Domoticz HTTP\");\nvar powerJSON = JSON.parse(msg.payload);\n\n//var msg.url = 'http://127.0.0.1:8080/json.htm?mac='+pwJSON.mac+'&power='+pwJSON.power+'&energy='+pwJSON.energy\n//msg.url = \"http://127.0.0.1:8080/json.htm?type=command¶m=udevice&hid=2&did=\"+pwJSON.mac.substr(10,6)+\"&dunit=1&dtype=248&dsubtype=1&nvalue=&svalue=\"+pwJSON.power+\";\"+pwJSON.energy;\nmsg.url = \"http://127.0.0.1:8080/json.htm?type=command¶m=udevice&hid=7&did=\"+powerJSON.mac.substr(10,6)+\"&dunit=1&dtype=248&dsubtype=1&nvalue=&svalue=\"+powerJSON.power+\";\"+powerJSON.energy;\n\nreturn msg;","outputs":"1","noerr":0,"x":451,"y":104,"z":"4fcfe3e2.b0301c","wires":[["39ec969d.c6136a"]]},{"id":"80563945.7fa9c8","type":"mqtt in","name":"","topic":"plugwise2py/state/circle/#","broker":"81785a4a.7e87a8","x":123,"y":226.888916015625,"z":"4fcfe3e2.b0301c","wires":[[]]},{"id":"5ed90d80.2007e4","type":"mqtt in","name":"","topic":"plugwise2py/state/energy/#","broker":"81785a4a.7e87a8","x":128,"y":152,"z":"4fcfe3e2.b0301c","wires":[["97654dde.689ab"]]},{"id":"6f9f1ac2.6815dc","type":"debug","name":"","active":false,"console":"false","complete":"url","x":882.333251953125,"y":103.33333587646484,"z":"4fcfe3e2.b0301c","wires":[]},{"id":"39ec969d.c6136a","type":"delay","name":"Throttle for my slow pi","pauseType":"rate","timeout":"30","timeoutUnits":"seconds","rate":"3","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":593,"y":150,"z":"4fcfe3e2.b0301c","wires":[["c3de3125.3c21d"]]},{"id":"c4bcff5b.3b43","type":"http in","name":"","url":"/switch","method":"get","swaggerDoc":"","x":86,"y":301.25,"z":"4fcfe3e2.b0301c","wires":[["b97606f.f4689f8"]]},{"id":"b97606f.f4689f8","type":"function","name":"Domoticz switch to plugwise","func":"// Switch on and off the plugwise module\n// Make a virtual switch in domoticz and make this the on action:\n// http://127.0.0.1:1880/switch?mac=0236943&cmd=switch&val=on\n// You can guess the off command.\n\n// No need to parse the output of the /switch payload.\n// It is already an object. That make this script pretty easy\n\nnode.log (\"Converteer Domoticz http:// requests naar Plugwise2py MQTT\");\nmsg.topic = \"plugwise2py/cmd/switch/000D6F000\"+msg.payload.mac;\n\nreturn msg;","outputs":1,"noerr":0,"x":381,"y":301,"z":"4fcfe3e2.b0301c","wires":[["a8555a3c.57aaa8"]]},{"id":"1d62cd01.e29d33","type":"debug","name":"","active":false,"console":"false","complete":"payload","x":892,"y":217,"z":"4fcfe3e2.b0301c","wires":[]},{"id":"a8555a3c.57aaa8","type":"mqtt out","name":"MQTT publish","topic":"","qos":"","retain":"","broker":"81785a4a.7e87a8","x":696,"y":336,"z":"4fcfe3e2.b0301c","wires":[]},{"id":"bf3d9a5b.40c268","type":"debug","name":"","active":false,"console":"false","complete":"topic","x":884,"y":258,"z":"4fcfe3e2.b0301c","wires":[]},{"id":"71ae23d9.8e51dc","type":"http in","name":"","url":"/schedule","method":"get","swaggerDoc":"","x":95,"y":369,"z":"4fcfe3e2.b0301c","wires":[["9fa9e5d4.605618"]]},{"id":"9fa9e5d4.605618","type":"function","name":"Domoticz schedule switch to plugwise","func":"// Switch the schedule on and off on the plugwise module\n// Make a virtual switch in domoticz and make this the on action:\n// http://127.0.0.1:1880/switch?mac=0236943&cmd=schedule&val=on\n// You can guess the off command.\n\n// No need to parse the output of the /switch payload.\n// It is already an object. That make this script pretty easy\n\n\n// No need to parse the output of the /schedule payload.\n// It is already an object.\n// Only for switching on/off the schedule, not edit the shcedule.\nnode.log (\"Converteer Domoticz http:// requests naar Plugwise2py MQTT\");\nmsg.topic = \"plugwise2py/cmd/schedule/000D6F000\"+msg.payload.mac;\n\nreturn msg;","outputs":1,"noerr":0,"x":354,"y":369,"z":"4fcfe3e2.b0301c","wires":[["a8555a3c.57aaa8"]]}]