Timers and DateTime

I didn’t know about this trigger until just yet. Great new function! Thanks! Is there also a way to do this for a group of datetime items? So that you can recycle the same rule for the group?

Also not sure if this doc is maintained and whether it pulls it automatically from json (it appears not) openhab-docs/jsr223.md at main · openhab/openhab-docs · GitHub

No, there’s no equivalent (yet?) to Member of for this Timer. You’ll have to list them all individually.

It’s manually maintained.

I have to say to the responses of “just use a rule to complete an action at a specific time” - there is one use case (at least) where this does not work. I use timers to execute actions at sunrise / sunset as well as for my wake alarm. All of these are dynamic and it would be cumbersome to update a Cron trigger each day.

It is simple to create a timer for these though - just as we use now.plusminutes(5) to create a date time object to set the timer one can also create your own date time object that isn’t based on the current time. For example create a new date time using the value from a sunrise date time item or an alarm date time item. I don’t have my code handy at the moment but I can try to remember to post an example later.

It seems like you’re using the Astro binding, since you have a sunrise datetime item. So why not you just use Astro to trigger a rule at sunrise? There’s no need for cron triggers or timers.

rule "Day"
when
    Channel 'astro:sun:local:rise#event' triggered START
then
    Time_of_Day.sendCommand("Day")
end

rule "Night"
when
    Channel 'astro:sun:local:set#event' triggered START
then
    Time_of_Day.sendCommand("Night")
end

I do have the Astro Binding. Ultimately I actually end up executing things based on these events but before they happen so that is why I don’t use the built in trigger in this instance.

1 Like

Interesting idea! So you would get today’s sunrise/sunset time every day, then update a DateTime item to trigger your rule at the desired offset from the sunrise/set time.

You can set an offset for every channel, you don’t need additional timers for that.

Thing astro:sun:local "Sonne" @ "zuhause" [geolocation="49,8,130", interval=300] {
    Channels:
        Type start : civilDawn#start [ // for display only
            offset=10,
            earliest="06:00",
            latest="08:00"
        ]
        Type start : civilDusk#start [ // for display only
            offset=15,
            earliest="16:00",
            latest="22:00"
        ]
        Type rangeEvent : civilDawn#event  [ // for trigger only
            offset=10,
            earliest="06:00",
            latest="08:00"
        ]
        Type rangeEvent : civilDusk#event  [ // for trigger only
            offset=15,
            earliest="16:00",
            latest="22:00"
        ]
}

it’s not displayed as yaml, I’m afraid, but you can configure the channels anyway.

You don’t need to, put the time in an item, use the item for the cron trigger and done.

I’ve never seen anything like this. Can you provide an example?

See above or in the documentation for 3.3 and 3.4

Good to know! Can you do this via the UI or is it only in text based thing definitions?

Looking above I see nothing of using an item in a cron rule. All I see examples of are the events from the Astro Channels.

edit - I do see now in the docs there is a single mention of using a rule trigger of “time is ‘item” that didn’t previously exist so that is good to know.

I presume that works with datetime items and would take effect immediately upon updating the item time? Overall documentation on the topic is rather lacking so it couldn’t hurt to have a little more detail in this topic.

Otherwise I think it’s important to still be aware of the many different ways to do things rather than simply telling someone their way is wrong. In programming there is always more than one way to do something and depending on the use case the best way may not always be the same.

Yes, it’s easy via Main UI → administration → Settings → Things → Astro sun thing → channels → select channel → configure.

Yes. As long as the date time is in the future, or the time part of ignoring the date, it will immediately set the rule to trigger at that time.

I’m not sure you saw my reply above where I went into some detail about the ways one can schedule code to run and when it’s best to use which approach.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.