Page 1 of 6

Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Sunday 26 July 2015 22:41
by dorenberg
Hi all,

I have succesfully installed Plugwise-2-py on my raspberry with a lot of help from Pepijn and SevenW over here. The next step would be to show these devices in domoticz via MQTT. (or another way of course.) Does anybody have some experience with this?

Thanks in advance!

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 7:52
by rron
dorenberg wrote:Hi all,

I have succesfully installed Plugwise-2-py on my raspberry with a lot of help from Pepijn and SevenW over here. The next step would be to show these devices in domoticz via MQTT. (or another way of course.) Does anybody have some experience with this?

Thanks in advance!
Did you install this on the same rpi as your domoticz is running?

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 10:53
by dorenberg
yes I did. USB plugwise stick in de rpi and it works! I have no clue how to connect these 2 programs.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 14:03
by rron
dorenberg wrote:yes I did. USB plugwise stick in de rpi and it works! I have no clue how to connect these 2 programs.
I will also try this. Is there a wiki or did you follow the github wiki?

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 16:41
by dorenberg
just the wiki on github and some extra help from SevenW because there was something wrong with permissions and trouble with MQTT configuration.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 19:16
by dorenberg
This is for the Plugwise Stretch 2.0 or Smile P1. Not for the Stick of plugwise.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 19:57
by RayAmsterdam
dorenberg wrote:This is for the Plugwise Stretch 2.0 or Smile P1. Not for the Stick of plugwise.
No, it's not. Only the later posts describe the Stretch 2.0. The previous posts describe the Smile P1 and Stick. I use it with the Stick (removed from the Stretch).

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 20:03
by dorenberg
I will have a go with is. I saw that recently but now I would like to do this via Plugwise-2-py.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 20:12
by rron
dorenberg wrote:just the wiki on github and some extra help from SevenW because there was something wrong with permissions and trouble with MQTT configuration.
When I'm doing "sudo pip install' I got the message: you must give at least give one requirement to install.
Is that the same fault?

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 20:15
by dorenberg
sudo pip install .

Dont forget the .

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 27 July 2015 20:21
by rron
dorenberg wrote:sudo pip install .

Dont forget the .
I overlooked . :D Now to the configuration.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Tuesday 28 July 2015 10:25
by dorenberg
let me know if you succeed in installing and the connection via MQTT to Domoticz.

As this is not so clear to me how this will work.



I have some assumptions. MQTT must be enabled in domoticz of course. MQTT should header with Domoticz/in with svalue nvalue and idx in the MQTT data.
The plugwise-2.py script should be altered to at the qpub.put( point with the proper MQTT values.

If somebody knows exactly what to do, help is most appreciated.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Tuesday 28 July 2015 10:41
by rron
I will do that but it will thake some time. I will contact you if I 'm ready to test.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Tuesday 28 July 2015 20:57
by pepijn
I used Node Red to translate the messages from Plugwise-2-py on MQTT to Domoticz

In Node-Red it looks like this.
Schermafbeelding 2015-07-28 om 20.48.15.png
Schermafbeelding 2015-07-28 om 20.48.15.png (24.65 KiB) Viewed 11527 times
You can try importing my flow as a starting point.

Code: Select all

[{"id":"44cdab58.bb3254","type":"mqtt-broker","broker":"localhost","port":"1883","clientid":""},{"id":"aa2e3003.55d1d","type":"mqtt in","name":"Plugwise","topic":"plugwise2py/state/energy/#","broker":"44cdab58.bb3254","x":79,"y":43,"z":"5edc3f92.a123c","wires":[["313d8fcf.cec27"]]},{"id":"313d8fcf.cec27","type":"function","name":"Plugwise 2 Domoticz","func":"//\n// Plugwise JSON MQTT bericht vertalen naar Domoticz HTTP\n//\nnode.log (\"Converteer Plugwise MQTT bericht naar Domoticz HTTP\");\nvar pwJSON = JSON.parse(msg.payload);\n\n///json.htm?type=command&param=udevice&hid=$HID&did=$DID&dunit=$DUNIT&dtype=$DTYPE&dsubtype=$DSUBTYPE&nvalue=$NVALUE&svalue=$SVALUE\"\n//var msg.url = 'http://127.0.0.1/json.htm?mac='+pwJSON.mac+'&power='+pwJSON.power+'&energy='+pwJSON.energy\nmsg.url = \"http://127.0.0.1/json.htm?type=command&param=udevice&hid=2&did=\"+pwJSON.mac.substr(10,6)+\"&dunit=1&dtype=248&dsubtype=1&nvalue=&svalue=\"+pwJSON.power+\";\"+pwJSON.energy;\n\nreturn msg;","outputs":1,"x":243,"y":91,"z":"5edc3f92.a123c","wires":[["cb9166da.346e98"]]},{"id":"2b0700e4.d4f9","type":"debug","name":"Debug","active":false,"console":"true","complete":"true","x":627,"y":89,"z":"5edc3f92.a123c","wires":[]},{"id":"cb9166da.346e98","type":"http request","name":"Domoticz","method":"GET","ret":"txt","url":"","x":447,"y":90,"z":"5edc3f92.a123c","wires":[["2b0700e4.d4f9"]]}]
If the flow works, your Plugwise devices should show up on your Devices tab.

Right now it uses HTTP/JSON posts to publish data to Domoticz, I will change this to MQTT but this is some work in progress.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Tuesday 28 July 2015 22:31
by dorenberg
THanks for your help. I have managed to install nodejs and node-red and started it. Importing the flow connects to the plugwise instance but debugging shows nothing. Listening to the mqtt broker I get Plugwise and Domoticz/out messages.

I think it is in the settings. Added the port to the json url. When formatting the Domoticz in node-red, I am unsure what to choose. JSON parsing error when I choose a JSON parsed object.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Tuesday 28 July 2015 22:34
by rron
I have send you a pm for help.

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Saturday 01 August 2015 22:46
by dorenberg
Everything works!! Not yet via MQTT but via the solution above. This is the code for Node-red. Slightly adapted. But all circles pop up in the unused list and can be added. I have set the time interval to 10 minutes which is sufficient for me.

Code: Select all

[{"id":"7d9fa7de.826058","type":"function","name":"Plugwise 2 Domoticz","func":"//\n// Plugwise JSON MQTT bericht vertalen naar Domoticz HTTP\n//\nnode.log (\"Converteer Plugwise MQTT bericht naar Domoticz HTTP\");\nvar pwJSON = JSON.parse(msg.payload);\n\n///json.htm?type=command&param=udevice&hid=$HID&did=$DID&dunit=$DUNIT&dtype=$DTYPE&dsubtype=$DSUBTYPE&nvalue=$NVALUE&svalue=$SVALUE\"\n//var msg.url = 'http://127.0.0.1:8080/json.htm?mac='+pwJSON.mac+'&power='+pwJSON.power+'&energy='+pwJSON.energy\nmsg.url = \"http://127.0.0.1:8080/json.htm?type=command&param=udevice&hid=2&did=\"+pwJSON.mac.substr(10,6)+\"&dunit=1&dtype=248&dsubtype=1&nvalue=&svalue=\"+pwJSON.power+\";\"+pwJSON.energy;\n\nreturn msg;","outputs":1,"noerr":0,"x":824,"y":187,"z":"e1aec63.f1e5138","wires":[["32191e24.cde6e2"]]}]

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Sunday 16 August 2015 15:17
by rron
dorenberg wrote:Everything works!! Not yet via MQTT but via the solution above. This is the code for Node-red. Slightly adapted. But all circles pop up in the unused list and can be added. I have set the time interval to 10 minutes which is sufficient for me.

Code: Select all

[{"id":"7d9fa7de.826058","type":"function","name":"Plugwise 2 Domoticz","func":"//\n// Plugwise JSON MQTT bericht vertalen naar Domoticz HTTP\n//\nnode.log (\"Converteer Plugwise MQTT bericht naar Domoticz HTTP\");\nvar pwJSON = JSON.parse(msg.payload);\n\n///json.htm?type=command&param=udevice&hid=$HID&did=$DID&dunit=$DUNIT&dtype=$DTYPE&dsubtype=$DSUBTYPE&nvalue=$NVALUE&svalue=$SVALUE\"\n//var msg.url = 'http://127.0.0.1:8080/json.htm?mac='+pwJSON.mac+'&power='+pwJSON.power+'&energy='+pwJSON.energy\nmsg.url = \"http://127.0.0.1:8080/json.htm?type=command&param=udevice&hid=2&did=\"+pwJSON.mac.substr(10,6)+\"&dunit=1&dtype=248&dsubtype=1&nvalue=&svalue=\"+pwJSON.power+\";\"+pwJSON.energy;\n\nreturn msg;","outputs":1,"noerr":0,"x":824,"y":187,"z":"e1aec63.f1e5138","wires":[["32191e24.cde6e2"]]}]
Did you succeed to connect it to domoticz with MQTT or did you leave it this way?

Re: Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 17 August 2015 18:15
by SevenW
dorenberg wrote:Everything works!! Not yet via MQTT but via the solution above. This is the code for Node-red. Slightly adapted. But all circles pop up in the unused list and can be added. I have set the time interval to 10 minutes which is sufficient for me.
Do the circles automatically show up in the "unused list" or do you need to add some hardware and virtual devices first. I am trying to figure out how this works.

Currently I am sending MQTT topics directly from Plugwise-2.py to domoticz/in, but I have to manually create virtual hardware and virtual devices. I do not seem to have control over the "idx", so I cannot use part of the MAC number as index.

Maybe the Node Red way is just superioir over direct MQTT. Still learning here.

SevenW

Connecting Plugwise-2-py via MQTT to Domoticz

Posted: Monday 17 August 2015 18:46
by pepijn
When i created the script this used to be the way to create devices. Now you can just create devices from the gui. The 'RAW device' way is not supported in the MQTT domoticz/in json.

@gizmocuz: could you confirm this is not supported in MQTT, could support be added?