Page 1 of 1
Notification when sensor is not working
Posted: Sunday 03 January 2016 13:37
by DasK
I guess this is common issue, but I swear I searched and I couldn't find anything.
I just want to get a notification when a sensor stop working (low battery, out of range, broken....)
I suppose I could use lastupdate variable, witch I believe only works in LUA and not in blockly, but there has to be an easy way to address this, since domoticz knows the sensor is not working because it turns the label red.

So my question is: Is there some variable that can be checked (better in blockly) to say: If this sensor is marked in red (not working) then send a notification?
Re: Notification when sensor is not working
Posted: Saturday 09 January 2016 12:50
by jake
Yes, I have the same, but then sometimes with a switch. I would like to automatic 'heal' the switch connection when connection is lost. At least be informed by NMA
Verstuurd vanaf mijn Transformer TF101 met Tapatalk
Re: Notification when sensor is not working
Posted: Saturday 09 January 2016 13:10
by sincze
I can share my code how I deal with this in lua if you want?? Sometimes my OTGW needs to be 'switched' off and back on.
Sent from my SM-G925F using Tapatalk
Re: Notification when sensor is not working
Posted: Saturday 09 January 2016 21:41
by jake
sincze wrote:I can share my code how I deal with this in lua if you want?? Sometimes my OTGW needs to be 'switched' off and back on.
Sent from my SM-G925F using Tapatalk
yes, please
Re: Notification when sensor is not working
Posted: Sunday 10 January 2016 11:06
by sincze
I use the following code if a device is not responding anymore)
Code can be easily modified if you router is not responding to internet for example.
Code: Select all
---------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Debug = "YES" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Script functions
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- Command Array functions
----------------------------------------------------------------------------------------------------------
function datetimedifferencenow(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
----------------------------------------------------------------------------------------------------------
-- Command Tools & Examples
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- Declare & Fill variables
----------------------------------------------------------------------------------------------------------
commandArray = {}
-- First check several devices if they responded within 300 seconds (5 mminutes) & check that the 433 mhz switch is ON.
-- I don't switch based upon 1 OTGW device I use several to make sure it is not working.
if (datetimedifferencenow(otherdevices_lastupdate['Max. Vloerverwarming']) > 300 and
(datetimedifferencenow(otherdevices_lastupdate['OTGW - Outside Temperature'])) > 300 and
(datetimedifferencenow(otherdevices_lastupdate['Socket OTGW'])) > 300 and
(otherdevices['Socket OTGW'] == 'On')
) then
-- Switch OFF the socket and send some LOG information + PUSHOVER notification
commandArray['Socket OTGW'] = 'Off'
print("OTGW: OTGW Reageert niet Let OP!")
commandArray['SendNotification']='ALERT OTGW#OTGW Reageert niet, Switching Off Socket#0'
print("OTGW: Switching off Socket!")
else
-- Now check if lastupdate of socket has been updated within 5 minuts and if it is switched off
if (datetimedifferencenow(otherdevices_lastupdate['Socket OTGW']) > 300 and
(otherdevices['Socket OTGW'] == 'Off')
)
then
-- Switch ON the socket and send some LOG information + PUSHOVER notification
commandArray['Socket OTGW'] = 'On'
print("OTGW Socket probably off!")
commandArray['SendNotification']='ALERT OTGW#OTGW Reageert niet, Switching On Socket#0'
print("OTGW: Switching on Socket!")
end
end
return commandArray
Re: Notification when sensor is not working
Posted: Sunday 24 April 2016 1:16
by Jordi
sincze, that's looks great. I'll try it.
I want it to detect if someone is using a frequency inhibitor (jamming) to avoid communication between domoticz with the door sensors, PIRs, etc.
if more than one fails could be for that reason.
Thanks
Re: Notification when sensor is not working
Posted: Sunday 24 April 2016 9:28
by jmleglise
Hi,
I am interessted in jamming detector too ! I hope you could share your progress here and solve this :
- I have no jamming detector to check if my counter-measure will work !
- a jammer have little range. So some device will work, and some not.
- differentiate between dead battery and jamming.
To help you, this is a code (for another purpose) that can inspire you.
Code: Select all
-- Checks if some sensors have been received recently, and
-- otherwise sends an e-mail to tell us to go check the lost one.
destEmail = '[email protected]' -- Where messages should be sent.
bodyMail=""
now = os.time()
local tableDeviceToCheck = { -- timeout for each device, in seconde.
MailBox=259200, -- 3 days 3*24*60*60,
["Motion Liv"]=86400, -- 1 days 1*24*60*60,
["Alert W"]=28800, -- 8 hours 8*60*60,
Lux=3600,
Temp1=50,
CPU=3600,
["WU Barometre"]=28800,
}
for deviceName, deviceTimeOut in pairs(tableDeviceToCheck) do
print(deviceName .." delay"..deviceTimeOut)
s = otherdevices_lastupdate[deviceName]
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)
lastAlive = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
-- If not seen since timeout, send an email
if (lastAlive + deviceTimeOut) < now then
bodyMail=bodyMail..deviceName.. " has not been seen since " .. s .. ".<br>\n"
end
end
if bodyMail~="" then
subject = 'Domoticz check : Device has been lost !'
commandArray['SendEmail'] = subject .. '#' .. bodyMail .. '#' .. destEmail
end
return commandArray
Re: Notification when sensor is not working
Posted: Tuesday 03 January 2017 20:36
by renerene
jmleglise wrote:To help you, this is a code (for another purpose) that can inspire you.
Thank you jmleglise. I have modified the code a bit, the result is below.
The trigger is 'time based', so it runs every minute. To prevent a mail bomb it only checks once a day, at 17:00 hrs.
It would be better if the table was expended with a third index ('Sensorstate OK / NOK) and that the table was stored in a user variable. That would give the possibility to direct (and only) send messages when the sensor changes it's status (connection lost / connection restored).
I don't know how to store and read the table values (yet), so To Be Continued
Code: Select all
-- Checks if some sensors have been received recently, and
-- otherwise sends a notification to tell us to go check the lost one.
-- https://www.domoticz.com/forum/viewtopic.php?f=15&t=9711&p=112074#p112074
index=1
now = os.time()
local tableDeviceToCheck = { -- timeout for each device, in seconde.
["badkamer thermo hygro sensor"]=3600, -- 1 uur
["Weerstation"]=14400, -- 4 uur
}
commandArray={}
date = os.date("*t")
if date.hour==17 and date.min==0 then
for deviceName, deviceTimeOut in pairs(tableDeviceToCheck) do
s = otherdevices_lastupdate[deviceName]
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)
lastAlive = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
tijd = now - lastAlive
print(deviceName .." "..tijd.. ' seconden geen reactie, grenswaarde ='..deviceTimeOut)
-- If not seen since timeout, send an email
if (lastAlive + deviceTimeOut) < now then
commandArray[index]={['SendNotification']='Melding#Device '..deviceName..' is niet gezien sinds '..s..' seconden. Batterij leeg?#0'}
index = index + 1
end
end
end
return commandArray
Re: Notification when sensor is not working
Posted: Thursday 09 February 2017 7:20
by Mikey
sincze wrote:I use the following code if a device is not responding anymore)
Code can be easily modified if you router is not responding to internet for example.
Code: Select all
---------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Debug = "YES" -- Turn debugging on ("YES") or off ("NO")
----------------------------------------------------------------------------------------------------------
-- Script functions
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- Command Array functions
----------------------------------------------------------------------------------------------------------
function datetimedifferencenow(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
----------------------------------------------------------------------------------------------------------
-- Command Tools & Examples
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
-- Declare & Fill variables
----------------------------------------------------------------------------------------------------------
commandArray = {}
-- First check several devices if they responded within 300 seconds (5 mminutes) & check that the 433 mhz switch is ON.
-- I don't switch based upon 1 OTGW device I use several to make sure it is not working.
if (datetimedifferencenow(otherdevices_lastupdate['Max. Vloerverwarming']) > 300 and
(datetimedifferencenow(otherdevices_lastupdate['OTGW - Outside Temperature'])) > 300 and
(datetimedifferencenow(otherdevices_lastupdate['Socket OTGW'])) > 300 and
(otherdevices['Socket OTGW'] == 'On')
) then
-- Switch OFF the socket and send some LOG information + PUSHOVER notification
commandArray['Socket OTGW'] = 'Off'
print("OTGW: OTGW Reageert niet Let OP!")
commandArray['SendNotification']='ALERT OTGW#OTGW Reageert niet, Switching Off Socket#0'
print("OTGW: Switching off Socket!")
else
-- Now check if lastupdate of socket has been updated within 5 minuts and if it is switched off
if (datetimedifferencenow(otherdevices_lastupdate['Socket OTGW']) > 300 and
(otherdevices['Socket OTGW'] == 'Off')
)
then
-- Switch ON the socket and send some LOG information + PUSHOVER notification
commandArray['Socket OTGW'] = 'On'
print("OTGW Socket probably off!")
commandArray['SendNotification']='ALERT OTGW#OTGW Reageert niet, Switching On Socket#0'
print("OTGW: Switching on Socket!")
end
end
return commandArray
I'm pretty new in domoticz, but this code looks great. But there is one thing I don't understand. Is the 'Socket OTGW' something like a Z-Wave USB Stick? Because I have such a Z-Wave stick, but I don't see this stick in the device list. How can you see this stick in the device list? I only see it in the Hardware list. thanks in advance
Re: Notification when sensor is not working
Posted: Thursday 09 February 2017 8:59
by Nautilus
Mikey wrote:
I'm pretty new in domoticz, but this code looks great. But there is one thing I don't understand. Is the 'Socket OTGW' something like a Z-Wave USB Stick? Because I have such a Z-Wave stick, but I don't see this stick in the device list. How can you see this stick in the device list? I only see it in the Hardware list. thanks in advance
Pretty sure it refers to Opentherm gateway (
http://otgw.tclcode.com/). Your usb Z-wave stick is a hardware component that allows compatible devices to be added to Domoticz. It is not seen as a device itself (like no other hardware components either). I don't think there is any good way of checking if there are some errors with the stick itself (I don't know how it would report those, could be that Domoticz log would pick up something so some sort of monitoring for log messages could work) but mainly I'd say you need to focus on checking the sensors and switches are seen during the expected intervals as done with the scripts in this thread. There is also the "Data timeout" setting for hardware which will enable the restart of the particular hardware if not data is received withing the configured interval. But I'm not sure if it works with z-wave sticks (not using it myself). Finally, maybe some additional inspiration from here:
viewtopic.php?t=6274
For general Domoticz monitoring I've found Monit to be reliable and working well:
https://www.domoticz.com/wiki/Monitoring_domoticz
Re: Notification when sensor is not working
Posted: Thursday 09 February 2017 12:30
by Mikey
Thanks Nautilus. I will check these links. There's only one more question. You wrote in your script: "433 mhz switch". What does that exactly mean?
Sorry for bothering you.
Re: Notification when sensor is not working
Posted: Thursday 09 February 2017 12:40
by Nautilus
Mikey wrote:Thanks Nautilus. I will check these links. There's only one more question. You wrote in your script: "433 mhz switch". What does that exactly mean?
Sorry for bothering you.
I guess this would be best left to answer by sinze as it is his script, but if you look at these lines:
Code: Select all
if (datetimedifferencenow(otherdevices_lastupdate['Max. Vloerverwarming']) > 300 and
(datetimedifferencenow(otherdevices_lastupdate['OTGW - Outside Temperature'])) > 300 and
(datetimedifferencenow(otherdevices_lastupdate['Socket OTGW'])) > 300 and
(otherdevices['Socket OTGW'] == 'On')
It looks like the first two (at least the "outside temperature") are sensors related to opentherm gateway and the third is maybe the opentherm unit itself that can be switched off completely. Therefore must check also that it is "On", otherwise it is expected there are no updates from the related sensors

Re: Notification when sensor is not working
Posted: Thursday 09 February 2017 12:43
by Mikey
That's OK, thanks a lot for your help
