Plugwise-2-py - an evolution of earlier python/linux work

Plugwise Forum about Plugwise devices and the Source software.

Plugwise-2-py - an evolution of earlier python/linux work

Postby SevenW » Tue Feb 04, 2014 5:51 pm

Hi,

Recently I took a look in this plugwise forum and noticed there is still a lot of activity and interest, even in the protocol. That made me decide that I now finally had to make some effort in sharing my work. Maybe someone can take advantage of this.

Almost two years back I haven taken up python-plugwise and did a major extension to suit my needs, which are mainly very reliable logging of solar panel outputs. I did a lot of reverse engineering the plugwise protocol and implemented several new commands. I also made an effort to get the communication reliable. I observed that sometimes messages are echoed a couple of times in the mesh network. Now this type of artifacts are no longer interpreted as responses to later messages to mention one thing. I also figured out how to enable for production (solar panels), how to change the integration interval form 60 minutes to other values. The SW is able to upload and activate switching schedules. I discovered commands to control groups, but did not further explore this. For those interested: Please take a look in the code on github.

https://github.com/SevenW/Plugwise-2-py

My next enterprise is to connect this to Housemon and Jeebus, also to be found on github.com/jcw. Housmon0.9.x/Jeebus will be providing a nice infrastructure for data logging and simple web-ui's to control settings, and graph recordings.

Have fun,
SevenW
SevenW
Starting Member
Starting Member
 
Posts: 25
Joined: May 2012

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby wimbo » Tue Apr 01, 2014 9:14 pm

Thanks! Looks promising.

One downside I've found while testing on a spare Raspberry Pi, is that it isn't compatible with my Python scripts for the old Hadara version.
I should not, I'm not using your PW-logger.py , I'm using my own simple scripts to read usage from Circles and put that in a MySQL DB.

Code: Select all
pi@framboos ~/PlugWim $ python test.py 000D6F000076XXXX (changed, obivously!)
Traceback (most recent call last):
  File "test.py", line 25, in <module>
    c = Circle(MAC, device)
  File "/usr/local/lib/python2.7/dist-packages/Plugwise_2_py-2.0dev-py2.7.egg/plugwise/api.py", line 274, in __init__
    if self.attr['always_on'] != 'False':
TypeError: 'NoneType' object has no attribute '__getitem__'


Seems you require some sort of extra parameter?
I've tried FALSE or TRUE, just to test. Doesn't work either.

Any ideas how to get it working again with my own scripts?

-EDIT- Removed second code part, my mistake.
wimbo
Starting Member
Starting Member
 
Posts: 6
Joined: February 2011

Re: Plugwise-2-py

Postby SevenW » Tue Jul 15, 2014 9:16 pm

Hi,
I have updated the command line tool: plugwise_util. It should work again.
SevenW
Starting Member
Starting Member
 
Posts: 25
Joined: May 2012

Re: Plugwise-2-py -MQTT interface

Postby SevenW » Tue Jul 15, 2014 9:21 pm

HI,
I have pushed a major update to github. I extended it with an MQTT interface that boths publishes readings, and can by used to send (switch) commands to the circles. The MQTT interface enables easy integration with programs like housemon 0.9 and openhab.

See https://github.com/SevenW/Plugwise-2-py

Have fun,
SevenW
SevenW
Starting Member
Starting Member
 
Posts: 25
Joined: May 2012

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby SevenW » Thu Sep 25, 2014 11:28 pm

Hi,

I have added a web-interface including a schedule editor. This may well be the first plugwise schedule editor in the linux open source domain.
The main Switch/Schedule control app is fully mobile device/touch enabled:

Image

The schedule editor is not touch-enabled, but supports excel like drag-to-copy and Ctrl-C/Ctrl-V to quickly copy blocks and columns:

Image

Please try if you like and submit issues on github if something appears to be broken, or you find difficulties to get it up and running.
See https://github.com/SevenW/Plugwise-2-py
and watch my blog for more details the coming days:
http://www.sevenwatt.com/main/

Have fun, SevenW
SevenW
Starting Member
Starting Member
 
Posts: 25
Joined: May 2012

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby Bwired » Fri Sep 26, 2014 3:40 pm

nice!
User avatar
Bwired
Administrator
Administrator
 
Posts: 5294
Joined: March 2006
Location: Netherlands

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby Phaeton » Fri Sep 26, 2014 11:38 pm

Looks great!

Verstuurd vanaf mijn Nexus 5 met Tapatalk
groeten,
Harry
User avatar
Phaeton
Advanced Member
Advanced Member
 
Posts: 561
Joined: May 2010
Location: Wassenaar

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby Strijker » Thu Nov 06, 2014 9:39 am

SevenW; first off - thanks for your efforts! I have it all running now and see lots of potential.
However; I am having trouble getting scheduling to work (at all) and cannot seem to find any documentation or hints on that.

some questions..

plug_schedule.JPG
Plug schedule variables
plug_schedule.JPG (15.04 KiB) Viewed 10129 times

filling a cell with a number 1 to ? turns it light orange and displays the number (I entered 100).
- I suppose this is the Standby-killer function.?
- what is the upper limit?

Filling the cell with 0 turns it grey
- Grey means OFF?

filling the cell with -1 turns it orange
- Orange means ON?

Assuming Orange=ON and Grey=OFF; will the plug switch OFF at 10:00 or at 9:45 ?



plug.JPG
plug control box
plug.JPG (16.3 KiB) Viewed 10129 times

Should I toggle the "Schedule" switch to run the schedule?
- sounds logical, but does not work as expected for me; it simply switches the plug on and off without relation to schedule as far as I can see.


plug_config.JPG
Plug config
plug_config.JPG (44.3 KiB) Viewed 10129 times

This configuration seems to follow of the above control box settings, so I guess this does not need specific settings to make the plug follow the set schedule?



How can I make the scripts start at boot? - do you have a best practice suggestion?

I am trying to figure out how to interface into Domoticz - would you happen to have some hints on that too maybe?


I know this is asking much - but this (to me) is a beautiful project I would love to see succeed!
Keep up the good work and let me know if I can help in any way?
Strijker
Starting Member
Starting Member
 
Posts: 4
Joined: November 2014

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby SevenW » Thu Nov 06, 2014 11:05 pm

Hi Strijker,

Thanks for your feedback. During testing schedules I once in a while stumbled into a situation where the schedule just would not switch, while every piece of logfile information indicated that the schedule was properly loaded into the circle. One can read a schedule checksum from the circle, which is good proof. Usually it worked the next day. I could not find a root cause. But lets start with the simple things first.

-1 = On, 0 = Off, positive value = standby wattage. Range? I am not sure whetehr there is an upper limit. Circles are rate 3680 Watt max, so I suspect that any value between 1 and 3680 works. Next time I go really deep into reverse engineering I can check this.

The "10" column means 10:00 AM. the "45" column to the left of it 9:45 AM.

You indeed can enable the schedule through the "plug control box" as you expected. I assume that with the upper switch you are able to switch the circle on and off. If not we may have to figure that out first.
Now when you switch the schedule on and off, you simply observe it switches the circle on and off. This can be explained for the following situation: Your schedule is mostly "ON". If the upper switch is in the "OFF" position, and your schedule says "ON" for that timeslot, then the circle switches on on enable the schedule, and it switches the circle to the requested position of the switch setting, which may be OFF.

So this is how it is suposed to work. Obviously it doesn't as you already tried a lot. Can you check the following:

The settings panel is only needed to indeed define the proper schedule. What you can do to see whether it operates with schedule is use a special test schedule. Set the schedule to "__PW2PY__test-alternate" and in the control box schedule = ON, then it should start switching every 15 minutes.

Is the time programmed in the circles correct? Every day at 4AM the clocks are synchronized. Seen from logging:
Code: Select all
2014-11-06 04:00:03,645 - pw-logger - INFO - sync_time: circle meter time is 04:00:01
2014-11-06 04:00:03,712 - pw-logger - INFO - Daily 4 AM: time synced circles.


If you see this, then the only thing that you have to make sure is that the clock of the computer it runs on is set correctly.

What you also can do is make a schedule that switches the circle off at for example 10AM every day of the week. Maybe there is a mix-up in days. I found something strange here.

So let me know what you found with a.o. the alternating schedule. You can PM me or send mail to info at my website domain for shorter turn around cycles in debuging.

SevenW
SevenW
Starting Member
Starting Member
 
Posts: 25
Joined: May 2012

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby Strijker » Fri Nov 07, 2014 9:45 am

Hi sevenW,
Thanks so much for that prompt response, the scheduling questions are all clear now.
I tried the test schedule and I can confirm that works properly; the circle is switched every 15 mins.
The logs also show a correct time sync at 4AM


Then I did the following:

First in the configuration window of the circle; I entered a new schedule name "_Wii"
Then I newly created that schedule "_Wii":
I edited the schedule into:
Everyday: OFF (cel value = 0 = grey) from 2:00 to 8:00
and clicked the checkbox-ok button of which I assume saves the schedule and sends it to the circle.
And went to bed.

This morning checking the plug around 7:32; it was ON ?!
But at 7:48, leaving the house if was OFF.

So looks like the alternating test schedule was still at work.

I cannot retrace from log anymore, but is there a specific order in doing this? - should I have created the schedule first and then assign it for example?
- I will try some more this evening and report back.

As for the other questions - starting at boot & Domoticz interfacing - No problem if you do not wish / know how to comment; as long as you haven't missed them...


How do I translate the timestamps in the logs? (~/datalog/2014/pwlog/pw-000D6F0000[plug].log)
(at '1415228400' I replaced a 60W bulb by a 0.4W charger with LED indicator)

Code: Select all
1415224800,         59.4061,         59.4061
1415228400,         50.2956,         50.2956
1415232000,          0.1613,          0.1613
1415235600,          0.1630,          0.1630
1415239200,          0.1636,          0.1636
1415242800,          0.1689,          0.1689
1415246400,          0.1671,          0.1671
1415250000,          0.1659,          0.1659
1415253600,          0.1648,          0.1648
1415257200,          0.1671,          0.1671
1415260800,          0.1689,          0.1689
1415264400,          0.1695,          0.1695
1415268000,          0.1695,          0.1695
1415271600,          0.1683,          0.1683
1415275200,          0.1677,          0.1677
1415278800,          0.1671,          0.1671
1415282400,          0.1677,          0.1677
1415286000,          0.1683,          0.1683
1415289600,          0.1701,          0.1701
1415293200,          0.3818,          0.3818
1415296800,          0.1648,          0.1648
1415300400,          0.1671,          0.1671
1415304000,          0.1677,          0.1677
1415307600,          0.1689,          0.1689
1415311200,          0.1683,          0.1683
1415314800,          5.2289,          5.2289
1415318400,         16.5699,         16.5699
1415322000,          0.2486,          0.2486
1415325600,          0.2475,          0.2475
1415329200,          0.2516,          0.2516
1415332800,          0.2486,          0.2486
1415336400,          0.2481,          0.2481
1415340000,          0.2492,          0.2492
1415343600,          0.2481,          0.2481
1415347200,          0.2692,          0.2692
Strijker
Starting Member
Starting Member
 
Posts: 4
Joined: November 2014

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby Strijker » Fri Nov 07, 2014 1:42 pm

Nevermind the last question about the timestamp translation:

date -d @[serial-time] seemed to do the trick:

$ tail -n 1 pwact-2014-11-07-000D6F0000${plug}.log
1415361600, 0.42

$ date -d @1415361600
Fri Nov 7 13:00:00 CET 2014
Strijker
Starting Member
Starting Member
 
Posts: 4
Joined: November 2014

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby SevenW » Fri Nov 07, 2014 11:36 pm

Hi Strijker,

The timestamp is the linux epoch, the seconds from 1-1-1970.
I never considered the use case of first selecting a schedule, and only create it. I can imaging that indeed it does not get read again. I suggest you just remove it in the settings editor, and than add it again. If you would
Code: Select all
tail -f /var/log/pw-logger.log
in a window at the same time, you should be able to see whether the change gets picked up. Maybe you need to increase log-level to debug, but then you get a lot.

In the control UI (boxes) you should also be able to read the actually active schedule. It should read _WII. So let me know whether you get this to work. Otherwise we can dive real deep into logfiles to investigate this.

Now on Domoticz, I do not have an answer. I could take a look. I think I am not using this domotica SW, because it was actaully assuming an additional 433MHz receiver that looked very propriatery to me. If it has MQTT interface, I may be able to implement the right protocol form the Plugwise-2-py side.

Startup:
I have the following lines in my /etc/rc.local (this depends on the linux distro)
Code: Select all
cd /home/plugwise2py #path your own plugwise scripts here
nohup python Plugwise-2.py >>/tmp/pwout.log&
cd config
nohup python Plugwise-2-web.py >>pwwebout.log&


SevenW
SevenW
Starting Member
Starting Member
 
Posts: 25
Joined: May 2012

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby Strijker » Sat Nov 08, 2014 10:00 am

Hello SevenW,

Again thanks for your efforts helping me get on track! Finally this morning I found the 'problem' with scheduling; It seems the scheduler is one hour off in my setup..


this morning, I loaded this schedule around 8:54 while the lamp was off (log at the bottom):
test_sched.PNG
testing
test_sched.PNG (4.33 KiB) Viewed 9947 times


the light actually turned on at exactly 9:00 and off again at 9:30
it stayed off at 9:45

So without a doubt:
- orange is ON
AND
- 9:00 actual time is 10:00 in the scheduler


I am running a Raspberry with timezone set to Europe - Amsterdam

Code: Select all
pi@domoticzpi ~ $ date
Sat Nov  8 09:50:21 CET 2014
pi@domoticzpi ~ $ date -u
Sat Nov  8 08:50:26 UTC 2014
pi@domoticzpi ~ $



log of loading the schedule (6_wii):
Code: Select all
2014-11-08 08:54:04,916 - pw-logger - INFO - 000D6F0000${aplug}: save log
2014-11-08 08:54:21,218 - pw-logger - INFO - generate schedule: __PW2PY__test-alternate
2014-11-08 08:54:21,245 - pw-logger - INFO - generate schedule: __PW2PY__test-10
2014-11-08 08:54:21,257 - pw-logger - INFO - import   schedule: _Wii.json
2014-11-08 08:54:21,275 - pw-logger - INFO - import   schedule: bedtijd.json
2014-11-08 08:54:21,293 - pw-logger - INFO - import   schedule: testsched1.json
2014-11-08 08:54:21,314 - pw-logger - INFO - import   schedule: testsched2.json
2014-11-08 08:54:21,330 - pw-logger - INFO - import   schedule: __WWi.json
2014-11-08 08:54:21,338 - pw-logger - INFO - import   schedule: 6_wii.json
2014-11-08 08:54:21,363 - pw-logger - INFO - import   schedule: winter.json
2014-11-08 08:54:21,380 - pw-logger - INFO - apply_schedule_changes: schedule changed. Update in circle wii - 6_wii
2014-11-08 08:54:21,384 - pw-logger - INFO - circle.define_schedule.
2014-11-08 08:54:21,407 - pw-logger - INFO - circle.schedule._shift_day rotate left by one day
2014-11-08 08:54:21,510 - pw-logger - INFO - circle.schedule._dst_shift rotate left [start of DST]
2014-11-08 08:54:21,540 - pw-logger - INFO - API  000D6F0000${THEplug} wii circle schedule off
2014-11-08 08:54:21,602 - pw-logger - INFO - circle.load_schedule. enter function
2014-11-08 08:54:27,379 - pw-logger - INFO - circle.load_schedule. exit function
2014-11-08 08:54:27,577 - pw-logger - INFO - API  000D6F0000${THEplug} wii circle schedule on
2014-11-08 08:55:01,626 - pw-logger - INFO - 000D6F000${aplug}: save log
2014-11-08 08:55:01,871 - pw-logger - INFO - 000D6F000${aplug}: save log
Strijker
Starting Member
Starting Member
 
Posts: 4
Joined: November 2014

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby SevenW » Sat Nov 08, 2014 10:55 pm

Hi Strijker,

Thanks for finding this bug in determining whether it is daylight saving time or not. I solved it. You should get the (latest) file Plugwise-2.py from github and then put it in your Plugwise-2py folder.

Now you may find the Wii is not an easy machine to standby-kill. But switch off during night is easy enough. Let me know. The thing is also on my list for a circle.

Regarding domoticz. It looks like it requires maybe some javascript to be written, and maybe some LUA script, to process incoming MQTT messages. It would help if you could point me to some nice example scripts that already take some incoming MQTT in domoticz. Plugwise-2-py maybe easy to adapt to send MQTT messages recognized by domoticz. Can you do some javascript/lua programming yourself on the domoticz side?

SevenW
SevenW
Starting Member
Starting Member
 
Posts: 25
Joined: May 2012

Re: Plugwise-2-py - an evolution of earlier python/linux work

Postby Stephan296 » Tue Jan 20, 2015 1:23 am

I want to install this software but i can't get it started.
None of the command will work on the pi.

When i start: nohup python Plugwise-2.py >>/tmp/pwout.log&
i get: nohup: ignoring input and redirecting stderr to stdout
Stephan296
Starting Member
Starting Member
 
Posts: 10
Joined: May 2011

Next

Return to Plugwise Forum

Who is online

Users browsing this forum: No registered users and 1 guest