Start script after specific sunrise time

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

Moderator: leecollings

Post Reply
jberinga
Posts: 60
Joined: Tuesday 11 August 2015 14:20
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: The Netherlands
Contact:

Start script after specific sunrise time

Post by jberinga »

Is it possible to execute this script when the sunrise is after 6:50?
Spoiler: show
local startTime = '6:30'
local endTime = '7:15'

return {
on = {
timer = { 'between ' .. startTime .. ' and ' .. endTime },
devices = { 'IsDonker', 'SensorMotionKeuken' }
},

data = {
dimmerSet = { initial = 0 }
},

execute = function(domoticz, device, item)
-- reset to initial value
if
domoticz.time.matchesRule('at ' .. startTime)
then
domoticz.data.dimmerSet = 0
end

--Donker, Alarm aan = Dimmer aan & dimmen + 1
if
domoticz.devices('IsDonker').state == 'On' and
domoticz.devices('WekkerAlarm').state == 'On' and
domoticz.time.matchesRule('between ' .. startTime .. ' and ' .. endTime)
--and domoticz.time.sunriseinMinutes.matchesRule('after 6:50')
then
domoticz.devices('DimmerSlaapkamer').dimTo(domoticz.data.dimmerSet)
domoticz.data.dimmerSet = domoticz.data.dimmerSet + 1
end

--Na 10 minuten, verlichting uit bij beweging beneden
if
domoticz.devices('DimmerSlaapkamer').state ~= 'Off' and
domoticz.devices('SensorMotionKeuken').state == 'On'
then
domoticz.devices('DimmerSlaapkamer').switchOff().afterMin(10)
domoticz.log('Slaapkamer dimmer gaat uit.', domoticz.LOG_INFO)
end

--Niet meer donker, verlichting uit
if
domoticz.devices('DimmerSlaapkamer').state ~= 'Off' and
domoticz.devices('IsDonker').state == 'Off'
then
domoticz.devices('DimmerSlaapkamer').switchOff()
domoticz.log('Slaapkamer dimmer gaat uit.', domoticz.LOG_INFO)
end

end
}
As you can see I have tried "domoticz.time.sunriseinMinutes.matchesRule('after 6:50')" but then I get the error: "attempt to index a nil value (field 'sunriseinMinutes')"
willemd
Posts: 648
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Start script after specific sunrise time

Post by willemd »

So you want to take some action betweeb 6:30 and 7:15 but only if sunrise is after 6:50?

I would then trigger the script with the between 6:30 and 7:15 condition and then in the script test whether sunrise is after 6:50 before doing any further action.

I see in the dzVents wiki there is a "sunriseInMinutes" time property, so you should be able to use that for the 6:50 sunrise test.
https://www.domoticz.com/wiki/DzVents:_ ... _scripting
FlyingDomotic
Posts: 356
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Start script after specific sunrise time

Post by FlyingDomotic »

Try with an uppercase "I" in "sunriseInMinute" (things are case sensitive).
jberinga
Posts: 60
Joined: Tuesday 11 August 2015 14:20
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: The Netherlands
Contact:

Re: Start script after specific sunrise time

Post by jberinga »

willemd wrote: Tuesday 03 September 2024 10:59 So you want to take some action betweeb 6:30 and 7:15 but only if sunrise is after 6:50?

I would then trigger the script with the between 6:30 and 7:15 condition and then in the script test whether sunrise is after 6:50 before doing any further action.

I see in the dzVents wiki there is a "sunriseInMinutes" time property, so you should be able to use that for the 6:50 sunrise test.
https://www.domoticz.com/wiki/DzVents:_ ... _scripting
Correct and that has been tested but I got the error "attempt to index a nil value (field 'sunriseinMinutes')".

But FlyingDomotic got a excelent point ;)
FlyingDomotic wrote: Tuesday 03 September 2024 12:28 Try with an uppercase "I" in "sunriseInMinute" (things are case sensitive).
Made the change and I will see what happens tomorrow morning.
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Start script after specific sunrise time

Post by habahabahaba »

Code: Select all

execute = function(domoticz, trigger)
        
        local currentDate = os.time()
        
        local setTime1 = '06:30'
        local time1 = os.date("%Y-%m-%d "..setTime1, currentDate)
        local time1toStamp = domoticz.time.dateToTimestamp(time1)
        
        local setTime2 = '07:15'
        local time2 = os.date("%Y-%m-%d "..setTime2, currentDate)
        local time2toStamp = domoticz.time.dateToTimestamp(time2)
        

        local minutesToSunrise = domoticz.time.sunriseInMinutes 
        local time3 = os.date("%Y-%m-%d 00:00", currentDate)
        local CurrentSunriseTimeStamp = domoticz.time.dateToTimestamp(time3) + minutesToSunrise * 60
        local todaySunriseTime = domoticz.time.timestampToDate(CurrentSunriseTimeStamp,'%Y-%m-%d time')

        
        
        domoticz.log('time 1 stamp: '.. time1toStamp, domoticz.LOG_ERROR)
        domoticz.log('Time1: '.. time1, domoticz.LOG_ERROR)
        
        domoticz.log('time 2 Stamp: '.. time2toStamp, domoticz.LOG_ERROR)
        domoticz.log('time2: '.. time2, domoticz.LOG_ERROR)
        
        domoticz.log('CurrentSunriseTimeStamp: '.. CurrentSunriseTimeStamp, domoticz.LOG_ERROR)
        
        domoticz.log('todaySunriseTime: '.. todaySunriseTime, domoticz.LOG_ERROR)
        

        
        
        if CurrentSunriseTimeStamp > time1toStamp and CurrentSunriseTimeStamp < time2toStamp then
            
            domoticz.log('Its MATCH!!!', domoticz.LOG_ERROR)
            
        end

    end
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest