Astro in OH2

I have a light that I want to come on 20 minutes before sunset and go off at 22:00.
So I’ve been reading a lot of threads and looking at examples. I have some been successful with other rules in the .rules file.
I have added the Astro binding.

and added the following to the .rules file:

rule "Amber Light Sunset On"
when
     Channel 'astro:sun:start:set#event' triggered START
then
    sendCommand(zwave_device_16500637f6a_node2_switch_dimmer, 100)
end

rule "Amber Light Off at 22:00"
when
	Time cron "0 0 22 1/1 * ? *"
then
    sendCommand(zwave_device_16500637f6a_node2_switch_dimmer, OFF)
end

I have also created the following in the .things file:

astro:sun:home [ geolocation="xxxx,yyyyy,88", interval=60 ] {
    Channels:
        Type start : set#event [
            offset=-20
        ]
        Type start : rise#event [
            offset=-20
        ]
}

(xxx, yyy replaced with my real coordinates)

I can’t tell from what I’ve read if this is all I need to make it work. My coordinates show up in the Astro Configuration. This makes me think it’s reading my .things file.

But the Astro thing (in HABMin) shows 71 channels, but none with the names I put in the thing file.

And, of course, I have to wait until sunset to see if it’s going to work…

When I set up Astro binding I didn’t use a Things file. I did how ever use the items file, here is one line

 Sun_Dawn_Start      "Dawn [%1$tR]"              <time>      { channel="astro:sun:local:civilDawn#start" }

I set my geolocation in PaperUI, I’m not using an offset but I think, maybe, that can be set in PaperUI as well. Have you linked anything to the Astro?

I don’t see a reason your rule wouldn’t work.

My understanding of what I’ve read and limited examples is that the Channel I’ve defined is a event that will be triggered a sunset -20 minutes (or 20 minutes before sunset).

I see what might be an error in that my channel in the rule should read:

Channel 'astro:sun:home:start:set#event' triggered START

I’m probably wrong, but I don’t think the other way refers to the thing I defined…dunno. :face_with_raised_eyebrow:

Good catch on the “home” in your channel. Reading other post I found others with issues using “home” and it has be mentioned to use “local” rather than home.

FYI I looked at my PaperUI and geolocation and interval can be set from there.

So…I should probably change it in both the rule and thing files???

Yes, the channel will need to be the same in both.

By the way: You can always get the correct channel name through Paper UI (Configuration->Things->Thing->Channel)
Fur sunset this will typically be:

astro:sun:home:set#event

Where astro:sun:home is the name of the thing, and set is the name of the channel. You must not use the channel type within the channel.
#event marks an event channel which is only to trigger rules. But it has to be configured the right way :wink: You mixed up rangeEvent and Start channels.

Please take a closer look at the full example

astro:sun:home [ geolocation="52.5200066,13.4049540,100", interval=60 ] {
    Channels:
        Type rangeEvent : rise#event [
            offset=-10,
            latest="08:00"
        ]
}

So, the Type should be rangeEvent, not start.

ummm…got this far AFTER having read the full example. :confounded:

I guess I don’t grok what a "range"Event is. Range implies to me it will be a range of time. Start on the other hand implies a particular start point in time.

Also, I think I get offset, but, latest? (I’m more interested in sunset…the rise type was just part of the cut and paste…)

In addition, home or local? What’s the diff? Home is a key word in thing files? And local isn’t?

Sorry I just don’t do well with examples where I need to extrapolate at this point in my learning curve. :neutral_face:

mark me confused :thinking:

And copied from the full example, doesn’t this show the type as start?:

astro:sun:home [ geolocation="52.5200066,13.4049540,100", interval=60 ] {
    Channels:
        Type start : rise#start [
            offset=5
        ]
        Type end : rise#end [
            offset=5
        ]
}

Astro Binding has a lot of channels. If you take a look at Sunset, there are four channels:

set#start -> Start of sunset (DateTime)
set#end -> End of sunset (DateTime
set#duration -> Duration of sunset (Number, in Minutes)
set#event -> rangeEvent, triggers START when reaching set#start and END when reaching set#end

So why is there a duration for sunset? Because the Sun is not a point but a circle, there is a moment when sun gets contact to the horizon and another moment when it loses contact to the horizon.

In question of offset and latest (and earliest!) you can set an offset and a range when the trigger should take place, so with

astro:sun:home [ geolocation="52.5200066,13.4049540,100", interval=60 ] {
    Channels:
        Type rangeEvent : set#event [
            offset=-10,
            latest="22:00"
            earliest="18:00"
        ]
}

the trigger would take place not earlier than 18:00, not later than 22:00 and between that time 10 Minutes before sunset. When using

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

it would be about 4 Minutes before

Channel 'astro:sun:home:set#event' triggered END

The name astro:sun:home is set by yourself:

astro:sun:home [ geolocation="xxxx,yyyyy,88", interval=60 ] {

if using

astro:sun:myastrothing [ geolocation="xxxx,yyyyy,88", interval=60 ] {

you would have to use

Channel 'astro:sun:myastrothing:set#event' triggered START

Change your cron expression to 0 0 22 * * ? *. The 1/1 means starting on the first of the month which may be messing things up for the OFF rule.

So, a bit clearer.
The list of Things (shown either in Paperui with the name I choose and in HABMin with less than helpful list under Channels ) is a list of things that come with the binding and in the .things file I’m defining what I want to default values to be (and the ones I don’t define get defaulted by Astro?)

And:

when
     Channel 'astro:sun:myastrothing:set#event' triggered START

So when Channel ‘astro:sun:myastrothing:set#event’ is triggered the START event, execute the then clause?

How do you get CronMaker to replace 1/1 with * (obviously I can just edit it now that I know…)

You should end up with:

rule "Amber Light Sunset On"
when
     Channel 'astro:sun:myastrothing:set#event' triggered START
then
    zwave_device_16500637f6a_node2_switch_dimmer.sendCommand(100)
end

rule "Amber Light Off at 22:00"
when
	Time cron "0 0 22 ? * * *"
then
    zwave_device_16500637f6a_node2_switch_dimmer.sendCommand(OFF)
end

I use : https://www.freeformatter.com/cron-expression-generator-quartz.html
To generate valid OH cron expressions

Please note the use of the .sendCommand method instead of the action.
See:

I rarely use cron expressions or CronMaker. I’ve no idea.

Yes, I read about the .sendCommand instead. Just hadn’t fixed after copy/paste from whatever example I copied. I’ve fixed that.

The two rules written as you show worked last night. But, what I’m really trying to get my head around is the syntax of this line in the when clause of rule:

Channel 'astro:sun:myastrothing:set#event' triggered START```

This is how I understand it at this point (please correct me where I’m wrong):

Channel 'astro:sun:myastrothing:set#event' triggered START
|        |     |    |           |    |     |         |
|        |     |    |           |    |     |         'START' shorthand for "and it is the START of the range event"
|        |     |    |           |    |     'triggered' shorthand for "when the range event is triggered"
|        |     |    |           |    'event' shorthand for range event
|        |     |    |           'set' shorthand for sunset channel
|        |     |    'myastrothing' a name I chose for my 'astro:sun' thing
|        |     'sun' data provided via the astro binding
|        'astro' the binding
'Channel' - built-in referring to a channel defined in a thing

I see by experimentation that I can create multiple ‘astro:sun’ things in the things file:

    Channels:
        Type rangeEvent : set#event [
            offset=20
        ]
}

astro:sun:myotherthing [ geolocation="xxx,yyy,88", interval=60 ] {
    Channels:
        Type rangeEvent : set#event [
            offset=20
        ]
}

And they show up in the Paperui. But, the offsets do not. (i.e. if I click the pencil icon the offset field is blank).
(I guess I might want to act on sunset elsewhere in the world… :smirk: )

Also, if I want the the event to happen 20 minutes before sunset it should be offset=-20, right?

Correct.

That maybe because you are defining them manually.
Do the event trigger? What do you see in the log?

The log shows the event 20 minutes after (offset was +20 at that point), so it triggered as specified.

The paperui shows the thing I named (as does the log show it triggering all the astro events, sunset, sunrise, dusk etc.)

Apparently, Paperui reads the things file, but doesn’t display the modifiers from the file.

If you have created the thing in a thing file you will not be able to midify them with the paperUI anyway.
As long as it triggers the event and runs the rule, I wouldn’t worry too much about a parameter not appearing in an admin UI as you would have to open the things files anyway to make changes if required.

Agreed.

Just notable that Paperui knows about the things, but not it’s parameters.

No, it does!
Maybe you didn’t look at the right place.
Please remember, that there are 4 channels for sunset, 3 of them have offset, earliest and latest as a parameter. I can confirm that my astro bindings shows up the correct parameters, set in .things file.

This is also a good way to control that there was no mistake in setting the parameters through the .things file, as not all typos are immediately identified as typos :wink:

Please be aware that openHAB will maybe create it’s own astro:sun:local Thing if location of the openHAB server is set up. (openHAB will also create wheater and ntp Things if these bindings are installed). Of course first these things are in the inbox…