On sunset but not before


i want to create a rule, that should fire an action on sunset, but not before 7pm.
What i tried:

rule "myRule"
Time cron “0 0 19 ? * *” or
Channel ‘astro:sun:934250e6:set#event’ triggered END
if((AstroSunData_Set_EndTime_TimeForSitemap.state as DateTimeType).calendar.before(__???)) {

how do i create a datetime object that represents 7 pm?

Thank you!

Steffen, it’s a lot easier, if You have a look at the Sunset Range event in Paper UI Things. Saves You a lot of work and works like a charm.

http://docs.openhab.org/addons/bindings/astro/readme.html -> Channel config

1 Like

If you also want a datetime object on your sitemap, you need to set two channels:
The “range channel”, already mentioned by @Schnicki, which can be triggered in rules and the “end time channel”, which creates the datetime for your sitemap.

In your case, both channels need to be configured like

Thank you!
I created now a astro.things with following ocntent:

astro:sun:home [ geolocation=“xx.xxxxx,xx.xxxxxx”, altitude=85, interval=240 ]
astro:sun:home_rangeEvent [ geolocation=“xx.xxxxx,xx.xxxxxx”, altitude=85, interval=240 ] {
Type rangeEvent : set#event [

So i can choose wether i want to use a earliest/latest set or a normal set :slight_smile:

(geolocation was hidden)

Tell us if that works :heart_eyes:
Unfortunately I was not able to set that up via text files … so I went with PaperUI setup.

It works for me!
I use the .things and .items file as much as i can as there is no support for the “eclipse smarthome” rule editor :frowning:

1 Like

Are you sure?
When I put your code into my things file I get an

2017-04-23 10:05:48.191 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'astro.things' has errors, therefore ignoring it: [18,1]: missing ']' at 'latest'
[18,7]: mismatched input '=' expecting ':'

After adding a comma behind the earliest definition I don’t get an error (did not check the rule trigger yet)


Sorry, didnt keep in mind that i fixed that after posting :-/

No problem, but please edit your above post so other users don’t copy wrong content, thx.

Thank you!
Fixed the .things in my posting above!

I’m struggeling with this config. I use the same but it is not working. earliest and latest are ignored.

My config:
astro:sun:Minus30 [ geolocation=“xx,yy”, interval=600 ]
Type rangeEvent : rise#event [

This should work as following:
Current sun rise time: 7:29
Because of -30 Offset new sun rise time: 6:59
Because of earliest 7:20: event should be triggered 7:20

But event is triggered at 6:59, which looks like earliest is not working?

What have I done wrong?

earliest AND latest in one trigger can’t work: the event gets triggered at 06:59, that’s it.
If you need another trigger at 07:20, add another astro thing and set it up for triggering at 07:20.

Hm, I understood this a little bit different.

earliest for me means what is the earliest time the event should come
latest for me means what is the latest time the event will come

This is no really AND it is just like:
If the event in inside of earliest and latest the deliver original date
if it is outside deliver ealiest or latest.

Am I wrong?

Example from documentation:
sun#rise earliest=18:00, latest=20:00

No idea. Maybe not.

Try your example through PaperUI setup to rule out any errors in your things file …

Edit: you should look for any errors in your openhab.log, normally it will tell you what is wrong with your syntax.

I tried it with PaperUI but there I cannot set latest or earliest. Can it be, that my binding is to old? I’m using Openhab 2.0 with original bindings.

That’s it :grinning:

Offsets may work with 2.0, but earliest/latest was introduced a lot later.
So you need to upgrade …