Page 1 of 1
Detecting meters that no longer update
Posted: Thursday 18 August 2016 23:32
by WebSpider
Hi!
I have a meter (Everspring AN181, Z-Wave) that measures power in a shed. However, sometimes someone accidentally turns off the power to the shed, and stuff like a fridge doesn't like that.
Is there any way I can fire events on the latest update of a device, or the absence of a Z-Wave node from the mesh?
Re: Detecting meters that no longer update
Posted: Friday 19 August 2016 7:11
by Egregius
If you have a look at my pass2php script you'll find examples of that.
I receive message if a node is marked as dead and also when a devices hasn't sent anything for 4 hours.
Re: Detecting meters that no longer update
Posted: Saturday 27 August 2016 14:19
by WebSpider
Thanks for the reply. I just looked at it, and if I get it right, you are using lua, to pass openzwave values to php, which then starts influencing Domoticz .. Why not use the commandArray['SendNotification'] (for me) or commandArray['UpdateDevice']?
Anyway, thanks a bunch for pointing out Lua can catch this
Re: Detecting meters that no longer update
Posted: Saturday 27 August 2016 15:18
by Egregius
Because I don't know anything about lua and I love PHP code.
the pass2php lua script passes all statusses, updatetimes, svalues etc to a php script. There it's put in arrays so they can be used to trigger anything you can imagen.
Re: Detecting meters that no longer update
Posted: Sunday 28 August 2016 22:56
by WebSpider
This turned out to be very doable in the native LUA, please find snippet below
Code: Select all
commandArray = {}
function timedifference (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
upd_delta = timedifference (otherdevices_lastupdate['Verbruik Vrieskist'])
print("Vrieskist not updated since "..upd_delta.." seconds");
if (upd_delta > 900) then
commandArray['SendEmail']='Vrieskist problemen#Al '..upd_delta..' seconden geen update van de vrieskist meer ontvangen#[email protected]'
end
Re: Detecting meters that no longer update
Posted: Monday 29 August 2016 18:22
by bizziebis
This works, however if the condition is true it will send you an email every minute (if used as a time script).
I've added an uservariable which is set when the email is sent. From this variable I check if the time difference since last update is > 1800. So I get an email every 30 minutes.
Re: RE: Re: Detecting meters that no longer update
Posted: Wednesday 31 August 2016 1:59
by havnegata
bizziebis wrote:
I've added an uservariable which is set when the email is sent. From this variable I check if the time difference since last update is > 1800. So I get an email every 30 minutes.
Can you please post the code for this! I have a couple of scripts with notifications beeing sent every minute, and would really like to avoid this
Re: Detecting meters that no longer update
Posted: Wednesday 31 August 2016 6:56
by bizziebis
Sure, just like this:
Code: Select all
difference = timedifference(otherdevices_lastupdate['Sensor1'])
if difference > 3700 then
if timedifference(uservariables_lastupdate['Sensor1 Notification']) > 3600 then
print('No data received for '..difference ..' seconds')
send_notification('Tom','No data received from sensor 1')
commandArray['Variable:Sensor1 Notification']='TIMER'
end
end
send_notification() is my own function, just replace it by something that will send you a notification.
'Sensor1 Notification' is an Uservariable of the type string which has to be created first.