Astro binding to move switches at sunset/sunrise

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!

Hi,

looks like you are not using recent enough build. You have to install a snapshot which includes this pull request https://github.com/eclipse/smarthome/pull/2762.

And it seems I made a mistake with the channel type. According to sjka https://github.com/eclipse/smarthome/pull/2762#issuecomment-272096368 it must look like:

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

Have to till sun rise and watch the logs from remote :smile:

OK, I’ll probably have to wait a couple of days for that PR to filter down to the Docker image on DockerHub. Now that the Docker image build is working again it should not be long. Thanks!

Sergey:

I’m probably telling you something you already know, but if you take @itheiss example (slightly modified by me and therefor probably wrong) and then also duplicate it as below … you could do:

// 30 mins prior to sunsest
Thing astro:sun:homeMinus30   [ geolocation="xx.xx,yy.yyy", interval=60] {
    Channels:
        Type rangeEvent : set#event [
            offset=-30
        ]
}

// 45 mins prior to sunsest
Thing astro:sun:homeMinus45   [ geolocation="xx.xx,yy.yyy", interval=60] {
    Channels:
        Type rangeEvent : set#event [
            offset=-45
        ]
}

That should work for that … now for my soapbox …
All this “Thing” generation seems repetitive and resource intensive (it’s not like your going to need a trigger to occur on the nautical sunrise minus 30 mins on every additional astro thing you create). – Kind of going off the tracks here to possible system changes … and … Maybe should bring in @ThomDietrich here.) I think that we need some way to DEFINE a new range event (trigger channel?) at least in this example, based on an existing thing(s) above but possibly modified with parameters as in

NOT A WORKING EXAMPLE

// 30 & 45 mins prior to sunsest
Thing astro:sun:home   [ geolocation="xx.xx,yy.yyy", interval=60] {
    Channels:
        Type rangeEvent : set#event : minus30 [
            offset=-30
        ]
        Type rangeEvent : set#event : minus45 [
            offset=-45
        ]
}

END OF NOT A WORKING EXAMPLE

Where the “minus30” entry and the “minus45” in the above gets added to the list of available triggers (trigger channels?). Enter as many different ones as you would want. The good news is that more items that you don’t need aren’t added like they are when you define and entirely new astro ‘thing’. Then maybe one could reference it as in:

YET ANOTHER NON-WORKING EXAMPLE

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

END OF YET ANOTHER NON-WORKING EXAMPLE

as the "#minus30 is simply added to the channel?

Thoughts? Maybe I should put this somewhere else? Am I missing something? Is this information anyone would want?

1 Like