Page 1 of 1

Turn of dummy switch if no motion after 30 min.

Posted: Friday 06 October 2017 13:43
by thorbj
Hi, how can i get this script to turn off HouseSw, only if any of the other switches is off, and have not been turned on again within 30 minutes?
Also the notification gets sendt immediately, I wan't it to wait until the HouseSw is off.

Code: Select all

return {
    active = true,
    on = {
        devices = {'Bevegelse Stue'},
		devices = {'Bevegelse Gang'},
		devices = {'Test'},
    },
    execute = function(domoticz, device)
        -- your script logic goes here, something like this:

		local HouseSw = domoticz.devices('Bevegelse i Huset')
		local LvgrmSw = domoticz.devices('Bevegelse Stue')
		local HallSw = domoticz.devices('Bevegelse Gang')
		local TestSw = domoticz.devices('Test')
		
		
        if (HouseSw.state == 'Off') and ((TestSw.state == 'On') or (LvgrmSw.state == 'On') or (HallSw.state == 'On')) then
            HouseSw.switchOn()
            domoticz.notify('Bevegelse', 'Noen beveger seg i huset.', domoticz.PRIORITY_LOW)
            domoticz.log('Noen beveger seg i huset.')
			elseif (HouseSw.state == 'On') and (TestSw.state == 'Off') and (LvgrmSw.state == 'Off') and (HallSw.state == 'Off') then
			HouseSw.switchOff().afterMin(30)
			domoticz.notify('Ingen bevegelse', 'Ingen bevegelse i huset.', domoticz.PRIORITY_LOW)
			domoticz.log('Ingen bevegelse i huset.')
        end
    end
}
Thanks :)

Re: Turn of dummy switch if no motion after 30 min.

Posted: Friday 06 October 2017 15:09
by emme
by my understanding you cannot use a device trigger since your requirement is that... none touch them :P
so I convert the script to a time (every minute) event

check if this can work for you

Code: Select all

return {
    active = true,
    on = { timer = {'every minute'}, },
    execute = function(domoticz)
        -- your script logic goes here, something like this:

		local HouseSw = domoticz.devices('Bevegelse i Huset')
		local LvgrmSw = domoticz.devices('Bevegelse Stue')
		local HallSw = domoticz.devices('Bevegelse Gang')
		local TestSw = domoticz.devices('Test')
		local timeMinPass = 30    -- Minutes to trigger 
		local timePassed = false   -- this is a flag to ensure time of 30 mins has passed
		
		if (LvgrmSw.lastUpdate.minutesAgo >= timeMinPass and HallSw.lastUpdate.minutesAgo >= timeMinPass and TestSw.lastUpdate.minutesAgo >= timeMinPass) and (LvgrmSw.state == 'Off' and HallSw.state == 'Off' and TestSw.state == 'Off') and HouseSw.state == 'On' then
			HouseSw.switchOff()
			domoticz.notify('Ingen bevegelse', 'Ingen bevegelse i huset.', domoticz.PRIORITY_LOW)
			domoticz.log('Ingen bevegelse i huset.')
		end
		
    end
}

Re: Turn of dummy switch if no motion after 30 min.

Posted: Friday 06 October 2017 23:01
by thorbj
Thank you! That solved the problem :)