[SOLVED] Help wanted to get Astro rules working

Hello,

I need some help here. The Astro binding information is not totally clear for me.

I’m upgrading from openHab 1.8.3 to 2.3.0 and I also want to use the new binding versions.
So I’m trying to get the Astro 2.x binding to work with my rules (translating the rules from 1.x binding to 2.x binding).
I want to trigger some rules with the astro binding and this is not a great success :roll_eyes:

This is my thing configuration:

Thing astro:sun:home  [ geolocation="52.5200066,13.4049540,100", interval=1800 ]

Thing astro:sun:home_plus20  [ geolocation="52.5200066,13.4049540,100", interval=1800 ]{
	Channels:
		Type start : set#start[offset=20]
	}

These are my Items:

DateTime SunRiseTime "Sun Rise: [%1$tH:%1$tM]" {channel="astro:sun:home:rise#start"}
DateTime SunSetTime "Sun Set: [%1$tH:%1$tM]" {channel="astro:sun:home:set#start"}
DateTime SunSetTimePlus20 "Sun Set Plus 20: [%1$tH:%1$tM]" {channel="astro:sun:home_plus20:set#start"}

This are the test rules:

rule "test Astro rule"
	when
		Channel "astro:sun:home:set#start" triggered START
	then
		mytestitem.sendCommand(ON)
	end

rule "test Astro rule + 20"
    when
		Channel "astro:sun:home_plus20:set#start" triggered START
	then
		mytestitem.sendCommand(ON)
	end

These rules won’t fire.
The Items shows the correct time in the UI!

In the binding examples there is only an example with an event:

rule "example trigger rule"
when
    Channel 'astro:sun:home:rise#event' triggered START 
then
    ...
end

But I want to trigger on the start of the sunset and sunrise, and on the sunset +20 offset.
so I changed the ‘event’ to ‘start’.
When I change the the ‘start’ to ‘event’, also nothing works.

Can someone help me please?

rule "test Astro rule"
when
    Channel "astro:sun:home:set#start" triggered
then
    mytestitem.sendCommand(ON)
end

rule "test Astro rule + 20"
when
    Channel "astro:sun:home_plus20:set#start" triggered
then
    mytestitem.sendCommand(ON)
end

Thanks for the tip, I will try this later today (@ sunset :smiley:)

Is it only with the ‘event’ that it is necessary to add the word ‘start’?
are there other conditions other than 'start" that can used after ‘triggered’ (with ‘event’ only?)?

Yes

afaik it’s only possible to use event channels for trigger:

rule myrule
when
    Channel 'astro:sun:home:set#event' triggered START or
    Channel 'astro:sun:home:rise#event' triggered START or
    Channel 'astro:sun:home:noon#event' triggered START
then
...

It’s also possible to use triggered END for trigger. START is the beginning of an event, END is the end.
WHAT!?! Sunrise has beginning and ending? Yes! As the sun is not a dot but a circle, there is a “first contact” to a line, the time when the circle “passes” the line and the “last contact” to the line. All events are virtual lines at various angles above or under horizon.

Thats a different answer as above.
Do you mean that the answer of vzorglub is not correct? (I don’t had the time to test it).

Could you please provide me some working examples (including the thing configuration)?

thanks

Please follow the link to the documentation. There is a full example at the end.

I just try that but it don’t work? I try all exaples, also from vzoglub (@vzorglub, could you provide me of working examples?)

Do I always need to create a extra thing with a event in it?
See my first post for my Things, they don’t trigger my rules, even when I use the

Channel 'astro:sun:home:rise#event' triggered START

line

In fact, you don’t need to configure any Channel, 'cause they are already pre configured.
I recommend a step-by-step solution.

  1. install Astro2 Binding and ensure that it’s installed.
  2. Create one thing:
Thing astro:sun:home "Sun"  [ geolocation="52.5200066,13.4049540,100", interval=180 ]
  • and take a look at Paper UI -> Things. The thing named “Sun” should appear as online.
  1. Now try linking some channels to items. Check if the thing “sun” is shown with the linked channels in Paper UI Control page.

When changing settings for channels, take a look at Paper UI -> Things -> Sun -> Channels (the one with changed settings) -> edit (the pencil symbol) to see if the parameters changed accordingly.

For first setup, it’s advisable to use a short interval to ensure that all changes take place in time. interval is in seconds, so 180 would be 3 Minutes.

When the first thing seems to be ok, create another thing and check wether the two things are online.

I thought my code would work but I could be wrong. I’ll have to test in the morning

Yesterday I created a bunch of testrules to trigger on the sunrise.
This one was the winner!

Channel "astro:sun:home:rise#event" triggered START

thank you guys for your advise.

I have also another question:

Is it possible to create a rule for the following logic?

when
     <CRON rule for for example 6 am>
then
     IF <check if it is after (or before) sunrise>{
     <do stuff>
     }
end

If this “IF” part possible?

Have a look at this very useful post:

I still have problems. The rules (or channels) with the offset won’t trigger.
See my first post for the configuration.

I use the datetime offset, could that be the problem?
I see there is also a event offset, what is the difference between the two?

Displaying datetimes on the GUI

For triggering in rules.

I recommend to use autodiscovered astro things, much more easier to setup for offsets :grinning:
If you need more than one offset, define additional things manually (via PaperUI) …

autodiscovered? do you mean with the PAPERUI (INBOX) ?

I use the text config files so I can backup them easy (like I did on OpenHab 1.x)

Yes.

PaperUI config is stored in JsonDB and backed up automatically :heart_eyes:

If you still want to do it with manual things files:
your things definitions are completely wrong, see examples in the docs for correct setup:

https://www.openhab.org/addons/bindings/astro/#full-example

Could you tell me why things are they completely wrong, so I can learn from it?
I used the examples as input for my configuration (almost the same!)

I used the thing config for the SUN thing, I made two things because I want to use the real sun set and I want to use one with a offset.
For the second one I used the “datetime offset” example.

so I created the following things:

Thing astro:sun:home  [ geolocation="52.5200066,13.4049540,100", interval=1800 ]

Thing astro:sun:home_plus20  [ geolocation="52.5200066,13.4049540,100", interval=1800 ]{
	Channels:
		Type start : set#start[offset=20]
	}

I know that I used “THING” before the thing config, this is so documented somewhere in the openhab documents, the things are online in the paperUI so I let it be there.

I find the explanation for this binding not very clear.

First there are all the available channels in the “channels” chapter, I want to use the thing “sun” with the group “set” and the channel “start”

Then there is the chapter “trigger channels”. I assume that this are the channels that can be used to trigger rules? The one I need (I want to use the thing “sun” with the group “set” and the channel (called event here) “start”) are included.

So I assume that a basic astro thing setup without any offset (see my first thing) can be used to display the time (datetime item) and trigger a rule like this:

when
   Channel "astro:sun:home:set#event" triggered START
then

This is also (almost) the same as in the axample.

I also thought that this same rule trigger can be used for a Thing with a “datetime offset”, should be logic but seems to be not.

Could you please rewrite my thing config and rules so like they should be? and please add some comment so I can understand what I’am doing wrong?

No, this is not possible like said before.

No, I can’t because I’m not using astro things in a text file. Please see the docs for a working config.

Instead I still recommend to do it the usual way via PaperUI:

1

You will be up and running a working config in 30 seconds :grinning:

You need to do this for the “Sunrise Start Time” (or whatever you want to use) to display your chosen time in your sitemap and you need to do this for the “Range event” channel to trigger on it in rules. Both channels need to have the same offset and/or earliest/latest settings.

Ok, thank you.

In the paper UI, do you also need to create more than 1 thing?
1 without offset and 1 with offset?