Astro binding to move switches at sunset/sunrise

Maybe i’m dumb but I remember I copied from the documentation few weeks ago.
I will see tomorrow if it works.

As usually, thanks so much Sihui for the support.

I don’t think so :slight_smile:
As far as I remember they have been in the docs all the time (I copied them too from that place).

Tried again, but no result. This is the rule:

rule "ImpostaNotte"
when
	Channel 'astro:sun:local:set#event'	triggered START
then
	sendCommand(Notte, ON)
end

The string astro:sun:local:rise#event has been copied from paperUI things page, so I suppose it is correct.

Okay, then we have to dig a little deeper:

  1. Check if you have the correct thing:
    In PaperUI, you should see a channel astro:sun:local:set#start
    If you see astro:sun:home:set#start, you need to change your rule to
    Channel 'astro:sun:home:set#event' triggered START

  2. add a loginfo to your rule:

    rule "ImpostaNotte"
    when
    Channel ‘astro:sun:local:set#event’ triggered START
    then
    logInfo(“FILE”,“Sunset event has been triggered”)
    sendCommand(Notte, ON)
    end

(Don’t forget to use the correct name local or home according to your defined thing)

Then take a look in to your openhab.log if it says “Sunset event has been triggered”.
If this is the case your switch definition may be wrong (you could try using Notte.sendCommand(ON)

What do you want to say with this?

If you meant me:
that the name of the channel definition has to match the name of the trigger definition.

Example:

Channel:

astro:sun:local:set#start

rule trigger:

Channel ‘astro:sun:local:set#event’ triggered START

I confirm that the rule was correct, but it started working after the installation of snapshot on 5th february

1 Like

@sihui
Sorry about that. Indeed my question was for you. I didn’t understand what you were trying to explane.
But now it’s all clear to me.
Thanks

Hi, I am trying to get something similar done: I have two switches

Switch nightTime "Nacht" <moon>
Switch dayTime "Tag" <sun>

that I want to change when the sun starts to go down (nightTime on/dayTime off) and when it has finished rising (nightTime off/ dayTime on).
I have created sun and moon things for the astro binding

astro:sun:home  [ geolocation="xxx,xxx", interval=60 ] 
astro:moon:home [ geolocation="xxx,xxx", interval=60 ]

and these rules to switch between day and night.

rule "Set day time"
when
    Channel 'astro:sun:home:rise#event' triggered START
then
    sendCommand(nightTime, OFF)
    sendCommand(dayTime, ON)
end

rule "Set night time"
when
	Channel 'astro:sun:local:set#event' triggered START
then
    sendCommand(nightTime, ON)
    sendCommand(dayTime, OFF)
end

It doesn’t seem to work though. The switches never change their states. Where is the error? And are these the right channels for my needs?
I am using openhab version 4.0.8 and the version of astro that gets installed via the paperUI.

I can’t fully answer why you are having the problem but I do notice the following:

  • the channel names are different between your sunrise and sunset rule trigger names. One references home which does match your Things and the other matches local which is different from your Things.
  • 4.0.8 is not a valid OH version number
1 Like

@rlkoshak Thanks! I don’t know why I did not see that. I changed local to home, hopefully that was the error.
I am actually using openhab 2.1.0, my bad, but 4.0.8 is what typing in ‘version’ returns in the openhab console… strange.

That’s the version of the Karaf server upon which OH runs.

Ah, that makes sense. Thank you. With the name (local -> home) everything is working great now

rule "example trigger rule"
when
Channel ‘astro:sun:home:rise#event’ triggered START
then

end

This will give an ON with no duration, means it will switch to OFF right after the ON.
I you need a steady ON/OFF you can use the above rule and use a proxy item.

As some have maybe seen, i moved forward to OH2. Right now i update Astro and have one issue regarding Sunset events. Previously i did it like this:

Switch MySunset_Event {astro=“planet=sun, type=set, property=end, offset=15”}

Now my questions:

  • Does such an item still exist to reference it later in a rule to switch on another item?
  • Or is the Rule above the way to go forward with OH2?
  • With the rule above, do I have any issue with this “going on with no duration”…if in the rule i want to switch on a device simply when sunset has come?

Best Regards,
Norbert

Offsets and earliest/latest events have to be defined in the channel, either in the things file or via PaperUI:

http://docs.openhab.org/addons/bindings/astro/readme.html

You may create those items, take a look at the Design Patterns:

Don’t fully understand this, but I don’t think you will have any issues …

The duration is mainly a concern for when people want to have a switch that remains ON for the full sunset time so they can check the sunset state and do something different in other rules.

The time of day design pattern shoes how to use the events, DateTimes, and how to keep track of the time of day without letting your rules with duplicated if(now.isAfter(sunrise) && now.isBefore(noon)) statements.

2 Likes

hm, i tried now to set an event via channel astro:sun:local:set#start. As to me it looked the most promising to what i want to reach…a trigger when sunset starts. Did not trigger. So I had a second look and saw that in the docs its stated to use the following channel: astro:sun:home:rise#event

Will do the same analog for set event. but my question is - in order to use events I have to use this “range event” channel. It does not work to simply make use of another channel like the one for set_start (?)

Regards
Norbert

Event is the only channel that can be used to trigger rules. I am not entirely certain whether event corresponds with start our end but I think it’s.

It depends on how you did configure your astro things: if you got them through autodiscovery the are usually named
1

astro:sun:local and the corresponding channel needs to be astro:sun:local:rise#event.

If you defined it manually either through text files or via GUI, it can have different names, in my case for example:
2
so the corresponding channel trigger needs to be

astro:sun:shutterlivingroom:rise#event.

In my PaperUI I see:

However, this rule never gets triggered:

rule "Zonsopgang - nachtverlichting uit"

when
    Channel 'astro:sun:local:rise#event' triggered START 
then
	logInfo("Astro","De zon komt op. Goedemorgen.")
    sendCommand(KNX_GV_Nachtverlichting_4_2_0, OFF)
end

So I guess I got the naming correct, but it still doesn’t work. Any idea?