Astro binding to move switches at sunset/sunrise

Event offsets are available with this PR

1 Like

I need to download it manually?
Or is automatically when I updated Openhabian?

Is there an example how to use this channel?

Ferry:

After doing a:

sudo apt-get update
sudo apt-get upgrade

Mine appears to be upgrading to the latest snapshot …That is potentially hazardous though, so certainly you would be doing so at your own risk.

All:

How are the offsets used … in the example on github there is something like:

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

Then it says:
Note: Offsets for each event group can be configured in the channel properties

OK … but where … can this be done in the textual configuration files (oh please let it be so) & if so how & what is the syntax?

Is it in the above like (Note the following DOES NOT WORK!)

    Channel 'astro:sun:home:rise#event,offset=-5' triggered START

or something else?

Trying, learning, but running out of brain,
Bruce

Haven’t found out yet how to do it with textual files …

To use the offset, you need the latest snapshot, in beta 5 there are only the events but not the delay included.

To configure a delay, you have to do this with PaperUI on the channel (click the pencil on the right)

But i also don’t know how to configure a channel config via config files. Maybe someone from the openHab experts can tell us.
@Kai any hint for us?

@sihui & @gerrieg :

Thank you! I do (and did) see that in the paper UI. Even so I don’t have an example on how to reference this event vs. the non offset events. Also having a predefined number (there are 13 ?) is probably not the way to go either as I don’t see that working for vast population that we all hope end up using openHAB. It could easily be a limitation of the UI as it stands currently and the devs trying to get something out there that we can use (or more probably I’m just not very smart) but it seems to be a limitation that will bite us sooner rather than later. In any case, thank you for the info. I might set something up with this once I learn more … but I’m really hoping for some textual config. Perhaps Kai will have info along this line – or at least some alternative.

I did just find Defining Channels though and that may be more what I’m looking for.

Always Learning,
Bruce

Great that offsets finally become available. Thanks for your link too, Bruce! Would be great if you can “duplicate” a channel in Paper UI though (and then set properties individually).

In addition to the sample rules I will provide my easy solution for a light which switches on at 6am and goes off a couple of minutes after sunrise completes. If sunrise is already completed by 6am, the light will not go on at all.

import org.joda.time.*
import org.openhab.core.library.types.*

var Timer tMorningLightOff

rule "ruleMorningLightOnAndOff"
when
	Time cron "0 0 6 ? * MON-FRI"
then
	var DateTime dtSunRiseEnd = parse(astroSun1AmsterdamRiseEndDateTime.state.toString)
	if(now < dtSunRiseEnd){
		sendCommand(hueMediumGlobeDimmer, 30)
		tMorningLightOff = createTimer(dtSunRiseEnd.plusMinutes(15)) [|
			sendCommand(hueMediumGlobeDimmer, 0)
		]
	}
end
1 Like

In an attempt to solve this problem in a way that I actually understand, I thought, I know … I’ll just be create multiple locations that I can reference all along the same latitude. If the longitude that I reference is 15 degrees apart from my own, then the sunset times of the other location will be an hour different (360 degrees / 24hrs per day = 15 degrees per hour).

Warning (Danger Danger) - The below is not tested as of this post! Use at your own risk.

So in my things file (sanitized in this example below for my protection) I now have:

astro:sun:home [ geolocation=“45.000000,-80.000000”, interval=60 ]
astro:moon:home [ geolocation=“42.000000,-80.000000”, interval=60 ]


astro:sun:minus60 [ geolocation=“42.000000,-65.000000”, interval=60 ]
astro:sun:minus45 [ geolocation=“42.000000,-68.750000”, interval=60 ]
astro:sun:minus30 [ geolocation=“42.000000,-72.500000”, interval=60 ]
astro:sun:minus07 [ geolocation=“42.000000,-78.250000”, interval=60 ]
astro:sun:minus05 [ geolocation=“42.000000,-78.750000”, interval=60 ]
astro:sun:plus01 [ geolocation=“42.000000,-80.250000”, interval=60 ]
astro:sun:plus05 [ geolocation=“42.000000,-81.250000”, interval=60 ]
astro:sun:plus10 [ geolocation=“42.000000,-82.500000”, interval=60 ]

Then if I want to turn on a light, say 60 mins before sunset I can simply:

//  Stairwell Lights On at Sunset - 1 hour.
rule "Stairwell Lights On - Sunset - 1 hour"
when
    Channel 'astro:sun:minus60:set#event' triggered START    
then
    sendCommand(swStairway, ON)
end

It looks like this should work out well until I can figure out how to do the offsets in a file. In the end I might not want them there but I don’t understand how to use them as they are - or even how to reference them if I define them.

Bruce

3 Likes

How are you differentiating whether this is minus 60 from sunrise or sunset?

It’s the sunset in this case, otherwise it would be

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

That’s a very clever hack! Will try this for my event to switch on the living lights 30 minutes before sunset.

1 Like

Ugh… sorry. Kind of obvious. Chalk it up to reading too quickly.

I just took advantage of the civil dawn/dusk and applied the offset there. Not perfect but close enough for the shift I was trying to achieve.

Yep … that’s another way!

I was finally able to set the offset by configuration in the thing configuration. Works with the latest build.

Try this …

Thing astro:sun:local   [ geolocation="xx.xx,yy.yyy", interval=300] {
    Channels:
        Trigger String : rise#event [
            offset=-30
        ]
}

You can verify the value in the Paper UI

3 Likes

Hello!
And if you need 2 different offsets for one event?

AFAIK this isn’t possible. Not via Paper UI and config files.

Hey @itheiss, that’s great! Would you care to post your answer here https://github.com/openhab/openhab2-addons/pull/1616#issuecomment-271875994 and additionally create a Pull Request for the README.md, the document behind the docs.openhab.org article?

So I’ve done the above and initially I got an exception in my logs. Touching the file fixed that and now I see a new Channel in PaperUI that wasn’t there before:

And my Thing definition:

astro:sun:home    [ geolocation="XX.XXXXXX,-XXX.XXXXXX", interval=60 ] {
	Channels:
	Trigger String : set#event [
		offset=-90
	]
}

Are you seeing the same?

I’ll find out this evening if it works or not despite these oddities. For now I’ve bound my Item to set#event but wonder if just set is the right one.

Thanks for figuring this out!