Page 1 of 1

No presence detection

Posted: Sunday 11 October 2020 19:18
by HvdW
I had a chat with my sister who lives alone about what would happen if something severe like an infarct would happen.
Her children call her, I call her but it doesn't happen every day.
We talked about presence detection, about presence detection and privacy.
No camera, just motion detection.

We concluded that the best possible surveillance would be a presence detection in the bedroom acting between 00:00 and 06:00 which only sends a notification if no presence is detected.
The same applies to the living room let's say between 08:00 and 22:00

Of course Domoticz comes to my mind.
I've been thinking about using something like system alive check

The setup would be RPI with a motion detection sensor which sends a notification when no motion is detected.

I have this system alive checker setup for the heating and Luftdaten as an example.
When one of the systems don't respond it sends out one notification which should be sufficient.

Code: Select all

--System-alive-check

-- this script can be used in conjunction with the System-alive checker plug-in.
-- the plugin pings a list of devices and creates switches for these devices
-- the reason for this script is to not treat devices as dead immediately after they
-- do not respond. More often than not, the second ping atempt does work. So only
-- if the device has been not responding for a while AFTER it is been presumed dead
-- then this script will notify you
-- put the names of these switches in the devicesToCheck list
-- you may have to tweak the THRESHOLD depending on the check interval

local THRESHOLD = 11 -- minutes
local devicesToCheck = 
        {
            'CV-ping', 
            'Luftdaten',
        }

return 
{
    on = 
    {
        devices = devicesToCheck,

        timer = 
        { 
            'every 10 minutes',
        },
    },

    data = 
    {
        notified = { initial = {} },
    },

    logging = 
    {
        level = domoticz.LOG_ERROR, -- change from LOG_DEBUG to LOG_ERROR when script executes without problems
        marker = 'notify',
    },

    execute = function(dz, item)
        if item.isTimer then
            
            for index, deviceName in ipairs(devicesToCheck) do
                local device = dz.devices(deviceName) 
                --dz.notify('notifyer achter de eerste if.',dz.PRIORITY_HIGH)
                dz.log('device name  ' .. device.name, dz.LOG_DEBUG) 
                dz.log('device state ' .. device.state, dz.LOG_DEBUG)        
                dz.log('device lastUpdate ' .. device.lastUpdate.minutesAgo, dz.LOG_DEBUG)        
                dz.log('device notified ' .. tostring(dz.data.notified[deviceName]), dz.LOG_DEBUG)        
                                
                if device.state == 'Off' and device.lastUpdate.minutesAgo >= THRESHOLD and dz.data.notified[deviceName] ~= true  then
                    --dz.notify('notifyer achter de tweede if.',dz.PRIORITY_HIGH)
                    dz.log('Idle device ' .. deviceName, dz.LOG_DEBUG)        
                    dz.notify('notifyer', deviceName .. ' is not responding anymore.',dz.PRIORITY_HIGH)
                    dz.data.notified[deviceName] = true
                end
            end
        else
            dz.data.notified[item.name] = false
        end
    end
}
The code is interesting because of this one notification triggered and not spamming with a notification every minute or so.

Re: No presence detection

Posted: Sunday 11 October 2020 21:45
by AllesVanZelf
I'm not an DzVents expert. But I love your Idea as Domotica solution!!
I would think a setup like: If Motion1 == "Off" for X seconds and Motion2 == "Off" for xx seconds , etc, would work. But not sure how to set this up.

Maybe you could start with a virtual switch what is switched on when motion on one of the motion sensors is detected.

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Motion living room',
            'Motion bedroom',
        },
        
    },

    logging =
    {
        level = domoticz.LOG_ERROR,
    },
    
    execute = function(dz)
        local motion1 = dz.devices('Motion Living room').state
        local motion2 = dz.devices('Motion Bedroom').state
        local motion-overall = dz.devices('Motion-detected')


        dz.log('State of Motion Living room '  .. tostring(motion1), dz.LOG_DEBUG)
        dz.log('State of Motion bedroom '  .. tostring(motion2), dz.LOG_DEBUG)
        dz.log('State of Motion-detected '  .. tostring(motion-overall), dz.LOG_DEBUG)

        if motion1 == 'On' or motion2 == 'On' then
            motion-overall.switchOn()

        elseif motion1 == 'Off' and motion2 == 'Off' then
            motion-overall.switchOff()
        end
    end
}
But you still need a kind of countdown. Maybe with a counter? Counting down with a check every x minutes? I'm looking forward to other suggestions.

Re: No presence detection

Posted: Sunday 11 October 2020 22:56
by HvdW
Well, I was thinking about the having the pir sensor switch on a dummy device <pir bedroom>.
The script checks <pir bedroom> for the state = on
<pir bedroom> has to be switched off at time 00:00
Every time the pir sensor gets activated it switches <pir bedroom>to state 'on'.
It's not important how many times <pir bedroom> is switched on.
At the end of the session the dzvents script checks the state of <pir bedroom>.
At the end of the surveillance session, at 06:00 dzvents checks <pir bedroom>

Code: Select all

if <pir bedroom> == on then
   <pir bedroom> = off
else
   dz.notify('notifyer', deviceName .. ' has not noticed any movement.',dz.PRIORITY_HIGH)
endif
In the example I presented the script has to test 2 dummy devices, each once a day.

Re: No presence detection

Posted: Monday 12 October 2020 14:09
by erem
I build a similar system using the rcwl-0516 sensor on a wemos D1 mini.
i have a custom arduino sketch for that, but it works as well with ESPEasy.

the problem is that you need to move quite a bit in bed for the sensor to register movement. So you get a lot of false positives.
i still have no solution for that. If you set the timeout too high, help will come to late. too shor will generate many false alarms.

an active solution (help/alarm button) seems preferable at this point.

just my €.02

Re: No presence detection

Posted: Monday 12 October 2020 20:08
by HvdW
Thank you,
I was thinking about ESP8266 as well.
In this case surveillance isn't very high on the priority list.
Just knowing that there has been any motion in the time span.

Can you publish the script for the ESP8266?

I was thinking about creating a WiFi connection and attach it to the home network.
It triggers the dummy device on on movement and after the time span dzvents checks and can send a notification.
Maybe this all can be done on the ESP8266 in one sequence.
Who knows.