Dzvents turn on garden lights when time is x minutes before sunrise

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

Moderator: leecollings

Post Reply
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Dzvents turn on garden lights when time is x minutes before sunrise

Post by snellejellep »

Since the days are getting shorter again i want my garden lights to turn on in the morning.

Current situation:
I am using dzvents to turn on a group of lights at sunset and turn them off at 1.00 at night.

Request:
Add to the above script the following:
Turn on at 6.00 when sunrise time is 6.30 or later and turn off at sunrise.

The request above is something i can not seem to get to work.
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Dzvents turn on garden lights when time is x minutes before sunrise

Post by snellejellep »

My script right now is:

Code: Select all

return {

on = {

timer = { "at sunset",

"at sunrise",

"every 5 minutes"

}

},

execute = function(dz, device)

local garden_lights = dz.groups("Tuinverlichting") --group used to switch multiple garden lights/switches

local morningtime = "06:30" --time in minutes after midnight sunrise should be for the garden lights to turn on

if dz.time.matchesRule("at sunset") then

garden_lights.switchOn()

elseif dz.time.matchesRule("at 1:00") then

garden_lights.switchOff()

elseif (sunriseinMinutes.matchesRule('after 6:30')) and dz.time.matchesRule("at 6:00") then

garden_lights.switchOn()

elseif dz.time.matchesRule("at sunrise") then

garden_lights.switchOff()

end

end

}
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents turn on garden lights when time is x minutes before sunrise

Post by waaren »

snellejellep wrote: Monday 24 September 2018 13:09 I am using dzvents to turn on a group of lights at sunset and turn them off at 1.00 at night.
Request: Add to the above script the following:
Turn on at 6.00 when sunrise time is 6.30 or later and turn off at sunrise.
You are close; can you try this ?

Code: Select all

return { on = { timer = {   "at sunset", 
                            "at sunrise",  
                            "at 01:00",
                            "at 06:00",
                        }},

    execute = function(dz)
        local garden_lights         = dz.groups("Tuinverlichting")       -- group used to switch multiple garden lights/switches
        local checkTimeInMinutes    = 6 * 60 + 30                        -- 6:30   
        
        if dz.time.matchesRule("at sunset") then
            garden_lights.switchOn()
        elseif dz.time.matchesRule("at 6:00") then
            if dz.time.sunriseInMinutes > checkTimeInMinutes then
                garden_lights.switchOn()
            end    
        elseif dz.time.matchesRule("at sunrise") or dz.time.matchesRule("at 1:00") then
            garden_lights.switchOff()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Dzvents turn on garden lights when time is x minutes before sunrise

Post by snellejellep »

thanks! i implemented it and will see if the lights will turn on.
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Dzvents turn on garden lights when time is x minutes before sunrise

Post by snellejellep »

It works great! Thanks!
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest