Page 1 of 1

Turning on Alarm autoomatically - help needed

Posted: Sunday 19 May 2019 21:28
by FrancescoS
Hi all,

I am looking for a simple way using dzvents to turn on my alarm system when no presence is detected.
I have found in the forum few examples but they are based on blocky.

Basically I have a couple of motion sensors, + systemalivechecker script to detect if mobile phones are connected to the router, or the TV is switched on.
I would like to switch the alarm on when after i.e. 20 minutes of pinger off and motion sensors no activity.

Can somebody help on this ?

Thanks in advance

Francesco

Re: Turning on Alarm autoomatically - help needed

Posted: Sunday 19 May 2019 22:12
by waaren
FrancescoS wrote: Sunday 19 May 2019 21:28 I am looking for a simple way using dzvents to turn on my alarm system when no presence is detected.

Basically I have a couple of motion sensors, + systemalivechecker script to detect if mobile phones are connected to the router, or the TV is switched on.
I would like to switch the alarm on when after i.e. 20 minutes of pinger off and motion sensors no activity.
What does the systemalivechecker steer ? Does it set a uservariable or a virtual switch /sensor ?
And what is domoticz version are you on ?

Re: Turning on Alarm autoomatically - help needed

Posted: Sunday 19 May 2019 23:28
by FrancescoS
Systemlivechecker switch on and off a virtual switch.
I am on dzvents 2.4.0

Re: Turning on Alarm autoomatically - help needed

Posted: Tuesday 21 May 2019 0:21
by hestia
Hi
I have a similar use case to put my heater on low when there is nobody at home and reverse.
And I have very poor info if somebody is home, so I need a lag before triggering the heater.

I have one script to set a evaluate if somebody with 4 values: nobody / perhaps nobody (during your 20 min) / somebody / somebody just arrived
Those 4 values allow to trigger other scripts

Code: Select all

--[[
a dz dzVents Script to evaluate if anybody is at home to trigger something (heater for instance...)
--]]

local DOMAIN = 'YaQuelquUn' -- For logging, as you like!

local SBDY_MANUAL = 425 -- Dummy device to force the presence
local SBDY_RESULT= 451 -- Dummy device to store the result
local SBDY_SENSORS = {395, 385, 369} -- All the SENSORS to detect people
local DEVICES = {395, 385, 369, 203} -- All the devices to trigger the script

local l_maxAuto = 3600*2 --  seconds ; time keep on light on when switch on by SENSORS
local l_maxManual = 3600*4 -- seconds ; time keep on light on when switch on by switch / bigger than l_max_SENSORS

local TIME_INTERVAL = 'every 10 minutes' -- Period to check if nobody, l_maxAuto and l_maxManual to take into accoutn

return {
    active = true,
    logging = {
	level = domoticz.LOG_ERROR, -- Select one of LOG_DEBUG, LOG_INFO, LOG_ERROR, LOG_FORCE to override system log level
	marker = DOMAIN
	},
    on = {
        devices = DEVICES,
        timer = {TIME_INTERVAL},
  	},
        
    execute = function(dz, the_device, triggerInfo)
        
    local LOG_LEVEL = dz.LOG_INFO -- LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_FORCE
        
    dz.log('*** start ' .. triggerInfo.type , dz.LOG_FORCE)
        
        
    local l_sensorsOn = false
    local l_maxOn = l_maxAuto + l_maxManual -- to be sure it is >
    
    for i, f_sensors in pairs(SBDY_SENSORS) do
    
        if dz.devices(f_sensors).active then 
            l_sensorsOn = true 
            -- print('active: ' .. dz.devices(f_sensors).name)
        else
            -- print ('lastupdate.secondsAgo: ' .. dz.devices(f_sensors).lastUpdate.secondsAgo)
            if l_maxOn > dz.devices(f_sensors).lastUpdate.secondsAgo then
                l_maxOn = dz.devices(f_sensors).lastUpdate.secondsAgo
                -- print (' < ' .. dz.devices(f_sensors).name)
            end
            
        end
    end
    local l_sbdy = 0
    if  l_sensorsOn  == true then
        dz.log('Somebody there!', LOG_LEVEL)
        l_sbdy = 20
    else
        if l_maxOn < l_maxAuto then
            dz.log('Somebody there?', LOG_LEVEL)
            l_sbdy = 10
        else
            dz.log('Nobody', LOG_LEVEL)
        end
    end
    if l_sbdy == 20 then -- Somebody there!
        if dz.devices(SBDY_RESULT).level == 0 then  -- nobody to somebodymbody
            dz.devices(SBDY_RESULT).switchSelector(30)
            dz.log('Nobody to somebody there', LOG_LEVEL)
        else -- somebody is confirmed
            dz.devices(SBDY_RESULT).switchSelector(20) -- other cases to smbody
            dz.log('Somebody still there now', LOG_LEVEL)
        end
    elseif l_sbdy == 10 then -- Somebody there perhaps!
        if dz.devices(SBDY_RESULT).level ~= 10 then
            dz.devices(SBDY_RESULT).switchSelector(10)
            dz.log('Somebody there perhaps!', LOG_LEVEL)
        end
    elseif l_sbdy == 0 then -- Nobody
        if dz.devices(SBDY_RESULT).level ~= 0 then
            dz.devices(SBDY_RESULT).switchSelector(0)
            dz.log('Nobody now', LOG_LEVEL)
        end
    end
end}
Note: I started something about a manual mode, but didn't go the end

and another script to pilot my heater

Code: Select all

-- Pilotage Chaudière

local SBDY_RESULT = 451 -- dummy which knows if anyone at home
local PILOT = 427 -- dummy which knows the boiler mode
local TRIGGER = {451, 427, 346} -- {SBDY_RESULT, PILOT, MODE}
local DEVICE = 347 -- device to pilot -- "Saving" Chaudière ECO
local MODE = 346 -- Off 0 ECS 10 Prog. 20 Vac. 30 On 40
local DOMAIN = 'ChaudièreP' -- For logging, as you like!

local TIME_INTERVAL = 'every 1 hours'

return {
    active = true,
    logging = {
	level = domoticz.LOG_ERROR, -- Select one of LOG_DEBUG, LOG_INFO, LOG_ERROR, LOG_FORCE to override system log level
	marker = DOMAIN
	},
	on = {
        devices = TRIGGER,
        timer = { TIME_INTERVAL },
        },

	execute = function(dz, the_device, triggerInfo)
	local LOG_LEVEL = dz.LOG_FORCE -- LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_FORCE
	local l_status = 'xx' -- status   
    dz.log('*** start ' .. triggerInfo.type , dz.LOG_LEVEL)
    
    if dz.devices(SBDY_RESULT).level ~= 0 then -- somebody at home
        dz.log('Somebody at home' , dz.LOG_LEVEL)
        if dz.devices(PILOT).level == 10 and dz.devices(PILOT).level == 20 then -- Normal / Prog.
           dz.devices(DEVICE).switchOff().checkFirst() -- suppression du mode saving
           l_status = 'Off'
           dz.log('ECO to Off' , dz.LOG_LEVEL)
        end
	else -- nobody at home
	    dz.log('Nobody at home' , dz.LOG_LEVEL)
	    if dz.devices(PILOT).level == 10 and dz.devices(PILOT).level == 20 then -- Normal / Prog.
            dz.devices(DEVICE).switchOn().checkFirst() -- mode saving
            l_status = 'On'
            dz.log('ECO to On' , dz.LOG_LEVEL)
        end
    end
	        
   	dz.log(dz.devices(DEVICE).name .. ' ' .. dz.devices(DEVICE).state .. ' to ' .. l_status, dz.LOG_FORCE)

end
}
Maybe you could use those scripts for your use case

Re: Turning on Alarm autoomatically - help needed

Posted: Tuesday 21 May 2019 2:10
by waaren
FrancescoS wrote: Sunday 19 May 2019 23:28 Systemlivechecker switch on and off a virtual switch.
I am on dzvents 2.4.0
Could be something like

Code: Select all

local scriptVar = 'setAlarm'
return 
{

    on = 
    {
        timer = {'every 20 minutes'}
    },

   logging = 
   { 
        level = domoticz.LOG_DEBUG,  -- set to LOG_ERROR when script runs OK
        marker = scriptVar 
   },

	execute = function(dz, item) 
        
        securityPanelDevice = dz.devices('Domoticz Security Panel') -- change name to reflect your system setup
        systemLive = dz.devices('systemLive').active    -- change name to your systemLivechecker device
        securityIdleMinutes = 20 
        
        motionSensors = 
        { 
            'XMotion-2',  
            'XButton-1',
            'Trap bewegingsmelder'
        }
        
        local function noMotion()
            for _, name in ipairs(motionSensors) do
                if dz.devices(name).lastUpdate.minutesAgo < securityIdleMinutes then
                    dz.log("Alarm will not be set because device " .. name .. " detected motion ", dz.LOG_DEBUG)
                    return false
                end
            end
            return true
        end
        
        if ( securityPanelDevice.state ==  dz.SECURITY_DISARMED ) and ( not systemLive ) and noMotion() then
            securityPanelDevice.armAway()
            dz.log("Security State set to armAway",  dz.LOG_DEBUG)
        else
            dz.log("No action needed. Security State: " ..securityPanelDevice.state .. "; systemLive switch active: " ..  tostring(systemLive),  dz.LOG_DEBUG)
        end
    end
}

Re: Turning on Alarm autoomatically - help needed

Posted: Thursday 23 May 2019 7:34
by FrancescoS
Hi,

thank you ! both work like a charm.
Now I have to improve the presence detection algorithm as systemlivechecker is not very reliable.
But this but works pretty fine.

Thanks and regards

Re: Turning on Alarm autoomatically - help needed

Posted: Friday 24 May 2019 17:27
by Gravityz
if you have a asus router there might be an easier way to do presence detection
i have a routine running on my router which checks connected mac id's. if none of them are connected i flip a domoticz virtual switch by using a curl command.
so basically if al my devices are off, my girlfriends devices are off and my tv is off i am not at home

Re: Turning on Alarm autoomatically - help needed

Posted: Monday 27 May 2019 13:51
by FrancescoS
Hi thanks,

I am now using this one >
https://easydomoticz.com/forum/viewtopic.php?t=7176

and it works perfectly with both iphone and android

Thx

Re: Turning on Alarm autoomatically - help needed

Posted: Monday 03 June 2019 16:55
by snellejellep
i have this:

Code: Select all

return {
	on = {
		devices = {
			'is someone home',
			'nachtmodus'
		}
	},
	execute = function(dz, device)
		
		local home          = dz.devices("is someone home")
		local nacht         = dz.devices("nachtmodus")
		local security      = dz.devices("Domoticz Security Panel")
		
		if home == "Off" then
		    security.armAway()
		elseif home == "On" and nacht == "Off" then
		    security.disarm()
		elseif home == "On" and nacht == "On" then
		    security.armHome().afterMin(10)
		end
		
	end
}
but it does not change the security panel state for me. if i check with the scripts above it matches and should work?
anybody an idea on what i am doing wrong?

Re: Turning on Alarm autoomatically - help needed

Posted: Monday 03 June 2019 17:09
by waaren
snellejellep wrote: Monday 03 June 2019 16:55 ... it does not change the security panel state for me. if i check with the scripts above it matches and should work?
anybody an idea on what i am doing wrong?
Did you check the log ?

You declared home and nacht both as devices (which are tables for Lua) What you need are states (one entry in the device table)
Declare them using

Code: Select all

local home          = dz.devices("is someone home").state
local nacht         = dz.devices("nachtmodus").state

Re: Turning on Alarm autoomatically - help needed

Posted: Monday 03 June 2019 17:38
by snellejellep
waaren wrote: Monday 03 June 2019 17:09
snellejellep wrote: Monday 03 June 2019 16:55 ... it does not change the security panel state for me. if i check with the scripts above it matches and should work?
anybody an idea on what i am doing wrong?

Code: Select all

local home          = dz.devices("is someone home").state
local nacht         = dz.devices("nachtmodus").state
that was the fix, many thanks!!