Page 1 of 1

Switch off afer 1 minute fails, where is problem in this script

Posted: Monday 28 October 2019 0:10
by HvdW
Hi,
I have this switch which I want to go to state OFF 1 minute after it is switched ON
I have been searching this forum and wasn't able to find the answer.
Help in correcting the script is appreciated.

Code: Select all

return {
	on = {
		devices = {
			'My_switch'
		}
	},
	execute = function(domoticz, TriggeredItem)
		domoticz.log('Device ' .. TriggeredItem .. ' was changed', domoticz.LOG_INFO)
		if (TriggeredItem) then -- state == 'On'
			TriggeredItem.switchOff().afterMin(1) -- if it is a switch
			domoticz.notify('Light info', 'The light ' .. TriggeredItem.name .. ' will be switched off soon')
		end
	end
}

Re: Switch off afer 1 minute fails, where is problem in this script

Posted: Monday 28 October 2019 0:20
by waaren
HvdW wrote: Monday 28 October 2019 0:10 I have this switch which I want to go to state OFF 1 minute after it is switched ON
Can you try this ?

Code: Select all

return
{
    on = 
    {
        devices = 
        {
            'My_switch'
        }
    },
    
    execute = function(domoticz, TriggeredItem)
        domoticz.log('Device ' .. TriggeredItem .. ' was changed', domoticz.LOG_INFO)
        if TriggeredItem.active then -- state == 'On'
            TriggeredItem.switchOff().afterMin(1) -- if it is a switch
            domoticz.notify('Light info', 'The light ' .. TriggeredItem.name .. ' will be switched off soon')
        else
            domoticz.log(TriggeredItem.name .. ' is now switched off.', domoticz.LOG_INFO)
        end
    end
}



Re: Switch off afer 1 minute fails, where is problem in this script  [Solved]

Posted: Monday 28 October 2019 1:15
by HvdW
.active that's it!
Thanks a lot!