Simple Dimm level depends of time

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

Moderator: leecollings

Post Reply
YourBro
Posts: 2
Joined: Thursday 02 August 2018 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Simple Dimm level depends of time

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

Re: Simple Dimm level depends of time

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
YourBro
Posts: 2
Joined: Thursday 02 August 2018 19:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Simple Dimm level depends of time

Post by YourBro »

Thank you Waaren, much better now!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest