Page 1 of 1

triggering script between given hours

Posted: Saturday 15 October 2022 18:48
by Adso76
I have PIR sensor on detecting which I want to turn on other device. But I want this to happen only between given hours. Whats wrong with the script?

Code: Select all


return {

on =
    {

        devices = {
            'PIRSleeping',
            ['nightTime'] = {'between 23:00 and 06:00'}

           },
    },
       
    execute = function(domoticz, PIRSleeping)

        if (domoticz.devices("PIRSleeping").state == "Off" and (domoticz.devices == 'nightTime' and domoticz.devices == 'On')) then

            domoticz.devices('gosund').switchOn()

        end
    end

}

Re: triggering script between given hours

Posted: Saturday 15 October 2022 22:38
by plugge
Assuming that 'nightTime' is a device (which I doubt) that is triggered between 23:00-06:00.
PIRSleeping hold the triggered device.
The script should/could read like:

Code: Select all

return {

on =
    {

        devices = {
            'PIRSleeping',
            ['nightTime'] = {'between 23:00 and 06:00'}

           },
    },
       
    execute = function(domoticz, PIRSleeping)

        if domoticz.devices("PIRSleeping").state == "Off" and
     	   (PIRSleeping.name == 'nightTime' and PIRSleeping.state == 'On')
	then
            domoticz.devices('gosund').switchOn()
	end
    end
}
if 'nightTime' is not a device then you need a different script:

Code: Select all

return {

on =
    {

        devices = {
            ['PIRSleeping'] = {'between 23:00 and 06:00'}

           },
    },
       
    execute = function(domoticz, PIRSleeping)

        if domoticz.devices('PIRSleeping').state == 'Off'
	then
            domoticz.devices('gosund').switchOn()
	end
    end

}

Re: triggering script between given hours

Posted: Sunday 16 October 2022 8:00
by Adso76
Thanks a lot! Works perfectly! I couldn't grasp that from dzvents tutorial.