[Solved] Seasonal Affectionate Disorder Lighting rules (noon start & end offsets)

Hi all,

Due to irregular work times and being prone to low energy during short daylight-season (aka fall & winter), I’d like to turn on and off some lights in relation to noon in the day. If I use clocks, it shifts once a year, while switching in relation to noon should provide a more gentle slope into and out of daylight savings time. I noticed my tropical houseplants (banana, mango) go into a growspurt at about 14 hours daytime, so I decided on that after I found out it is exactly 420 minutes from noon either way. Once I get it working I’ll probably tweak it to give me 16 hours of light a day.

I have read up on the astro binding, and I think I understand. I need to set start and end times for eventRanges to trigger rules. I should not need to define

Thing astro:sun:offset "Fake Sun" @ "Home"[ geolocation="anonymized moehahah", interval=60, useMeteorologicalSeason="true" ] {
        Channels:

//      event offset
                Type rangeEvent : rise#event [
                        offset=60
                ]

// Noon

//      dateTime offset
                Type start : noon#start [
                        offset=-420
                ]

                Type end : noon#end [
                        offset=420
                ]

                Type rangeEvent : noon#start [
                        offset=-420
                ]
                Type rangeEvent : noon#end [
                        offset=420
                ]

// event offset
        Type rangeEvent : set#event [
                offset=-60
                ]
}

And after restarting openhab, I can confirm this changes the event start and end times in the openhab.log.
So we’re all good, right?
sort of. If I don’t set the dateTime offset for noon,

//      dateTime offset
                Type start : noon#start [
                        offset=-420
                ]

                Type end : noon#end [
                        offset=420
                ]

then the notice saying it’s 420 minutes prior to noon / noon was 420 minutes ago, appears in the logs, AT NOON! not at 420 minutes before or after noon, at noon start, and a minute later at noon end.
So this is why I set a datetime offset.

rule "Switch On Before Sunrise"
        when
                Channel "astro:sun:offset:noon#event" triggered START
        then
                logInfo("Astro","Noon starts in 420 minutes")
                Outlet43_Power.sendCommand(ON)
        end

rule "Switch Off After Sunrise"
        when
                Channel "astro:sun:offset:rise#event" triggered START
        then
                logInfo("Astro","Sunrise ended an hour ago")
                Outlet43_Power.sendCommand(OFF)
        end

rule "Switch On Before Sunset"
        when
                Channel "astro:sun:offset:set#event" triggered START
        then
                logInfo("Astro","Sunset starts in 60 minutes")
                Outlet43_Power.sendCommand(ON)
        end

rule "Switch Off After Sunset"
        when
                Channel "astro:sun:offset:noon#event" triggered END
        then
                logInfo("Astro","it's 420 minutes after noon")
                Outlet43_Power.sendCommand(OFF)
        end

So, I would expect, from these rules, to have noon offset start at 420 minutes prior to noon, turning the light on. Then, an hour after sunrise, the light turns off again.
Then, an hour before sunset, the light turns on, after which it waits until 420 minutes have passed, and turns off the light again.

However: I guess the light turned on at noon, since it was on when I got home from work at about 18:30. It was supposed to turn on at about 17:45, because sunset is at 18:45. So I waited. But the moment 420 minutes after noon had passed, came, and went.
The light was still on, until I went to the bathroom at midnight, after which I noticed it being off.

When I came back, the logs showed this (I grepped for astro events)

2021-10-07 00:00:30.241 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:morningNight#event triggered START
2021-10-07 00:00:30.429 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:morningNight#event triggered START

I don’t know what morningNight is, but it turned off the light and I don’t see it anywhere in my rules, things, or items.
This seems like an inconsistency caused by a typo/oversight on the developers side.

Please point out if I have, myself, had an oversight. It is entirely possible. I still consider myself a noob, although I must admit I am more experienced than I was 10 years ago. Slowely but surely, I’ll turn into an intermediate programmer :stuck_out_tongue:

Where do you live? I’m asking because at certain locations, certain astro events don’t fire at all certain times of year

I don’t live up north far enough for the sun not to be above or below the horizon 18 degrees. I read about this on the forums. It’s not related. I can see sundown and noon being triggered. I just wonder why it won’t turn off my light/trigger my rule. I had noticed the astro binding taking a while to become initialized.

I’d recommend focusing on this, since I didn’t implement this but it still turns off my light:

" When I came back, the logs showed this (I grepped for astro events)

[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:morningNight#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:morningNight#event triggered START

I don’t know what morningNight is, but it turned off the light and I don’t see it anywhere in my rules, things, or items.
This seems like an inconsistency caused by a typo/oversight on the developers side."

I mean It works as it should:

tail -f /var/log/openhab/events.log| grep astro
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:morningNight#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:morningNight#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:morningNight#event triggered END
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:morningNight#event triggered END
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:astroDawn#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:astroDawn#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:nauticDawn#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:nauticDawn#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:astroDawn#event triggered END
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:astroDawn#event triggered END
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:nauticDawn#event triggered END
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:nauticDawn#event triggered END
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:civilDawn#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:civilDawn#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:civilDawn#event triggered END
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:civilDawn#event triggered END
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:daylight#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:daylight#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:moon:local:rise#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:rise#event triggered START
[INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:rise#event triggered START

Astro deals with a twenty-four day, 00:00 to 24:00. There are thus two night-ish segments in most days, morning night and evening night.

Not sure if that means good or bad, we can’t see any timestamps in your log snippet

I’m not using it, so it’s not relevant to me. It was not really the question asked in OP, merely something I noticed and have no use for. What I am curious about is WHY it turns off my light, none of my rules say it should, as you may be able to confirm if you read my entire post.

I thought it was more relevant that all events I was intending to use triggered. But as long as it doesn’t trigger my action, time is not relevant.

It triggers noon at 13:24 even though I set an offset of 420 minutes prior and after (for start and end respectively), and for the rangeevent.

events.log

2021-10-07 00:00:30.241 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:morningNight#event triggered START
2021-10-07 00:00:30.429 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:morningNight#event triggered START
2021-10-07 05:51:00.008 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:morningNight#event triggered END
2021-10-07 05:51:00.013 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:morningNight#event triggered END
2021-10-07 05:51:00.019 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:astroDawn#event triggered START
2021-10-07 05:51:00.025 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:astroDawn#event triggered START
2021-10-07 06:32:00.008 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:nauticDawn#event triggered START
2021-10-07 06:32:00.014 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:nauticDawn#event triggered START
2021-10-07 06:32:00.020 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:astroDawn#event triggered END
2021-10-07 06:32:00.025 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:astroDawn#event triggered END
2021-10-07 07:12:00.011 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:nauticDawn#event triggered END
2021-10-07 07:12:00.017 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:nauticDawn#event triggered END
2021-10-07 07:12:00.023 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:civilDawn#event triggered START
2021-10-07 07:12:00.029 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:civilDawn#event triggered START
2021-10-07 07:47:00.007 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:civilDawn#event triggered END
2021-10-07 07:47:00.013 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:civilDawn#event triggered END
2021-10-07 07:51:00.003 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:daylight#event triggered START
2021-10-07 07:51:00.007 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:daylight#event triggered START
2021-10-07 08:44:00.004 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:moon:local:rise#event triggered START
2021-10-07 08:47:00.005 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:rise#event triggered START
2021-10-07 08:47:00.013 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:rise#event triggered START
2021-10-07 08:51:00.005 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:rise#event triggered END
2021-10-07 08:51:00.011 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:rise#event triggered END
2021-10-07 13:23:00.006 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:noon#event triggered START
2021-10-07 13:23:00.010 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:noon#event triggered START
2021-10-07 13:24:00.005 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:noon#event triggered END
2021-10-07 13:24:00.011 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:noon#event triggered END
2021-10-07 17:55:00.012 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:set#event triggered START
2021-10-07 17:58:00.004 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:set#event triggered END

It’s weird because sunrise/sunset DO follow the required offset in the logs… and Turns OFF and ON the light. But the noon start/end does NOT turn ON and OFF the light.
openhab.log

2021-10-07 08:47:00.535 [INFO ] [org.openhab.core.model.script.Astro ] - Sunrise ended an hour ago
2021-10-07 13:23:00.016 [INFO ] [org.openhab.core.model.script.Astro ] - Noon starts in 420 minutes
2021-10-07 13:24:00.022 [INFO ] [org.openhab.core.model.script.Astro ] - it's 420 minutes after noon
2021-10-07 17:55:00.020 [INFO ] [org.openhab.core.model.script.Astro ] - Sunset starts in 60 minutes

as far as I understand from docs and reading the forums, DateTime offsets and RangeEvent offsets are completely independent of one another. As you can see, the time for noon start and noon end seems to be correct! in the datetime offset, so logically the same offset would be correct for the rangeevent.

The Astro binding has no idea what you light even is, so it won’t be doing anything to it.
Perhaps you’ve experimented with rules in UI and/or files, and overlooked one. Perhaps an event occurs when you don’t expect it. We can’t see your rules, we can’t see your unexpected light change. Perhaps that is shown as an Item command in your event.log, and you can relate it some other event.

Oh okay. First post and last post complained about wrong times.

Yes, absolutely correct.

Okay, so we can look closely at the ‘noon’ offset part only.
And …

So we can focus closely on only the event.

                Type rangeEvent : noon#start [
                        offset=-420
                ]
                Type rangeEvent : noon#end [
                        offset=420
                ]

These look fine to me.

EDIT - Ohhh wait, no these are nonsense. You can offset an event like noon, but not the start and end of that event individually.

                Type rangeEvent : noon#event [
                        offset=-420
                ]

There’s only one noon, so you can’t offset it both early and late.
But …
If you’re not using the ‘regular’ noon event astro:sun:local, use that for the other offset.

However …

                Type rangeEvent : rise#event [
                        offset=60
                ]

That one’s not working either -

Maybe your edits are not taking effect - check in your openhab.log that your xxx.things file loads without error.

Maybe it’s a matter of patience; Astro events are normally calculated and scheduled at midnight for the day ahead (or at reboot time for the day remaining)

Thanks for this useful reply, this took away some questions I had.
Kind of sucks that I can’t extend the range of an event, but the workaround is pretty easy, just make another offset sun.

Except for the light turning off at midnight :stuck_out_tongue: Since I started fresh with this openhab config, there’s no scripts or actions that should turn that light off.

I’ll see if it’s remedied after I fix the initial flaws in my setup. Think this’ll do it for now though!

2021-10-08 19:09:46.809 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Offset_Noon_End_EndTime’ changed from NULL to 2021-10-08T20:23:00.000+0200
2021-10-08 19:10:23.728 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Offset_Noon_Start_StartTime’ changed from NULL to 2021-10-08T06:22:00.000+0200

Seem to be getting the times I want!

NoonStart.things

Thing astro:sun:NoonStart "Noon Start" @ "Address, Town"[ geolocation="##.####,#.######", interval=60, useMeteorologicalSeason="true" ] {
        Channels:
// Noon
//      dateTime offset
                Type start : noon#start [
                        offset=-420
                ]
}

NoonEnd.things

Thing astro:sun:NoonEnd ""Noon Start" @ "Address, Town"[ geolocation="##.####,#.######", interval=60, useMeteorologicalSeason="true" ] {
        Channels:

// Noon

//      dateTime offset
                Type end : noon#end [
                        offset=420
                ]
}

Sunrise/sunset are still in one file, which was previously posted in this topic. Just remove the Noon section and it should work.

Mark fixed.

You don’t seem to have any offset noon events at all now, unless you’ve changed rules not to use those anymore.

Strange. It seems to be working properly however.

EDIT: I went back and checked and realized I omitted the event offset earlier…

Thing astro:sun:NoonEnd "Noon End" @ "House"[ geolocation="##.#####,##.####", interval=60, useMeteorologicalSeason="true" ] {
        Channels:


// Noon

//      dateTime offset
                Type end : noon#end [
                        offset=540
                ]
//      rangeevent offset
                Type rangeEvent : noon#event [
                        offset=540
                ]
}

rule "Switch On Before Sunrise"
        when
                Channel "astro:sun:NoonStart:noon#event" triggered START
        then
                logInfo("Astro","Noon starts in 420 minutes")
                Outlet43_Power.sendCommand(ON)
        end

rule "Switch Off After Sunrise"
        when
                Channel "astro:sun:offset:rise#event" triggered START
        then
                logInfo("Astro","Sunrise ended an hour ago")
                Outlet43_Power.sendCommand(OFF)
        end

rule "Switch On Before Sunset"
        when
                Channel "astro:sun:offset:set#event" triggered START
        then
                logInfo("Astro","Sunset starts in 60 minutes")
                Outlet43_Power.sendCommand(ON)
        end

rule "Switch Off After Sunset"
        when
                Channel "astro:sun:NoonEnd:noon#event" triggered END
        then
                logInfo("Astro","it's 420 minutes after noon")
                Outlet43_Power.sendCommand(OFF)
        end

openhab.log

2021-10-08 23:01:02.544 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.
2021-10-08 23:01:03.295 [INFO ] [openhab.core.model.script.greenhouse] - Pump off!
2021-10-08 23:01:06.166 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - Started HABPanel at /habpanel
2021-10-09 06:22:00.596 [INFO ] [org.openhab.core.model.script.Astro ] - Noon starts in 420 minutes
2021-10-09 08:51:00.015 [INFO ] [org.openhab.core.model.script.Astro ] - Sunrise ended an hour ago
2021-10-09 11:00:00.480 [INFO ] [openhab.core.model.script.greenhouse] - Pump on!
2021-10-09 11:01:00.563 [INFO ] [openhab.core.model.script.greenhouse] - Pump off!
2021-10-09 17:50:00.018 [INFO ] [org.openhab.core.model.script.Astro ] - Sunset starts in 60 minutes
2021-10-09 20:23:00.020 [INFO ] [org.openhab.core.model.script.Astro ] - it's 420 minutes after noon
[2021-10-10 06:22:00.020 [INFO ] [org.openhab.core.model.script.Astro ] - Noon starts in 420 minutes
2021-10-10 08:52:00.018 [INFO ] [org.openhab.core.model.script.Astro ] - Sunrise ended an hour ago
2021-10-10 17:48:00.013 [INFO ] [org.openhab.core.model.script.Astro ] - Sunset starts in 60 minutes
2021-10-10 20:23:00.017 [INFO ] [org.openhab.core.model.script.Astro ] - it's 420 minutes after noon

events.log

pi@OpenHAB:~ $ tail -f /var/log/openhab/events.log| grep astro
2021-10-10 19:26:00.023 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:NoonEnd:civilDusk#event triggered END
2021-10-10 19:26:00.025 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:civilDusk#event triggered END
2021-10-10 20:06:00.006 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:NoonEnd:nauticDusk#event triggered END
2021-10-10 20:06:00.011 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:nauticDusk#event triggered END
2021-10-10 20:06:00.015 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:astroDusk#event triggered START
2021-10-10 20:06:00.020 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:nauticDusk#event triggered END
2021-10-10 20:06:00.025 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:NoonEnd:astroDusk#event triggered START
2021-10-10 20:06:00.030 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:offset:astroDusk#event triggered START
2021-10-10 20:06:00.034 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:NoonStart:nauticDusk#event triggered END
2021-10-10 20:06:00.038 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:NoonStart:astroDusk#event triggered START
2021-10-10 20:22:00.006 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:NoonEnd:noon#event triggered START
2021-10-10 20:23:00.004 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:NoonEnd:noon#event triggered END