switchOff after restart Domoticz

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

Moderator: leecollings

Post Reply
Andrey95
Posts: 1
Joined: Friday 04 May 2018 19:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

switchOff after restart Domoticz

Post 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
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: switchOff after restart Domoticz

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: switchOff after restart Domoticz

Post 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)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest