Astro binding to move switches at sunset/sunrise

I tried a lot of what was suggested and found astro too much hard work for what it should have been. I mean all i wanted to do was to turn a light on around the time it went dark so how hard could that be? :slight_smile: In the end i popped for a different approach using MQTT and a command line tool called sunwait. http://www.risacher.org/sunwait/

Assuming MQTT already set up i did the following…

  • Download and compile sunwait then copy to /usr/local/bin
  • Add cron entries (sudo crontab -e) that would trigger MQTT events at the right time for sun rise and sun set (can add offsets here too)
00 01 * * * /usr/local/bin/sunwait sun up +0:00:00 <lat>N <long>W; echo 0 | /usr/bin/mosquitto_pub -u <user> -P <pass> -t home/night -l -q 2
00 01 * * * /usr/local/bin/sunwait sun down -0:10:00 <lat>N <long>W; echo 1 | /usr/bin/mosquitto_pub -u <user> -P <pass> -t home/night -l -q 2
  • This starts a wait at 1am every day that when triggered calls the MQTT pub message for sun up/down events
  • Then i bound an item to this in openhab…
Switch Lights_NightTime "Night Time" <moon> {mqtt="<[mosquitto:home/night:state:MAP(binary.map)]"}

Seems reliable and i can control offset nicely. Given the pages of information ive read about astro, it seems a lot simpler if you have MQTT set up too.

for reference i tied the switch to a rule which turned on all lights in a group at sundown -10 and turned them off at 10pm

rule "Evening Lights On"
when
    Item Lights_NightTime changed to ON
then
    logInfo( "Lights", "Turning on evening lights...")
    LightsEvening_Group.members.forEach[s | s.sendCommand(ON)]
end

rule "Evening Lights Off"
when
    Time cron "0 0 22 ? * MON-SUN"
then
    logInfo("Lights", "Turning off evening lights...")
    LightsEvening_Group.members.forEach[s | s.sendCommand(OFF)]
end

Nice work, but in my opinion a little bit complicated for a lot of users.
Installing the astro binding and do some mouse clicks to configure it is a lot easier … :sunglasses:

1 Like

Hi @sihui. Sorry for the late reply, I was offline for several days.

I had some unforgettable sunsets. :wink:

Thanks!

Given the list of problems here and on other threads its clearly not quite as simple as we would all like it to be quite yet. Maybe 2.2 will fix that of course.

Very much of the opinion that astro is a bit of sledgehammer to crack a nut. Id love to see a nice simple “night time” binding that provides a switch when its light / dark with some optional offsets so i didn’t have to do what i did. Taking 2.2 daily snapshots is not something i wanted to do either given the variety of success in this thread and other issues that could bring.

1 Like

I’m with @sihui. What you did is very clever but I fail to see how it is any less complicated or any less of a sledge hammer than using Astro.

I’m sure many users would welcome such a binding. Do you plan on implementing it?

Having a new “simpler” nightime binding won’t fix this problem. Bugs happen, they get fixed in the newer versions, the project moves on. This is true for all add-ons.

True, but i guess the main difference is that it works reliably now in 2.1, which astro does not. Ive not plucked up the courage to try 2.2 snapshots as that seems a bit bleeding edge for me and any issues will lower the wife acceptance factor.

im pretty new to the community having lingered for a short while but Im tempted to have a go as the scope seems very simple so it may be a nice introduction.

True, maybe im just a bit impatient and like things to work. This thread has been going for 9 months so change is very slow. I really love openhab and the architecture so far and am bought in for the long run :slight_smile:

It is indeed an older thread but to be fair, the bug in Astro was fixed within a week or two, if not sooner, from when the problem was reported. In an ideal world, the problem would have been detected during the beta period test but for whatever reason, it was not.

If you don’t want to be on the bleeding edge but still get it to work, I think you can choose a specific version of the SNAPSHOT. Just choose one that isn’t too far past when the 2.1 release occurred.

Were it almost any other binding, you could also upgrade just that one binding. But I think Astro is now managed directly under the Eclipse Smarthome project and I don’t think it is as easy to get it as a separate jar file as the other bindings are.

For the record, I’ve been running on build 988 very stably for over 8 weeks now. It absolutely does not have the bug with Astro.

Thanks for the guidance, very tempted to give that a go now.

Here is a workaround for manually installing an astro binding update:

1 Like

Hi,

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:home:set#event' triggered START
then
    sendCommand(nightTime, ON)
    sendCommand(dayTime, OFF)
end

And put those switches into my site map just for testing purposes

		Frame label="TAG/NACHT ANZEIGE"{
						Switch item=nightTime label="Nacht" icon="moon"
				Switch item=dayTime label="Tag" icon="sun"
				}

The problem now it does not seem to work, both “switches” are turned off.

This is what i can find in the log:


2018-01-08 20:33:08.355 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'daynight.rules'

2018-01-08 20:33:09.449 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'daynight.rules'

what did i do wrong ?

For one, have you waited for a sunrise or a sunset to occur? Those rules will only trigger for those events. If you restart OH or change a .items file without Persistence and restoreOnStartup then these Switches are in the NULL state.

You either need to wait for a sunrise or a sunset or you need to create a System started rule that will calculate what the switches should be in based on the actual time of day.

See Design Pattern: Time Of Day

Thank you it works now. Waited for sunrise.

One more question what do I need to change so the switch for nighttime and daytime are triggered 30 minutes before sunrise/sunset ?

kind regards

@salexes
For this you can define an offset in the thing config of the astro thing. Or create an additional thing for this then you can use both.

astro:sun:Special [ geolocation="xx.xx,yy.yy", altitude=300, interval=600 ]
{
	Channels:
		Type rangeEvent : rise#event [
            offset=-15,
            earliest="07:00",
            latest="08:00"
        ]
        
		Type rangeEvent : set#event [
            offset=20, 
            //earliest="19:10",
            latest="20:00"
        ]
} 
1 Like

Sorry for hijacking, but I’m currently clueless on a similar Approach. I’d like to have a rangeEvent on daylight and night.
my config is:

astro:sun:home   [ geolocation="xx.xxx, xx.xxx", interval=300 ] {
	Channels:
		Type rangeEvent : night#start [
			earliest="21:30",
			latest="22:30"
		]
		Type rangeEvent : night#end [
			earliest="06:00",
			latest="06:30"
		]
		Type rangeEvent : daylight#start [
			earliest="06:00",
			latest="07:30"
		]
		Type rangeEvent : daylight#end [
			earliest="16:00",
			latest="21:30"
		]
}

but still:

2018-01-08 16:37:00.042 [vent.ChannelTriggeredEvent] - astro:sun:home:daylight#event triggered END
...
2018-01-09 08:12:00.005 [vent.ChannelTriggeredEvent] - astro:sun:home:daylight#event triggered START

I’m beginning to think, the “#event” won’t be touched by “#start” and “#end” ?

Thank you just implemented it, lets see if it works!

This is normal, and will trigger again on the offset times

Will something like this work?
I have some devices that I would like to have a 2 hr off set and others with an 1 hr?

astro:sun:home [ geolocation=“xx, yy”, interval=60 ]

// 2 hours before sunrise or no later than 8:30 am or no earlier than 5:30 am for some devices
{
Channels:
Type rangeEvent : rise#event
[
offset=-120,
earliest=“05:30”,
latest=“08:30”
]

// 1 hours before sunrise or no later than 8:30 am or no earlier than 5:30 am for other devices
Type rangeEvent : rise2#event
[
offset=-60,
earliest=“05:30”,
latest=“08:30”
]

or would something like this work?

astro:sun:home2 [ geolocation=“xx, yy”, interval=60 ]

// 2 hours before sunrise or no later than 8:30 am or no earlier than 5:30 am for some devices
{
Channels:
Type rangeEvent : rise#event
[
offset=-120,
earliest=“05:30”,
latest=“08:30”
]

astro:sun:home1 [ geolocation=“xx, yy”, interval=60 ]

// 1 hours before sunrise or no later than 8:30 am or no earlier than 5:30 am for some devices
{
Channels:
Type rangeEvent : rise#event
[
offset=-60,
earliest=“05:30”,
latest=“08:30”
]

Second one should work, different offsets need different things.

Great - this solution works for me too.