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

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

Moderator: leecollings

Post Reply
HvdW
Posts: 663
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

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

Post 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
}
Bugs bug me.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}


Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
HvdW
Posts: 663
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

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

Post by HvdW »

.active that's it!
Thanks a lot!
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest