Page 1 of 1
Last seen notification
Posted: Friday 30 October 2015 17:11
by gmccarthy
Not sure if the following is currently possible - if not it would be a nice feature.
Notification when last sensor time is greater than xxx.
If one of my sensors stops reporting for more than x mins I'd like to know about it as it's probably died then and needs a reboot.
Re: Last seen notification
Posted: Friday 30 October 2015 22:41
by Minglarn
This is something i've been searching for!
+1 for this!
Re: Last seen notification
Posted: Saturday 31 October 2015 7:43
by Egregius
Isn't that what's "Sensor Timeout" is for in the settings/other page?
Re: Last seen notification
Posted: Saturday 31 October 2015 10:57
by stlaha2007
@gmccarthy:
Which need to reboot, your sensor/gateway or domotics?
Else domotics has a hardware time out which can be configured to restart/reboot that hardware/gateway.
Look at the settings of your hardware device. If you mean a specific sensor, it depends i would think. Then your suggestion would be a nice one to know which sensor needs to a (manual) reboot.
Sent from my D6503 using Tapatalk
Re: Last seen notification
Posted: Saturday 31 October 2015 11:16
by gmccarthy
Its not to reboot anything - its more of a info notification that I need to investigate a sensor that has not reported in for a while.
Found this:
viewtopic.php?f=31&t=5498
There is already logic inside domoticz, but the function is not completed.
function CheckDeviceTimeout
I will put it on the todo list
Re: Last seen notification
Posted: Saturday 31 October 2015 16:50
by stlaha2007
Youre right. Seen that topic long time ago. Never thought of being the prob yoi wanted to know.
Guess we have to wait for Gizmocus to finish its ToDo
Sent from my D6503 using Tapatalk
Re: Last seen notification
Posted: Sunday 01 November 2015 19:45
by hansrune
Maybe I can help .... I created the following LUA script to monitor ESIC/WT450 and other unreliable sensors. This sends me notification when selected sensors drops out, and another one if it starts responding again. You can also exclude sensors from being monitored for timeouts.
The script makes use of Domoticz user variables for configuration as follows:
- SensorTimeOut (integer) is useful to change for debugging, or undefined for defaults
- SensorsAlerted (string) - blank / undefined for no alerts. NB: Set to "None" as initial value for alerts
- SensorMonitorDevices (string) - comma separated list of substrings to match for device names
- SensorMonitorExcluded (string) - comma separated list of substrings out of the matched devices to exclude
The substring matches are intentional, and the purpose is to make it easy to include / exclude device names containing functional names such as Temp and (R)egulator.
A minimal setup of user variables can be as follows, but only
SensorsAlerted is strictly needed.
- Typical Variables
- SensMonTypical.png (32.61 KiB) Viewed 8198 times
A more typical user variable setup can look like this. In this case it displays a state where one sensor has timed out
- Minimal variables
- SensMonStart.png (47.98 KiB) Viewed 8198 times
Please note the needed inital word None. Just my laziness / makes the code simpler, but is required for this to work.
If you prefer, you can just use the fallback variables in the script instead of user variables. I find user variables handy as i use the same LUA script in two different houses.
The following script_time_sensormonitor.lua can also be downloaded from
here
Code: Select all
--
-- $Id: script_time_sensormonitor.lua,v 1.2 2015/09/09 18:59:49 pi Exp $
--
logging = true
debug = false
--
-- User variables from Domoticz setup
-- SensorTimeOut (integer) is useful to change for debugging, or undefined for defaults
-- SensorsAlerted (string) - blank / undefined for no alerts, set to "None" as initial value for alterts
-- SensorMonitorDevices (string) - comma separated list of substrings to match for device names
-- SensorMonitorExcluded (string) - comma separated list of substrings out of the matched devices to exclude
--
monitordevices=uservariables["SensorMonitorDevices"];
excludeddevices=uservariables["SensorMonitorExcluded"];
sensorsalerted=uservariables["SensorsAlerted"];
devicetimeout=uservariables["SensorTimeOut"];
--
-- Fallback values
--
if not ( monitordevices ) then
monitordevices = "Temp,CPU"
end
if not ( excludeddevices ) then
excludeddevices = "egulator"
end
if not ( devicetimeout ) then
devicetimeout = 600
end
--
-- No changes should be needed below here
--
function changedsince(device)
t1 = os.time()
ts = otherdevices_lastupdate[device]
year = string.sub(ts, 1, 4)
month = string.sub(ts, 6, 7)
day = string.sub(ts, 9, 10)
hour = string.sub(ts, 12, 13)
minutes = string.sub(ts, 15, 16)
seconds = string.sub(ts, 18, 19)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difftime=(os.difftime(t1,t2))
-- if (debug) then print("Device " .. device .. " not changed in " .. difftime .. " seconds") end
return difftime
end
commandArray = {}
for device, value in pairs(otherdevices_svalues)
do
pos = nil
exclpos = nil
for matchname in string.gmatch(monitordevices, "[^,]+")
do
pos = string.find(device,matchname,1,true)
if ( pos ) then
for exname in string.gmatch(excludeddevices, "[^,]+")
do
exclpos = string.find(device,exname,1,true)
if ( exclpos ) then
if (debug) then print("Excluded device " .. device .. " matching " .. exname) end
break
end
end
if ( exclpos ) then break end
if (debug) then print("Included device " .. device .. " matching " .. matchname .. " value=" .. value) end
deltatime = changedsince(device)
if ( deltatime > devicetimeout ) then
if (logging) then print("Timeout for " .. device .. ". Not seen for " .. deltatime .. " seconds" ) end
if ( sensorsalerted ) then
pos = string.find(sensorsalerted,"," .. device,1,true)
if not ( pos ) then
sensorsalerted = sensorsalerted .. "," .. device
if (logging) then print("sensorsalterted addition: " .. device .. " added to " .. sensorsalerted) end
commandArray['Variable:SensorsAlerted']=sensorsalerted
commandArray['SendNotification']="Sensor " .. device .. " inactive"
end
end
else
if ( sensorsalerted ) then
pos = string.find(sensorsalerted,"," .. device,1,true)
if ( pos ) then
len = string.len(device) + 1
sensorsalerted = string.sub(sensorsalerted, 1, pos - 1) .. string.sub(sensorsalerted, pos + len)
if (logging) then print("sensorsalterted removal: " .. device .. " removed from " .. sensorsalerted) end
commandArray['Variable:SensorsAlerted']=sensorsalerted
commandArray['SendNotification']="Sensor " .. device .. " active again"
end
end
end
else
if (debug) then print("No match device " .. device .. " no match for " .. matchname) end
end
end
end
return commandArray
Re: Last seen notification
Posted: Tuesday 10 November 2015 22:53
by smdoyle
Hi hansrune, that is really helpful and very well described. Thanks to the clear instructions and URL I was able to get it working in a matter of minutes. Looks a well designed piece of code too!
Many thanks!
Re: Last seen notification
Posted: Wednesday 11 November 2015 9:20
by hansrune
Good to hear that. Maybe i should make it wiki material...
Re: Last seen notification
Posted: Monday 04 July 2016 9:21
by Flopp
Nice work
Re: Last seen notification
Posted: Monday 04 July 2016 10:11
by Flopp
Since Domoticz doesn't accept empty Value for Strings you have to write None as Value
Re: Last seen notification
Posted: Monday 04 July 2016 10:14
by Flopp
Is there a way to make a short delay, I had 3 sensors that was too old but I only got one email.
Can the RPi be too quick or maybe the mail server took time to send the first mail so the other two emails never reached the mail server?
My SensorAlerted includes all 3 sensor that is old.
Re: Last seen notification
Posted: Monday 04 July 2016 10:16
by dannybloe
gmccarthy wrote:Not sure if the following is currently possible - if not it would be a nice feature.
Notification when last sensor time is greater than xxx.
If one of my sensors stops reporting for more than x mins I'd like to know about it as it's probably died then and needs a reboot.
Have you looked at
dzVents? It allows you to do this in just a
couple of lines of code.
Re: Last seen notification
Posted: Tuesday 05 July 2016 8:11
by Flopp
That looks interesting and you can do a lot more with dzvents
Re: Last seen notification
Posted: Saturday 23 June 2018 11:54
by EDsteve
Just in case someone is coming across this thread like me.
The solution is already there:
- click on the "Notification" button from the sensor you want to monitor
- change the "type" in the pull down menu to "last Update"
- and configure the rest of the settings
Re: Last seen notification
Posted: Tuesday 12 April 2022 19:47
by HM31
Just in case the same someone wanted to use the above trick. Type "Last Update" is unfortunately not available for all type of devices.
Re: Last seen notification
Posted: Wednesday 13 April 2022 1:04
by waltervl
HM31 wrote: ↑Tuesday 12 April 2022 19:47
Just in case the same someone wanted to use the above trick. Type "Last Update" is unfortunately not available for all type of devices.
On what device type did you miss it?
Re: Last seen notification
Posted: Wednesday 13 April 2022 6:46
by kniazio
dannybloe wrote: ↑Monday 04 July 2016 10:16
gmccarthy wrote:Not sure if the following is currently possible - if not it would be a nice feature.
Notification when last sensor time is greater than xxx.
If one of my sensors stops reporting for more than x mins I'd like to know about it as it's probably died then and needs a reboot.
Have you looked at
dzVents? It allows you to do this in just a
couple of lines of code.
I have such an error:
Code: Select all
2022-04-13 06:45:00.117 Error: EventSystem: in /home/pi/domoticz/dzVents/runtime/dzVents.lua: /home/pi/domoticz/dzVents/runtime/EventHelpers.lua:464: bad argument #1 to 'pairs' (table expected, got string)
Here is my script:
Code: Select all
local devicesToCheck = {
{ ['name'] = 'Wewnętrzna', ['threshold'] = 30 }
}
return {
active = true,
on = {
['timer'] = 'every 5 minutes'
},
execute = function(domoticz)
local message=""
for i, deviceToCheck in pairs(devicesToCheck) do
local name = deviceToCheck['name']
local threshold = deviceToCheck['threshold']
local minutes = domoticz.devices[name].lastUpdate.minutesAgo
if ( minutes > threshold) then
message = message .. 'Device ' ..
name .. ' seems to be dead. No heartbeat for at least ' ..
minutes .. ' minutes.\r'
end
end
if (message) then
domoticz.email('Dead devices', message, '[email protected]')
domoticz.log('Dead devices found: ' .. message, domoticz.LOG_ERROR)
end
end
}
Re: Last seen notification
Posted: Wednesday 13 April 2022 15:44
by HM31
waltervl wrote: ↑Wednesday 13 April 2022 1:04
HM31 wrote: ↑Tuesday 12 April 2022 19:47
Just in case the same someone wanted to use the above trick. Type "Last Update" is unfortunately not available for all type of devices.
On what device type did you miss it?
Dummy devices, on/off switches, open/close sensor, motion sensor, etc ...
Re: Last seen notification
Posted: Wednesday 13 April 2022 16:06
by waltervl
Yes I see now, on all switches this last update notification is not possible. Available though on most other sensors (not switches) like temperature, UV, Weather, thermostats, pressure, custom sensor, Lux etc.