Lights on when LUX <=500 else off

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

Moderator: leecollings

Post Reply
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Lights on when LUX <=500 else off

Post by EdwinK »

I know I've seen such a script here somewhere, but searching for it doesn't find any.

What I need to do is when the LUX is below a set level (500 for example) it needs to turn on the outside lights. When the level is above the set level then turn it off again.

(The 500 is arbitrary, it could well be another level that I need, think twilight or dusk).
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lights on when LUX <=500 else off

Post by waaren »

EdwinK wrote: Sunday 30 December 2018 15:32 I know I've seen such a script here somewhere, but searching for it doesn't find any.

What I need to do is when the LUX is below a set level (500 for example) it needs to turn on the outside lights. When the level is above the set level then turn it off again.

(The 500 is arbitrary, it could well be another level that I need, think twilight or dusk).
In its most simple form

Code: Select all

-- outside lights 

return {
            on      =   {   timer                       =   { "every 15 minutes"  } },
            
    execute = function(dz)
        lowerLux        = 400
        upperLux        = 500
        currentLux      = dz.devices("lux device name").lux
        outsideLight    = dz.devices("outside light name")
        
        if currentLux < lowerLux then
            outsideLight.switchOn().checkFirst()
        elseif currentLux > upperLux then
            outsideLight.switchOff().checkFirst()
        end
    end
}
Last edited by waaren on Sunday 30 December 2018 17:35, edited 1 time in total.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Lights on when LUX <=500 else off

Post by EdwinK »

Thanks. I like the most simple form's :). Just I have several switches. One called 'Lamp - Berging' and the others 'Buiten - 1' and 'Buiten - 2' Should have said that before ;)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lights on when LUX <=500 else off

Post by waaren »

EdwinK wrote: Sunday 30 December 2018 16:07 Thanks. I like the most simple form's :). Just I have several switches. One called 'Lamp - Berging' and the others 'Buiten - 1' and 'Buiten - 2' Should have said that before ;)
If you always want to switch them together then probably easier to put them in a group. Please send me a PM if you want to discuss further
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Lights on when LUX <=500 else off

Post by EdwinK »

Let's see if I can get that to work
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: Lights on when LUX <=500 else off

Post by havnegata »

Please, @waaren, continue to share your knowledge here in the forum and not by PM's. That way lots of people can learn, and I for sure have learned a lot from you!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lights on when LUX <=500 else off

Post by waaren »

havnegata wrote: Sunday 30 December 2018 17:32 Please, @waaren, continue to share your knowledge here in the forum and not by PM's. That way lots of people can learn, and I for sure have learned a lot from you!
I will but sometimes the process of getting to a result require a lot of communication that is not very interesting for many.
I always ask to share the end-result when it can be of any use to others.

and.. thx for the compliment.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Lights on when LUX <=500 else off

Post by EdwinK »

O.. I will put the end result ;)

Code: Select all

-- outside lights 

return {
            on      =   {   timer                       =   { "every 15 minutes"  } },
            
    execute = function(dz)
        lowerLux        = 400
        upperLux        = 500
        currentLux      = dz.devices("LUX").lux
        outsideLights   = dz.groups("Buitenlampen")   --This should be a group, not a scene!!
        
        if currentLux < lowerLux then
            outsideLights.switchOn().checkFirst()
        elseif currentLux > upperLux then
            outsideLights.switchOff().checkFirst()
        end
    end
}
Now it looks real simple.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
havnegata
Posts: 114
Joined: Wednesday 10 September 2014 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10162
Location: Norway
Contact:

Re: Lights on when LUX <=500 else off

Post by havnegata »

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest