Page 1 of 1

Start script after specific sunrise time

Posted: Tuesday 03 September 2024 10:40
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')"

Re: Start script after specific sunrise time

Posted: Tuesday 03 September 2024 10:59
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

Re: Start script after specific sunrise time

Posted: Tuesday 03 September 2024 12:28
by FlyingDomotic
Try with an uppercase "I" in "sunriseInMinute" (things are case sensitive).

Re: Start script after specific sunrise time

Posted: Tuesday 03 September 2024 13:16
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.

Re: Start script after specific sunrise time

Posted: Wednesday 04 September 2024 7:19
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