Page 1 of 1

switchOff after restart Domoticz

Posted: Friday 04 May 2018 19:47
by Andrey95
I wrote a script so that after restarting domoticz some switches are turned off, but it works. tell me what is wrong

Code: Select all

return {
    active = true,
    on = {
        timer = {'every minute'}
    },
    logging = { 
        level = domoticz.LOG_ERROR 
    },
    execute = function(dz)

         local Switches = domoticz.devices().filter({2,39})
        
        Switches.forEach(function(Switch)
            if (domoticz.systemUptime < 10) then
                Switches.switchOff().checkFirst()
            end
        end)    
    end
}

Re: switchOff after restart Domoticz

Posted: Friday 04 May 2018 20:36
by dannybloe
The timer fires every minute and systemUpTime is in seconds. So before the timer triggers your script it is very likely that more than 10 seconds have passed and your if-statement is false.

Better use a persistent data value that you compare with the uptime and when the uptime is lower than the currently stored value then you pull the switches. You get the idea.

Re: switchOff after restart Domoticz

Posted: Friday 04 May 2018 21:35
by waaren
Please be aware that domoticz.systemUpTime returns the number of seconds the whole system is Up.

domoticz.startTime.getISO() will give you the date/time domoticz was started. (domoticz.startTime is a time object)