@Egregius, Thanks for sharing this script. It is a real nice option to refresh devices.
I have a couple TKB dimmers which also don't update correctly and with this script they update fine.
I have also implemented this on a couple of ZWAVE.ME and POPP devices as they only sometimes don't update correctly.
One thing I noticed is that when you add the on/off action scripts like you specified, it seems the eventsystem gets "blocked" until the script ends before processing the next event.
Most devices report statuses several times which means that the script runs 2-4 times for each device each time.
This means that when I switches several devices Off or On at the same time, the event system became slow/unresponsive for quite a number of seconds.
The way I have worked around that is to put a bash script in between which is fired by the device On/Off action and doesn't wait for the php to end. It will also check whether the PHP refresh is already running for that particular device in which case it skips firing the php again.
This is the script I create for each device I want to do a refresh for: ( e.g. script:///home/pi/domoticz/scripts/refresh/refresh-tafel.sh)
Code: Select all
#!/bin/bash
#~ Specify the ZWAVE NodeID to refresh
devid=37
#~ Check whether the refrsh is already running for this device and only fire when not.
chk=`sudo ps x | grep "refresh-zwavedevice.php $devid" | grep -cv grep`
if [ "$chk" = "0" ] ; then
php /home/pi/domoticz/scripts/refresh/refresh-zwavedevice.php $devid >> /var/tmp/refresh.log 2>&1 &
else
echo "$(date +%x) $(date +%X) Already running for $devid" >> /var/tmp/refresh.log 2>&1 &
fi
The PHP look like yours with the addition of the parameter containing the Zwave NodeID:
Code: Select all
#!/usr/bin/php
<?php
$devices=file_get_contents('http://127.0.0.1:8080/json.htm?type=openzwavenodes&idx=5'); //Change IDX to IDX of your zwave controller
function RefreshZwave($node) {
echo date("m/d/y H:i:s "),"Start Refresh for $node\n";
$zwaveurl='http://127.0.0.1:8080/ozwcp/refreshpost.html';
$zwavedata=array('fun'=>'racp','node'=>$node);
$zwaveoptions = array('http'=>array('header'=>'Content-Type: application/x-www-form-urlencoded\r\n','method'=>'POST','content'=>http_build_query($zwavedata),),);
$zwavecontext=stream_context_create($zwaveoptions);
//~ print_r($zwaveoptions);
//~ print_r($zwavecontext);
for ($k=1;$k<=5;$k++){sleep(2);$result=file_get_contents($zwaveurl,false,$zwavecontext);echo date("m/d/y H:i:s "),"refresh ",$node," ",$result,"\n";if($result=='OK') break;}
}
if(!empty($argv[1])) {
RefreshZwave($argv[1]);
}
else {
echo date("m/d/y H:i:s "),"no idx defined\n";
}
As you can see, it also creates a log file so I can see what is going on.
Cheers
Jos