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¶m=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