Turn of dummy switch if no motion after 30 min.

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

Turn of dummy switch if no motion after 30 min.

Post 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 :)
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

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

Post 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
}
The most dangerous phrase in any language is:
"We always done this way"
thorbj
Posts: 113
Joined: Thursday 20 November 2014 22:11
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Norway
Contact:

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

Post by thorbj »

Thank you! That solved the problem :)
2xRaspberry Pi Model 2 w/RaZberry z-wave chip (master/slave)|Fibaro Wall Plug|Fibaro Universal Dimmer 500W|Aeon Labs Multisensor|RFXtrx433E|Nexa WMR-1000|Nexa Pe-3|Nexa Remote|Nexa LGDR3500|Lightify Gateway|Lightify RGBW bulb
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest