[SOLVED] Time Of Day rule not triggering

  • Platform information:
    • Hardware: Raspberry Pi 3 / 1GB RAM / 32GB Storage
    • OS: OpenHabian
    • Java Runtime Environment: OpenJDK/Zulu 1.8
    • openHAB version: 2.4

I basically copied the “Design Pattern” post for time of day, but the rule for the “AFTERNOON” time (90 minutes before sunset) does not trigger. Here are the relevent snippets:

  • Items:

String vTimeOfDay “Current Time of Day [%s]”
DateTime vSunset_Time “Evening [%1$tH:%1$tM]” { channel=“astro:sun:5f1939d7:set#start” }
DateTime vEvening_Time “Afternoon [ %1$tH:%1$tM]” { channel=“astro:sun:9a95a386:set#start” }

You will note two different “Astro Sun” channels: the ‘5f1939d7’ value is the regular one while the ‘9a95a386’ one is one I created with a -90 minute offset from the start time of Sunset.

  • Rules:

rule “Calculate time of day state”
System started or // run at system start in case the time changed when OH was offline
Channel “astro:sun:5f1939d7:rise#event” triggered START or
Channel “astro:sun:5f1939d7set#event” triggered START or
Channel “astro:sun:9a95a386:set#event” triggered START or
Time cron “0 1 0 * * ? *” or // one minute after midnight to give Astro time to calculate the new day’s times
Time cron “0 0 6 * * ? *” or
Time cron “0 0 23 * * ? *”
[The rest of the rule snipped]

So I have the “When” conditions in there, and if I force the rules file to be run (after the start of my 90-minute offset but before sunset) by making a change in the rules file, the time of day does get calculated properly and set to AFTERNOON; it just doesn’t seem to get triggered on its own. In addition, when the “correct” Sunset time is reach, the time of day gets calculated at that time (and set to EVENING), as it should.

I am just not sure why the time of day isn’t getting calculated when the 90-minute offset event starts.

Your insights, as always, is appreciated! Thanks! :slight_smile:

Are your offset sunset triggered events showing in the events log? or show a value in paperui?

as @NicGray already asked, does event.log show the trigger take place ?

Also as a first line inside your rule add a debug output and see if that appears in openhab.log.

When I add the vEvening_Time item in my sitemap, it does show the correct time (90 minutes before the “Sunset” time)

It does not, though as I mentioned previously, if I force the rule to run during the “AFTERNOON” period by making a change in the rules file, it does calculate the time of day and then subsequently does make the Time Of Day “AFTERNOON”. It just doesn’t seem to trigger at the correct time.

Sunset does trigger properly on its own.

OK, I have added this as the first line of my “Then” section:

logDebug("Time Of Day", "DEBUG: Calculating time of day...")

I will check the log around the time my offset time should trigger (18:52 local time) and see what gets entered in the log files (if anything)

I will uopdate when I can. Thanks! :slight_smile:

You are setting Items to offset values, that’s fine.

But you are not using Items to trigger the rule - you’re using event triggers. That’s fine too … so long as you have configured the event offset in your Things? Astro state channels and event channels are separately configured.

That’s because then the “system started” trigger applies.
Same for your regular sunset trigger (check if you see a corresponding entry in event.log)

If you don’t see an entry in events.log for your 90-minutes-trigger then your thing definition may be bad or the binding needs a restart. Try deleting and re-adding your thing and double-check the spelling.

Unfortunately I was not able resolve this with the rules as-is, so I solved it by a different means: in my “when” section, I put just a cron timer every five minutes to calculate the time of day, and that seems to be working

Thanks to everyone for your suggestions, though.

OK, I think I found the real solution to this, though I won’t know for sure until tomorrow. I was searching around the forums for something semi-related, but found that someone actually had a similar issue to this and said they put the offset on the “Range Event”.

I realised I put my 90 minute offset on the “Sunset End Time”, so I have put my 90 minute offset on the Sunset “Range Event”, so I will see what happens tomorrow.