Last seen notification Topic is solved

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
gmccarthy
Posts: 14
Joined: Sunday 06 September 2015 22:28
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: United Kingdom
Contact:

Last seen notification

Post 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.
User avatar
Minglarn
Posts: 214
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Re: Last seen notification

Post by Minglarn »

This is something i've been searching for!

+1 for this!
When you eliminate the impossible, whatever remains, however improbable, must be the truth.” -Spock in Star Trek VI
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Last seen notification

Post by Egregius »

Isn't that what's "Sensor Timeout" is for in the settings/other page?
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: Last seen notification

Post 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
gmccarthy
Posts: 14
Joined: Sunday 06 September 2015 22:28
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: United Kingdom
Contact:

Re: Last seen notification

Post 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
stlaha2007
Posts: 370
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: Last seen notification

Post 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
hansrune
Posts: 49
Joined: Monday 07 October 2013 10:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Last seen notification

Post 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
Typical Variables
SensMonTypical.png (32.61 KiB) Viewed 8200 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
Minimal variables
SensMonStart.png (47.98 KiB) Viewed 8200 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
smdoyle
Posts: 1
Joined: Tuesday 10 November 2015 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.3295
Location: UK
Contact:

Re: Last seen notification

Post 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!
hansrune
Posts: 49
Joined: Monday 07 October 2013 10:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Last seen notification

Post by hansrune »

Good to hear that. Maybe i should make it wiki material...
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Last seen notification

Post by Flopp »

Nice work
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Last seen notification

Post by Flopp »

Since Domoticz doesn't accept empty Value for Strings you have to write None as Value
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Last seen notification

Post 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.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Last seen notification

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Last seen notification

Post by Flopp »

That looks interesting and you can do a lot more with dzvents
EDsteve
Posts: 26
Joined: Thursday 13 October 2016 11:43
Target OS: Linux
Domoticz version:
Contact:

Re: Last seen notification

Post 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
HM31
Posts: 56
Joined: Friday 04 August 2017 16:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Last seen notification

Post 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.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Last seen notification

Post 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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
kniazio
Posts: 198
Joined: Thursday 06 October 2016 8:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7243
Contact:

Re: Last seen notification

Post 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
}
HM31
Posts: 56
Joined: Friday 04 August 2017 16:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Last seen notification

Post 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 ...
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Last seen notification

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest