Updated Plugwise Stretch script

Must be cleaned all topics go to the right subforum
Post Reply
ThaBoo
Posts: 7
Joined: Saturday 15 February 2014 18:38
Target OS: Raspberry Pi
Domoticz version:
Contact:

Updated Plugwise Stretch script

Post by ThaBoo » Saturday 04 June 2016 20:12

Hi,

I have completely rewritten my previous plugwise stretch reading script to a version that does not need virtual devices nor translation tables or ram disk space. The script has been running stable for 3 months now in my setup.

The only thing needed in advance is a plugwise hardware declaration in domoticz. After that the plugwise devices will just show up in the domoticz devices menu.

Notes:
- Since I have only switching plugs and thermo/hygro meters, these are the devices that are supported right now.
- A plug will show up as 2 devices: a switch and a energy metering device.
- The script will NOT allow you to change the switch state of a plugwise plug.

I have no time at hand for extensive documentation but here it is for your inspiration:

Code: Select all

#!/bin/bash

# Prerequisites:
# Tested only on a raspberry Pi
# Installation of xmlstarlet ('sudo apt get xmlstarlet')
# I am not aware anymore if curl is part of the standard domoticz distribution, otherwise go and get it.
# In Domoticz, configure a hardware device called "Plugwise Stretch" and enter the ID# of that in the header line below.

#Plugwise Stretch parameters
#Stretchpassword can be found on the strech detail
stretchIP=xxx.xxx.xxx.xxx
stretchPassword=yyyyyyyy
#adapt the header to match address and port number where the Domoticz json is available. Change "hid=x" to the hardware 
# ID of the plugwise hardeware in your domoticz configuration. For me, it is 2.

header="http://raspberrypi.local:8080/json.htm?type=command&param=udevice&hid=2&did="

#script starts here

result=`curl -s --user stretch:$stretchPassword $stretchIP/core/modules | xmlstarlet sel -I -t -m "/modules/module" -v "concat( vendor_model,' ',protocols/master_controller/mac_address,protocols/network_router/mac_address,protocols/network_coordinator/mac_address,protocols/sleeping_end_device/mac_address,' ',services/motion_trigger/measurement,services/thermo_meter/measurement,services/electricity_point_meter/measurement[@directionality='consumed'],' ',services/hygro_meter/measurement,services/electricity_point_meter/measurement[@directionality='produced'],' ',services/electricity_interval_meter/measurement[@directionality='consumed'],' ',services/electricity_interval_meter/measurement[@directionality='produced'],' ',services/relay/measurement,' ',services/relay/@id)" -n` 

declare -a stream=( $result )
element_count=${#stream[@]}

i=0
while [ "$i" -lt "$element_count" ]
do
	if [[ ${stream[$i]} == N* ]]
	then \

		echo ${stream[$i]}"|id:"${stream[$i+1]}"|c1:"${stream[$i+2]}"|u1:"${stream[$i+3]}"|c2:"${stream[$i+4]}"|u2:"${stream[$i+5]}
		curl -s `echo ${header}$((0x${stream[$i+1]:8}))"&dunit=1&dtype=90&dsubtype=1&nvalue=0&svalue="${stream[$i+2]}";"${stream[$i+4]}` > /dev/null
		curl -s `echo ${header}$((0x${stream[$i+1]:8}))"&dunit=2&dtype=90&dsubtype=1&nvalue=0&svalue="${stream[$i+3]}";"${stream[$i+5]}` > /dev/null
		if [[ ${stream[$i+6]} == on ]]
		then \
				switchstatus=1
		else
				switchstatus=0
		fi
		echo ${stream[$i]}"|id:"${stream[$i+1]}"|sw:"${switchstatus}
		curl -s `echo ${header}${stream[$i+1]:8}"&dunit=3&dtype=17&dsubtype=0&nvalue="${switchstatus}` > /dev/null
		i=$i+5
		sleep 0.5
	else
		if [[ ${stream[$i]} == SE ]]
		then \
			humidity=`expr substr ${stream[$i+3]} 1 2`
			echo ${stream[$i]}"|id:"${stream[$i+1]}"|tm:"${stream[$i+2]}"|hm:"${humidity}
			curl -s `echo ${header}$((0x${stream[$i+1]:8}))"&dunit=1&dtype=82&dsubtype=1&nvalue=0&svalue="${stream[$i+2]}";"$humidity";0"` > /dev/null
			i=$i+2
			sleep 0.5
		else
			if [[ ${stream[$i]} == SC ]]
			then \
#				echo ${header}${stream[$i+1]:8}"&dunit=1&dtype=XX&nvalue="${stream[$i+2]}
				i=$i+2
				sleep 0.5
			fi
		fi
	fi
	((i++))
done
 
Domoticz, Raspberry Pi, RFXCom, Plugwise Stretch & Smile, KlikaanKlikuit, EQ3 Max!, Foscam, Harmony Hub, Oregon Scientific

RayAmsterdam
Posts: 190
Joined: Sunday 11 January 2015 17:40
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Updated Plugwise Stretch script

Post by RayAmsterdam » Tuesday 14 February 2017 21:47

Hello,

Can you help me getting this script working? I have copied the script in 'plugwise.sh'. I modified the StretchIP, StretchPassword and the hid.
When I run the scriot from the command line (SSH) I get the following result:

Code: Select all

[email protected]:~ $ /home/pi/domoticz/scripts/plugwise.sh
NR|id:000D6F000261B09C|c1:0.00|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F000261B09C|sw:1
NR|id:000D6F000261B5A4|c1:0.00|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F000261B5A4|sw:1
NR|id:000D6F0003558889|c1:0.95|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F0003558889|sw:1
NR|id:000D6F000261B5A6|c1:0.00|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F000261B5A6|sw:1
NC|id:000D6F000258727F|c1:42.83|u1:0.00|c2:18.31|u2:0.00
NC|id:000D6F000258727F|sw:1
NR|id:000D6F000261B593|c1:0.85|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F000261B593|sw:1
NR|id:000D6F00036BC40B|c1:0.00|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F00036BC40B|sw:1
NR|id:000D6F0003558B9C|c1:1.11|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F0003558B9C|sw:1
NR|id:000D6F00036BC372|c1:5.17|u1:0.00|c2:1.46|u2:0.00
NR|id:000D6F00036BC372|sw:1
NR|id:000D6F000261B08F|c1:1.31|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F000261B08F|sw:1
NR|id:000D6F000261B099|c1:1.33|u1:0.00|c2:0.00|u2:0.00
NR|id:000D6F000261B099|sw:1
NR|id:000D6F0003558B45|c1:0.00|u1:0.00|c2:0.56|u2:0.00
NR|id:000D6F0003558B45|sw:1
NR|id:000D6F000261B0BF|c1:44.63|u1:0.00|c2:9.63|u2:0.00
NR|id:000D6F000261B0BF|sw:1
SE|id:000D6F00019DCB79|tm:21.90|hm:58
NR|id:000D6F00035588B1|c1:3.80|u1:0.00|c2:1.14|u2:0.00
NR|id:000D6F00035588B1|sw:1
In Domoticz the plugs don't appear in the device list. What am I doing wrong?

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests