Page 1 of 1

Simple Dimm level depends of time

Posted: Thursday 02 August 2018 19:28
by YourBro
Hi everyone,

Newbie question :D
I am trying create script to change dimm level depending on time. The problem if device.state == "On", I cannot turn lamp off at all, only by disabling script.

Bar device it is fibaro dimmer.

Any help would be greatly appreciated.

Code: Select all

return {
    on = {
        devices = {
            "Bar"
        }
    },
    execute = function(dz, device)
        if (dz.time.matchesRule("at 18:00-21:00"))  then 
            lightlevel = 100
        else 
            lightlevel = 20
        end
        if(device.state == "On") then
            device.dimTo(lightlevel)
        else
            device.switchOff()
        end
    end
}

Re: Simple Dimm level depends of time

Posted: Thursday 02 August 2018 20:13
by waaren
YourBro wrote: Thursday 02 August 2018 19:28 Hi everyone,

Newbie question :D
I am trying create script to change dimm level depending on time. The problem if device.state == "On", I cannot turn lamp off at all, only by disabling script.

Bar device it is fibaro dimmer.

Any help would be greatly appreciated.
the problem with your script is that it is calling itself (via the device) Adding the silent() option should solve it. See below

Code: Select all

return {
    on = {
        devices = {
            "Bar"
        }
    },
    execute = function(dz, device)
        if (dz.time.matchesRule("at 18:00-21:00"))  then 
            lightlevel = 100
        else 
            lightlevel = 20
        end
        if device.state == "On"  then
            device.dimTo(lightlevel).silent()
        else
            device.switchOff().silent()
        end
    end
}

Re: Simple Dimm level depends of time

Posted: Monday 06 August 2018 21:45
by YourBro
Thank you Waaren, much better now!