Page 1 of 1

Plugwise circle / stealth - plugin

Posted: Monday 11 November 2019 21:37
by ghulleman
Hi all

Just wanted to share a plugin I wrote thusfar (not my best work ;-) ) Since I seem unable find how to create a wiki account, I just post it here. This plugin communicates with the stretch (unlike the plugwise2py, which communicates directly with the USB-stick) and allow basis switch operations and logging of current power consumption. No total usage at this moment.

Step 1: create a folder under the domoticz\plugins, called Plugwise. Another name will require a change in the python code.
Step 2: create a file "plugin.py" in this folder, containing the code below (in plugin.txt, as the form does not allow .py files).
Step 3: restart domoticz
Step 4: add hardware (Plugwise should be in the hardware list). Setup parameters....
- Devices should be added to the setup upon start of the plugin.
Step 5: add unused devices to the UI.

Note: In the plugin folder, a file is created 'devices.json'. This file contains the link between circle/sensor and unitid in domoticz. Do _not_ deleted (unused) devices in domoticz or this file if you do not know what you are doing as this will case a mismatch between plugwise/plugin/domoticz. Also, if debug is enabled, a log.txt file is created. As my experience is that when you make a mistake as a developer, domoticz UI is unresponsive and you cannot access the internal log.

Reset:
If you made a mess: delete the 'hardware', delete the devices.json and repeat from step 4.

This is provided as-is, feel free to use this as you please and extend on it. Do try to help the community and publish any improvements, please.
plugin.txt
(19.27 KiB) Downloaded 191 times

Re: Plugwise circle / stealth - plugin

Posted: Monday 11 November 2019 23:57
by waaren
ghulleman wrote: Monday 11 November 2019 21:37 Just wanted to share a plugin I wrote thusfar. Since I seem unable find how to create a wiki account,
Please contact @Gizmocuz via forum PM to get a WIKI account. Creation of new accounts is temporary disabled because of large amounts of SPAM user creations attacks.

Re: Plugwise circle / stealth - plugin

Posted: Tuesday 12 November 2019 16:11
by jeroenkl
great, but got some errors:

Code: Select all

2019-11-12 16:09:24.733 Status: (Plugwise) Started.
2019-11-12 16:09:25.569 (Plugwise) Loading parameters
2019-11-12 16:09:25.570 (Plugwise) Loading appliances from stretch
2019-11-12 16:09:25.562 Status: (Plugwise) Entering work loop.
2019-11-12 16:09:25.563 Status: (Plugwise) Initialized version 1.0.0, author 'Gerrit Hulleman'
2019-11-12 16:09:40.408 Error: (Plugwise) 'onHeartbeat' failed 'KeyError'.
2019-11-12 16:09:40.408 Error: (Plugwise) ----> Line 371 in '/home/pi/domoticz/plugins/Plugwise/plugin.py', function onHeartbeat
2019-11-12 16:09:40.408 Error: (Plugwise) ----> Line 181 in '/home/pi/domoticz/plugins/Plugwise/plugin.py', function onHeartbeat
2019-11-12 16:09:40.408 Error: (Plugwise) ----> Line 284 in '/home/pi/domoticz/plugins/Plugwise/plugin.py', function getModuleDataFromNode
2019-11-12 16:09:49.946 (Plugwise) onHeartbeat called

at the first start I saw all my plugs in the domoticz log passing.

Code: Select all


2019-11-12 16:14:04.993 Status: (Plugwise) Started.
2019-11-12 16:14:05.827 (Plugwise) Loading parameters
2019-11-12 16:14:05.828 (Plugwise) Loading appliances from stretch
2019-11-12 16:14:05.818 Status: (Plugwise) Entering work loop.
2019-11-12 16:14:05.819 Status: (Plugwise) Initialized version 1.0.0, author 'Gerrit Hulleman'

2019-11-12 16:14:09.014 (Plugwise) Processing appliances
2019-11-12 16:14:09.015 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.017 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.017 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.018 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.019 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.020 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.021 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.021 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.022 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.023 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.024 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.024 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.025 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.026 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.027 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.028 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.028 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.029 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.030 (Plugwise) Appliance found: xxxx - xxxx
2019-11-12 16:14:09.031 (Plugwise) Loading mapped devices from config file
2019-11-12 16:14:09.031 (Plugwise) 0 devices loaded from configuration file
2019-11-12 16:14:09.032 (Plugwise) 'Language':'nl'
2019-11-12 16:14:09.032 (Plugwise) 'Mode6':'Debug'
2019-11-12 16:14:09.032 (Plugwise) 'Name':'Plugwise'
2019-11-12 16:14:09.032 (Plugwise) 'Address':'192.168.2.17'
2019-11-12 16:14:09.032 (Plugwise) 'Key':'PlugwiseStretch'
2019-11-12 16:14:09.032 (Plugwise) 'Port':'0'
2019-11-12 16:14:09.032 (Plugwise) 'Database':'/home/pi/domoticz/domoticz.db'
2019-11-12 16:14:09.032 (Plugwise) 'DomoticzVersion':'4.11468'
2019-11-12 16:14:09.032 (Plugwise) 'StartupFolder':'/home/pi/domoticz/'
2019-11-12 16:14:09.032 (Plugwise) 'HardwareID':'38'
2019-11-12 16:14:09.032 (Plugwise) 'Author':'Gerrit Hulleman'
2019-11-12 16:14:09.032 (Plugwise) 'UserDataFolder':'/home/pi/domoticz/'
2019-11-12 16:14:09.033 (Plugwise) 'HomeFolder':'/home/pi/domoticz/plugins/Plugwise/'
2019-11-12 16:14:09.033 (Plugwise) 'DomoticzHash':'xxxx'
2019-11-12 16:14:09.033 (Plugwise) 'Mode1':'10'
2019-11-12 16:14:09.033 (Plugwise) 'Password':'xxxxxx'
2019-11-12 16:14:09.033 (Plugwise) 'Version':'1.0.0'
2019-11-12 16:14:09.033 (Plugwise) 'DomoticzBuildTime':'2019-11-05 16:05:44'
2019-11-12 16:14:09.033 (Plugwise) 'Username':'stretch'
2019-11-12 16:14:09.033 (Plugwise) Device count: 0
2019-11-12 16:14:09.033 (Plugwise) Last unitId : 0
2019-11-12 16:14:09.034 (Plugwise) Heartbeat : 10
2019-11-12 16:14:09.035 (Plugwise) Plugin operational
What to do next?

thanks, Jeroen

Re: Plugwise circle / stealth - plugin

Posted: Wednesday 13 November 2019 8:33
by ghulleman
Line 284 which causes can be commented out. It was used during debugging and seems no longer used.

I believe you have some hardware that I do not have in your system. My setup only has circles, senses, a button and stealths. Line 284 retrieves the 'type' of devices, which is present in my modules.

Try logging the 'ModuleNode' parameter and check the XML.

Re: Plugwise circle / stealth - plugin

Posted: Wednesday 13 November 2019 13:30
by jeroenkl
ghulleman wrote: Wednesday 13 November 2019 8:33 Line 284 which causes can be commented out. It was used during debugging and seems no longer used.

I believe you have some hardware that I do not have in your system. My setup only has circles, senses, a button and stealths. Line 284 retrieves the 'type' of devices, which is present in my modules.

Try logging the 'ModuleNode' parameter and check the XML.
I'm using circles only, It looks like something is wrong and causes this main heartbeat error unfortunately.
2019-11-13 13:28:58.852 Error: (Plugwise_stretch) 'onHeartbeat' failed 'KeyError'

Re: Plugwise circle / stealth - plugin

Posted: Friday 15 November 2019 9:03
by jeroenkl
somehow no file is created also:
Note: In the plugin folder, a file is created 'devices.json'. This file contains the link between circle/sensor and unitid in domoticz. Do _not_ deleted (unused) devices in domoticz or this file if you do not know what you are doing as this will case a mismatch between

Code: Select all

2019-11-15 09:01:35.993 Status: (Plugwise_stretch) Started.
2019-11-15 09:01:36.834 (Plugwise_stretch) Loading parameters
2019-11-15 09:01:36.834 (Plugwise_stretch) Debug logging mask set to: NONE
2019-11-15 09:01:36.834 (Plugwise_stretch) Loading appliances from stretch
2019-11-15 09:01:36.825 Status: (Plugwise_stretch) Entering work loop.
2019-11-15 09:01:36.825 Status: (Plugwise_stretch) Initialized version 1.0.0, author 'Gerrit Hulleman'
2019-11-15 09:01:40.039 (Plugwise_stretch) Processing appliances
2019-11-15 09:01:40.044 (Plugwise_stretch) Loading mapped devices from config file
2019-11-15 09:01:40.045 (Plugwise_stretch) 0 devices loaded from configuration file
2019-11-15 09:01:40.045 (Plugwise_stretch) Plugin operational
2019-11-15 09:01:51.390 Error: (Plugwise_stretch) 'onHeartbeat' failed 'KeyError'.
2019-11-15 09:01:51.390 Error: (Plugwise_stretch) ----> Line 371 in '/home/pi/domoticz/plugins/Plugwise/plugin.py', function onHeartbeat
2019-11-15 09:01:51.390 Error: (Plugwise_stretch) ----> Line 181 in '/home/pi/domoticz/plugins/Plugwise/plugin.py', function onHeartbeat
2019-11-15 09:01:51.390 Error: (Plugwise_stretch) ----> Line 284 in '/home/pi/domoticz/plugins/Plugwise/plugin.py', function getModuleDataFromNode
@ghulleman, can you please assist?

BR, Jeroen

Re: Plugwise circle / stealth - plugin

Posted: Friday 15 November 2019 21:50
by ghulleman
I have updated the plugin and added two things:
1. Try catch, so modules that do not process correctly will not stop the plugin
2. Dump the module-XML causing the problem (only if debug mode is enabled).

This will not fix the issue, but it will give me some details on why this is not working for you people. Please provide the XML in the log that causes the error.

If this does not work, please uncomment lines 180 and 181 and try to send the entire xml file.

Re: Plugwise circle / stealth - plugin

Posted: Saturday 16 November 2019 17:28
by jeroenkl
ghulleman wrote: Friday 15 November 2019 21:50 I have updated the plugin and added two things:
1. Try catch, so modules that do not process correctly will not stop the plugin
2. Dump the module-XML causing the problem (only if debug mode is enabled).

This will not fix the issue, but it will give me some details on why this is not working for you people. Please provide the XML in the log that causes the error.

If this does not work, please uncomment lines 180 and 181 and try to send the entire xml file.
Great thanks!
a lot of the same errors caught for each plugs I have currently installed:

Code: Select all

Exception caught
<module id="xxxxx">
		<vendor_name>Plugwise</vendor_name>
		<vendor_model>NR</vendor_model>
		<hardware_version>6539-0701-4023</hardware_version>
		<firmware_version>2011-06-27T10:52:18+02:00</firmware_version>
		<created_date>2016-12-22T20:19:46.844+01:00</created_date>
		<modified_date>2019-02-02T10:14:29.198+01:00</modified_date>
		<deleted_date />
		<services>
			<electricity_point_meter id="xxxxxx">
				<measurement directionality="consumed" log_date="2019-02-02T10:14:29.134+01:00" unit="W">11.47</measurement>
				<measurement directionality="produced" log_date="2019-02-02T10:14:29.134+01:00" unit="W">0.00</measurement>
			</electricity_point_meter>
			<electricity_interval_meter id="xxxxx">
				<measurement directionality="consumed" interval="PT1H" log_date="2019-02-02T10:00:00+01:00" unit="Wh">2.70</measurement>
				<measurement directionality="produced" interval="PT1H" log_date="2019-02-02T10:00:00+01:00" unit="Wh">0.00</measurement>
			</electricity_interval_meter>
			<relay id="xxxxx">
				<measurement log_date="2019-02-02T10:14:06.451+01:00">on</measurement>
			</relay>
		</services>
		<protocols>
			<network_router id="xxxxx"><mac_address>000D6F0000xxxxx</mac_address><network id="xxxxx" /></network_router>
		</protocols>
	</module>

Re: Plugwise circle / stealth - plugin

Posted: Saturday 16 November 2019 21:55
by ghulleman
It was the modelname. The XML returned from my stretch returned with an attribute. The file has been updated in the original post. Please let me know if this works for you.

Re: Plugwise circle / stealth - plugin

Posted: Sunday 17 November 2019 9:23
by jeroenkl
ghulleman wrote: Saturday 16 November 2019 21:55 It was the modelname. The XML returned from my stretch returned with an attribute. The file has been updated in the original post. Please let me know if this works for you.
Yes! Almost there!! , got all the Plugs (missing 1) in Domoticz as a device.


2019-11-17 09:16:14.255 (Plugwise_stretch) Exception caught
2019-11-17 09:16:14.268 (Plugwise_stretch) <module id="8f030ae42df54f5b9a1xxxxxxxxx">
2019-11-17 09:16:14.268 <vendor_name>Plugwise</vendor_name>

LOG XML for this:

Code: Select all

Exception caught
<module id="8f030ae42df54f5b9a1xxxxxxxxxx">
		<vendor_name>Plugwise</vendor_name>
		<vendor_model>NC</vendor_model>
		<hardware_version />
		<firmware_version />
		<created_date>2016-01-09T20:21:28.380+01:00</created_date>
		<modified_date>2016-12-22T17:07:51.122+01:00</modified_date>
		<deleted_date />
		<services>
			<electricity_point_meter id="48fa5647622046aaa1c34f74f2xxxxxx">
			</electricity_point_meter>
			<relay id="8f673845818e478aae5fc94525xxxxx">
			</relay>
			<electricity_interval_meter id="674293332f4e4c8390958fd0exxxxx">
			</electricity_interval_meter>
		</services>
		<protocols>
			<network_coordinator id="965f231030d74815823962xxxxxxx"><mac_address>000xxxxxxxx</mac_address><network id="d49d49f054b346409d5xxxxx" /></network_coordinator>
		</protocols>
	</module>
	
Found: It is a 'second circle+' which should not be part of my network. I'm not using it, only the first circle+. Unfortunately I cannot remove it from the stretch application.
Can you avoid this error in the Plugwise plugin?



Can you fix this also?
thanks in advance!

regards,

Jeroen

Re: Plugwise circle / stealth - plugin

Posted: Tuesday 15 December 2020 23:32
by WillemV
Thank you for this, works like a charm.
I am, however, also trying to get the Energy logging going.

Therefor I would like to read data from the Domoticz.db
Unfortunately I have little experience with Python.

In line 239 near the bottom of the def onHeartbeat(self): section the following command updates a record in the database:
self.updateDevice(deviceUnitId, 0, str(valDouble)+';0', True)

There has to be a similar command to read the sValue from the DeviceStatus table in the db.
After that I want to recalculate that value and update the table with that new value.
However I can't figure out the syntax for a read or get command.

Any assistance would be very welcome.

Re: Plugwise circle / stealth - plugin

Posted: Sunday 31 January 2021 12:32
by Jrienks
Plugwise heeft een doorstart gemaakt, waardoor er geen grafieken van energieverbruik meer worden aangeboden via de Plugwise app. Als alternatief kun je terugvallen op Source, maar dan moet je de Stick uit de Stretch halen, waardoor je de app niet meer kunt gebruiken en die is wel handig voor actuele data en schakelschema's.

Ik ben op zoek naar een manier om de Stretch uit te lezen en dan zelf de verbruiken van de circles op te slaan. Kan dat via Domoticz zonder extra hardware of de stick uit de Stretch te halen?

Re: Plugwise circle / stealth - plugin

Posted: Sunday 07 February 2021 19:10
by freekdk
I have a combined bash script and pearl script to get the values from the smile and calculate 5 minutes W averages. The smile has about each 8 seconds a new value for used and produced Watt. So averaging this during 5 minutes and multiplying this by 5/60=1/12 gives the produced/consumed Wh.

One can do the same thing in the Python script, provided the heartbeat is set to less than 8, say 6 seconds. The previous time of the measure of the Watt value should be saved and the value forgotten if this time is the same as the current time. The Wh calculated each 5 minutes should be stored in the location where the widget shows the produced(-)/consumed(+) Wh during that day. When the day ends the Wh value starts from 0.

My problem is where and how this Wh value should be stored.

Re: Plugwise circle / stealth - plugin

Posted: Monday 08 February 2021 12:09
by freekdk
Just found out that in the line:

Code: Select all

self.updateDevice(deviceUnitId, 0, str(valDouble)+';0', True) # force update...
one needs to replace the zero in ";0" by the value of the used/produced energy in Wh.
Will develop the necessary python code to show the use/production during the day.

Re: Plugwise circle / stealth - plugin

Posted: Wednesday 10 February 2021 18:16
by freekdk
I managed to change the code so used/produced energy is accounted for. Could not get previous counter values from the database, but I use a file for each device to keep track of the counter value. I have no idea how to upload the new source.

Re: Plugwise circle / stealth - plugin

Posted: Thursday 11 February 2021 16:42
by freekdk
The hack with the file to store the previous counter value is not needed.
Devices[unitID].sValue contains the previous stored sValue, which contains two numbers: Watt and counter.
So Devices[unitID].sValue.split(';')[1] gives you the previous value of the total Wh used/produced.