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

Last seen notification

Post by gmccarthy » Friday 30 October 2015 18:11

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: 150
Joined: Friday 21 August 2015 19:27
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Stockholm / Sweden
Contact:

Re: Last seen notification

Post by Minglarn » Friday 30 October 2015 23:41

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: 2715
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Last seen notification

Post by Egregius » Saturday 31 October 2015 8:43

Isn't that what's "Sensor Timeout" is for in the settings/other page?

stlaha2007
Posts: 437
Joined: Monday 05 October 2015 10:16
Target OS: -
Domoticz version:
Contact:

Re: Last seen notification

Post by stlaha2007 » Saturday 31 October 2015 11:57

@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: 21
Joined: Sunday 06 September 2015 22:28
Target OS: Raspberry Pi
Domoticz version: beta
Location: United Kingdom
Contact:

Re: Last seen notification

Post by gmccarthy » Saturday 31 October 2015 12:16

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

Re: Last seen notification

Post by stlaha2007 » Saturday 31 October 2015 17:50

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: 73
Joined: Monday 07 October 2013 10:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Last seen notification

Post by hansrune » Sunday 01 November 2015 20:45

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.
SensMonTypical.png
Typical Variables
SensMonTypical.png (32.61 KiB) Viewed 4634 times
A more typical user variable setup can look like this. In this case it displays a state where one sensor has timed out
SensMonStart.png
Minimal variables
SensMonStart.png (47.98 KiB) Viewed 4634 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 23:15
Target OS: Raspberry Pi
Domoticz version: V2.3295
Location: UK
Contact:

Re: Last seen notification

Post by smdoyle » Tuesday 10 November 2015 23:53

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: 73
Joined: Monday 07 October 2013 10:51
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Last seen notification

Post by hansrune » Wednesday 11 November 2015 10:20

Good to hear that. Maybe i should make it wiki material...

Flopp
Posts: 354
Joined: Sunday 03 January 2016 15:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Last seen notification

Post by Flopp » Monday 04 July 2016 9:21

Nice work

Flopp
Posts: 354
Joined: Sunday 03 January 2016 15:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Last seen notification

Post by Flopp » Monday 04 July 2016 10:11

Since Domoticz doesn't accept empty Value for Strings you have to write None as Value

Flopp
Posts: 354
Joined: Sunday 03 January 2016 15:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Last seen notification

Post by Flopp » Monday 04 July 2016 10:14

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: 1473
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Last seen notification

Post by dannybloe » 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Flopp
Posts: 354
Joined: Sunday 03 January 2016 15:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Last seen notification

Post by Flopp » Tuesday 05 July 2016 8:11

That looks interesting and you can do a lot more with dzvents

EDsteve
Posts: 34
Joined: Thursday 13 October 2016 11:43
Target OS: Linux
Domoticz version:
Contact:

Re: Last seen notification

Post by EDsteve » Saturday 23 June 2018 11:54

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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests