Page 4 of 6

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

Posted: Sunday 21 February 2016 11:26
by bacsa
Found it... Need to make a harware mqtt device.

Fixed.

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

Posted: Saturday 05 March 2016 1:02
by BlueBullet
Nice work! Much appreciated to prevent my plugwise circles from gathering dust :D

Question though:
Is there a way to add a dummy device that will display the cumulative power consumption of all circles?
And would it be best to implement this in the Node-Red flow or alternatively do the calculations through a lua or bash script and send the outcome to the dummy device?

In addition for someone who may want to use it, I use this script to add Plugwise2py to init.d so it starts at (re)boot:

Create script in /etc/init.d

Code: Select all

sudo nano /etc/init.d/plugwise2py
Add this:

Code: Select all

#! /bin/sh
# /etc/init.d/plugwise2py

### BEGIN INIT INFO
# Provides:          plugwise2py
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Simple script to start plugwise2py at boot
# Description:       A simple script modified from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO

# If you want a command to always run, put it here

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting plugwise2py"
    # run application you want to start
    #go to the working directory:
    cd /home/pi/Plugwise-2-py
    # run application:
    /usr/bin/nohup /usr/bin/python /home/pi/Plugwise-2-py/Plugwise-2.py >>/tmp/pwout.log&
    ;;
  stop)
    echo "Stopping plugwise2py"
    # kill application you want to stop (get pid of the process)
    kill -9 $(pidof /usr/bin/python /home/pi/Plugwise-2-py/Plugwise-2.py) 
    ;;
  *)
    echo "Usage: /etc/init.d/plugwise2py {start|stop}"
    exit 1
    ;;
esac

exit 0
Warning - its important you test your script first and make sure it doesn't need a user to provide a response, press "y" or similar, because you may find it hangs the raspberry pi on boot waiting for a user (who's not there) to do something!

Make script executable:

Code: Select all

sudo chmod 755 /etc/init.d/plugwise2py
Test starting the program:

Code: Select all

sudo /etc/init.d/plugwise2py
Test stopping the program:

Code: Select all

sudo /etc/init.d/plugwise2py
To register your script to be run at start-up and shutdown, run the following command:

Code: Select all

sudo update-rc.d plugwise2py defaults
If you ever want to remove the script from start-up, run the following command:

Code: Select all

sudo update-rc.d -f  plugwise2py remove

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

Posted: Thursday 14 April 2016 14:19
by Jendemen
Can someone give advise what I am doing wrong?
I re-installed Domotics several times, went through the Readme from SevenW step by step, searched the forum, but can't find the solution.

The Web job is running fine, showing my test circles, but no value shown.
If I do a ps -ef | grep Plugwise, I only see the web job running, but not the plugwise-2.py. I think that is my problem.
The log files are only amended when I start the program: nohup python Plugwise-2.py >>/tmp/pwout.log&
In the pw-logger.log file it shows that mac is not found, I am sure the addresses are correct.

The pwout.log show that /home/pi/datalog/2016/pwact/pwact-2016-04-14*.log is missing. If I create the file manually, the line disppears.

Any help/advise highly appreciated!

Log files:
tail pw-communication.log
2016-04-14 13:55:59,605 - pwcomm - RECV 76 -->> 0024 00E8 .... 000D6F0000C3E6D5 10044BEB00061B3001856539070140234DCCDB7B02 03DF <---
2016-04-14 13:55:59,613 - pwcomm - SEND 38 ---> 0048 000D6F0000C3E6D5 00061B20 BBD6 <---
2016-04-14 13:55:59,623 - pwcomm - RECV 22 ---> 0000 00E9 00C1 ................ FA5D <---
2016-04-14 13:55:59,711 - pwcomm - RECV 106 -->> 0049 00E9 .... 000D6F0000C3E6D5 10044B78000298A010044BB400019AF3FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00061B20 09F3 <---
2016-04-14 13:55:59,727 - pwcomm - SEND 30 ---> 0026 000D6F0000C3E6D5 0D32 <---
2016-04-14 13:55:59,738 - pwcomm - RECV 22 ---> 0000 00EA 00C1 ................ E5F6 <---
2016-04-14 13:55:59,816 - pwcomm - RECV 66 -->> 0027 00EA .... 000D6F0000C3E6D5 3F8096BAB61868733C2A3C7C00000000 3822 <---
2016-04-14 13:55:59,822 - pwcomm - SEND 38 ---> 0048 000D6F0000C3E6D5 00061B00 DDB4 <---
2016-04-14 13:55:59,833 - pwcomm - RECV 22 ---> 0000 00EB 00C1 ................ 0B24 <---
2016-04-14 13:55:59,911 - pwcomm - RECV 106 -->> 0049 00EB .... 000D6F0000C3E6D5 10044A880001BDFA10044AC40001DDEA10044B000001FF4A10044B3C00018AA700061B00 732A <---

tail pw-logger.log
2016-04-14 13:59:32,376 - pw-logger - DEBUG - poll_configuration()
2016-04-14 13:59:32,377 - pw-logger - DEBUG - read_apply_controls
2016-04-14 13:59:32,544 - pw-logger - INFO - API 000D6F0000B1D7AB Buitenlamp circle schedule off
2016-04-14 13:59:32,588 - pw-logger - INFO - circle mac: 000D6F0000B1D7AB needs to be switched on
2016-04-14 13:59:32,589 - pw-logger - INFO - API 000D6F0000B1D7AB Buitenlamp circle switch: on
2016-04-14 13:59:32,861 - pw-logger - INFO - sync_time: circle TV time is 12:59:33
2016-04-14 13:59:33,189 - pw-logger - INFO - sync_time: circle Buitenlamp time is 00:00:12
2016-04-14 13:59:33,446 - pw-logger - INFO - sync_time: circle Koelkast time is 12:59:32
2016-04-14 13:59:40,081 - pw-logger - INFO - get_status_json: mac not found in circles or controls
2016-04-14 13:59:40,083 - pw-logger - INFO - get_status_json: mac not found in circles or controls

tail /tmp/pwout.log
KeyError: '000D6F0000B1C08E'
rsync: link_stat "/home/pi/datalog/2016/pwact/pwact-2016-04-14*.log" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.1]
True
Traceback (most recent call last):
File "Plugwise-2.py", line 1353, in <module>
main.run()
File "Plugwise-2.py", line 1303, in run
idx=self.controlsbymac[c.mac]
KeyError: '000D6F0000B1C08E'

And after creating the file /home/pi/datalog/2016/pwact/pwact-2016-04-14*.log manually (and rights to pi)
tail /tmp/pwout.log
File "Plugwise-2.py", line 1303, in run
idx=self.controlsbymac[c.mac]
KeyError: '000D6F0000B1C08E'
True
Traceback (most recent call last):
File "Plugwise-2.py", line 1353, in <module>
main.run()
File "Plugwise-2.py", line 1303, in run
idx=self.controlsbymac[c.mac]
KeyError: '000D6F0000B1C08E'

Config files:
pw-conf.json:
{"static": [
{"mac":"000D6F0000B1C08E","category":"thuis","name":"TV","loginterval":"60","always_on":"True","monitor":"yes","savelog":"yes","production":"False","location":"Kamer"},
{"mac":"000D6F0000B1D7AB","category":"thuis","name":"Buitenlamp","loginterval":"60","always_on":"False","monitor":"yes","savelog":"yes","production":"False","location":"Buiten"},
{"mac":"000D6F0000C3E6D5","category":"thuis","name":"Koelkast","loginterval":"60","always_on":"True","monitor":"yes","savelog":"yes","production":"False","location":"Keuken"}
]}

pw-control.json:
{"dynamic": [
{"mac": "000D6F0000B1D7AB", "switch_state": "on", "name": "nas", "schedule_state": "off", "schedule": "", "savelog": "yes", "monitor": "yes"}
],
"log_level": "info",
"log_comm": "no"}

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

Posted: Monday 18 April 2016 10:16
by Jendemen
Solved: All Circles need to be entered in BOTH pw-conf AND pw-control !

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

Posted: Monday 02 May 2016 12:35
by dorenberg
Hi all, just to check with all of you. When switching a circle within domoticz, I can only switch it off but not on again. Using the B prefix device to switch the circle. I am getting an error to check the hardware? Any ideas over here?

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

Posted: Thursday 25 August 2016 5:56
by Frisootje
Hi, for the last 4 hours I've been trying to get Plugwise-2-py working, hoping to eventually integrate Plugwise into Domoticz.

I keep getting a 'KeyError' for a Plugwise mac address. The mac address is exactly right though, I checked against Plugwise Source database. I put all three JSON config files through a validator, they're all valid. I am very new to the Pi and still learning about its command-line, so please bear with me. What is going wrong here?

/tmp/pwout.log

Code: Select all

rsync: link_stat "/home/pi/datalog/2016/pwact/pwact-2016-08-25*.log" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.1]
True
Traceback (most recent call last):
  File "Plugwise-2.py", line 1353, in <module>
    main.run()
  File "Plugwise-2.py", line 1303, in run
    idx=self.controlsbymac[c.mac]
KeyError: '000D6F0001A404FA'
pw-conf.json

Code: Select all

{"static": [
{"mac": "000D6F0001a404fa", "category": "hvac", "name": "airco1e", "loginterval": "2", "always_on": "False", "production": "False", "location": "misc"},
{"mac": "000D6F0001a4065b", "category": "hvac", "name": "airco2e", "loginterval": "2", "always_on": "False", "production": "False", "location": "misc"}
]}
pw-control.json

Code: Select all

{"dynamic": [
{"mac": "000D6F0001a404fa", "switch_state": "on", "name": "airco1e", "schedule_state": "off", "schedule": "", "savelog": "yes", "monitor": "yes"},
{"mac": "000D6F0001a4065b", "switch_state": "on", "name": "airco2e", "schedule_state": "off", "schedule": "", "savelog": "yes", "monitor": "yes"}
],
"log_level": "info",
"log_comm": "no"}
pw-hostconfig.json

Code: Select all

{"permanent_path": "/home/pi/datalog", "tmp_path": "/tmp", "log_path": "/home/pi/pwlog", "serial": "/dev/ttyUSB1", "log_format": "epoch", "mqtt_ip": "127.0.0.1", "mqtt_port": "1883"}

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

Posted: Thursday 25 August 2016 16:03
by Frisootje
Sigh... found it I think. The Circle MAC addresses seem to be case sensitive. Even though the error message was all upper case, I put the addresses in the config files in lower case. After I changed that, it works.

Another question: how do I fill out the initiation block in Node Red? I have the device ID set to the hardware IDX for the virtual device, but what number should the virtual switch get? Simply the same? I put it on 3 and then some Plugwise circles started showing up under my Aeotec Z-stick?! I've now made them both '6', which is the hardware idx of the virtual device.

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

Posted: Saturday 27 August 2016 15:11
by SevenW
Hi,

The devices will be automatically added when everything is configured right. The plugwise-2-py NodeRed code needs to be configured. I noticed that I never came around adding a manual to my github stuff.

So please go in your browser to NodeRed, Plugwise-2-py, and edit the node at the top line called "Initialise global context"

There you will find four variables that can be set to your configuration:

Code: Select all

//edit the following variables to match your configuration:
domoticz_ip = "127.0.0.1";
domoticz_port = "8080";
virtual_hardware_id = 2;
virtual_switch_id = 2;
//end config section
Both virtual_hardware_id and virtual_switch_id should indeed be set to the same value, 6 in your case.

Let me know whether the solves your problem.

BTW, I never considered the case sensitivity for the MAC addresses. In a next iteration I will convert them to upper case in the code to avoid this kind of confusion.

SevenW.

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

Posted: Thursday 01 September 2016 13:28
by connectix
I tried to find the "Initialise global context" virtual_hardware_id = 2; an virtual_switch_id = 2; in node_red but i cannot find it. Can you tell me where to find it in node red? All the circles are read by domoticz but i cannot see the switches

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

Posted: Monday 05 September 2016 10:33
by bink
First I would like to thank SevenW. for integrating the Plugwise into domoticz. Have been using the Plugwise-2-py scripts and feeding the info into domoticz for some months now. However I'm now running into the following issue:

I'm trying to replace my current Kaku switch as it's not 100% reliable with a plugwise circle to switch on/off some lights. I'm using a scene to switch on the lights when I press a kaku button. The scene includes some Hue lights a couple of zWave switches and now a plugwise circle. All the devices except the circle are switching on/off. If I look into log the switch command seems to be sent and the circle status does change inside domoticz. However the circle does not change status in real life. If I look in the pw-logger.log I also don't see a switch command coming by. So it looks like domoticz is not sending the MQTT command out (If Iswitch the circle manually from the domoticz switches page it works without a problem).

Does anybody have an idea why this is not working?

Domoticz event:

Code: Select all

2016-09-05 10:28:02.038 RFLink Sending: 10;HomeEasy;7ad36647;d;OFF
2016-09-05 10:28:02.899 (RFLink) Light/Switch (Spotjes Daklicht)
2016-09-05 10:28:03.001 Activating Scene/Group Device: Spot tafel (Off)
2016-09-05 10:28:03.006 (Hue) Lighting Limitless/Applamp (Spot tafel)
2016-09-05 10:28:03.106 Activating Scene/Group Device: Ikea bol (Off)
2016-09-05 10:28:03.112 (Hue) Lighting Limitless/Applamp (Ikea bol)
2016-09-05 10:28:03.216 Activating Scene/Group Device: Eettafel (Off)
2016-09-05 10:28:03.222 (Hue) Lighting Limitless/Applamp (Eettafel)
2016-09-05 10:28:03.312 Activating Scene/Group Device: Circle Printer switch (Off)
2016-09-05 10:28:03.312 (VirtualPlugwise-2-py) Lighting 2 (Circle Printer switch)
2016-09-05 10:28:03.402 Activating Scene/Group Device: Lamp Bank (Off)
2016-09-05 10:28:03.403 (VirtualPlugwise-2-py) Lighting 2 (Lamp Bank)
2016-09-05 10:28:03.522 Activating Scene/Group Device: Tele2 (Off)
2016-09-05 10:28:03.522 OpenZWave: Domoticz has send a Switch command! NodeID: 8 (0x08)
2016-09-05 10:28:04.637 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.644 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.649 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.655 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.660 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.665 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.673 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.678 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.685 Executing script: /root/domoticz/scripts/domoticz_main
2016-09-05 10:28:04.737 Executing script: /root/domoticz/scripts/domoticz_main

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

Posted: Friday 16 September 2016 10:37
by dorenberg
I have the same issue here. I can switch a circle off but not on. The rest works flawlessly over here sinds beginning of the year or end of last year.

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

Posted: Thursday 27 October 2016 13:29
by proohu01
I had all of this working perfectly until I reinstalled my Domoticz system. Now all is working except for the "energy" part. I have tried to figure out what is at fault but I am stuck! :oops:

This is the error I get in Node-RED:

Code: Select all

27-10-2016 13:20:55Plugwise2 Energy to Domoticz
function : (error)
SyntaxError: Unexpected number in JSON at position 27
This is the "Plugwise2 Energy to Domoticz" Node-RED function:

Code: Select all

//
// Relay Plugwise MQTT energy message to Domoticz HTTP
//
node.log ("Relay Plugwise MQTT energy message to Domoticz HTTP");
var sensor_url = context.global.plugwiseCfg.sensor_base_url;
var pwJSON = JSON.parse(msg.payload);
var state = context.global.plugwiseState[pwJSON.mac];
var pvalue = pwJSON.power;
var evalue = pwJSON.cum_energy; 

if (state)
    if (state.state.production) {
        pvalue = -pvalue;
        evalue = -evalue;
    }

///json.htm?type=command&param=udevice&hid=$HID&did=$DID&dunit=$DUNIT&dtype=$DTYPE&dsubtype=$DSUBTYPE&nvalue=$NVALUE&svalue=$SVALUE"
msg.url = sensor_url + "did=E"+pwJSON.mac.substr(9,7)+"&dunit=1&dtype=243&dsubtype=29&nvalue=&svalue="+pvalue+";"+evalue;
return msg;
This is the incomming payload from MQTT:

Code: Select all

{ "topic": "plugwise2py/state/energy/000D6F00003D48A5", "payload": "{\"typ\":\"pwenergy\",\"ts\":2016-10-27 12:00:00,\"mac\":\"000D6F00003D48A5\",\"power\":0.2059,\"energy\":0.2059,\"cum_energy\":39631.9232,\"interval\":60}", "qos": 0, "retain": true, "_topic": "plugwise2py/state/energy/000D6F00003D48A5", "_msgid": "bd9f67e1.e7e1a8" }

I fail to see what position 27 is.

Can anyone shine a light on this?

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

Posted: Thursday 27 October 2016 13:41
by proohu01
Could it be the date notation?

Code: Select all

ts\":2016-10-27 12:00:00,
If I look at the "power" part (the part that is working), the incomming payload looks like this:

Code: Select all

{ "topic": "plugwise2py/state/power/000D6F000037B1BB", "payload": "{\"typ\":\"pwpower\",\"ts\":43990,\"mac\":\"000D6F000037B1BB\",\"power\":49.63}", "qos": 0, "retain": false, "_topic": "plugwise2py/state/power/000D6F000037B1BB", "_msgid": "86dbb6b9.875f88" }
The date looks different. But is that the problem? And if so, why does Plugwise-2-py give me two date notations?

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

Posted: Wednesday 09 November 2016 2:09
by darmokusumo
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?

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

Posted: Monday 28 November 2016 23:32
by digisaster
I just want to say thanks to @SevenW (and others) for the plugwise support
I'm new to domoticz, so i probably made all errors you can make to install the software and the scripts.

It took me a few days/nights to got it running.

If you just stick on https://github.com/SevenW/Plugwise-2-py and "it just don't work" read on.

- Never make the error to use the sudo command, when you do this, you really need delete all the files/dirs because the permission will be wrong
- Never start with only the pw-conf.json, and then after testing edit the second, just change both pw-conf.json, and pw-control.json in one turn.
- The mqtt_port=1883, somehow i was using 1880
- If you do the "nohup python Plugwise-2.py >>/tmp/pwout.log&" and when you press enter and see a "exit" you made a error,
and if you read the outputfile you will find out what kind of error you did made
- The biggest error was copy/paste some lines from the config, and forget to remove the latest , in the pw-conf.js

So i did this:

Code: Select all

{"static": [
{"mac": "000D6F0003973AAC", "category": "misc", "name": "circle+", "loginterval": "60", "always_on": "False", "production": "False", "location": "hall"},
{"mac": "000D6F000397465C", "category": "misc", "name": "circle1", "loginterval": "60", "always_on": "False", "production": "False", "location": "hall"},
]}
But i needed:

Code: Select all

{"static": [
{"mac": "000D6F0003973AAC", "category": "misc", "name": "circle+", "loginterval": "60", "always_on": "False", "production": "False", "location": "hall"},
{"mac": "000D6F000397465C", "category": "misc", "name": "circle1", "loginterval": "60", "always_on": "False", "production": "False", "location": "hall"}
]}
And the nodered file inside the folder "domoticz" is working "out of the box" but i needed to read the README.md file a few times.

The only reason why i still was running a windows server was the plugwise software, and I'm glad i can shut this down.

p.s. if you want to make the software a bit more "idiot proof" you could try to precheck the file permissions and/or make a bash script for launching the python command so you can return a readable error when python returns a error.

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

Posted: Wednesday 30 November 2016 19:48
by edwin1234
I got this error:
Traceback (most recent call last):
File "C:\Users\Edwin\Plugwise-2-py\Plugwise-2.py", line 26, in <module>
from serial.serialutil import SerialException
ImportError: No module named serial.serialutil

what does this mean?

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

Posted: Wednesday 30 November 2016 23:38
by digisaster
edwin1234 wrote:I got this error:
Traceback (most recent call last):
File "C:\Users\Edwin\Plugwise-2-py\Plugwise-2.py", line 26, in <module>
from serial.serialutil import SerialException
ImportError: No module named serial.serialutil

what does this mean?

I guess it means that you don't have pyserial installed?

You could try:
pip install pyserial

But to be honest, i cant find one reason to install this on windows
I don't say there is anything wrong with windows, but if you get yourself a raspberry pi, it will work "out of the box" and only consume max 5 watt

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

Posted: Thursday 01 December 2016 10:29
by edwin1234
Thanks for your answer.
Im just afrait raspberry pi is not fast enough.
I have one with domotiga on it and had lots of troubles also with speed
Thats why i use windows , maybe stupid but thats my problem ;-)
I have solved the first isue but now i have an error that theres no paho mqtt client but i have mosquitto, can i use that too?
Thanks for your help

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

Posted: Friday 02 December 2016 17:47
by digisaster
edwin1234 wrote:Thanks for your answer.
Im just afrait raspberry pi is not fast enough.
I have one with domotiga on it and had lots of troubles also with speed
Thats why i use windows , maybe stupid but thats my problem ;-)
I have solved the first isue but now i have an error that theres no paho mqtt client but i have mosquitto, can i use that too?
Thanks for your help

I also use mosquitto as a mqtt client, so yes, that should be possible to use

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

Posted: Friday 02 December 2016 21:35
by heggink
I run domoticz on a different pi than the one that has my plugwise stick. I am assuming things should just work if I fill in the right ip in domoticz as well as in the plugwise-2-pi configs, correct?
Thanks!
H