Astro binding to move switches at sunset/sunrise

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

Hi Bruce,
I also came to this embodiment, but it seems to me curve :frowning:

something like that would be good!

1 Like

Ingo, did you or @rlkoshak ever get this to work in text files?

I’ve got things:

astro:sun:home          [ geolocation="xx.xx,yy.yy", interval=60 ]
astro:moon:home         [ geolocation="xx.xx,yy.yy", interval=60 ]

Thing astro:sun:homeMinus60   [ geolocation="xx.xx,yy.yy", interval=60 ] {
    Channels:
        Type rangeEvent : set#event [
            offset=-60
        ]
}

And Items:

DateTime Sunrise_Time  "Sunrise [%1$tH:%1$tM]"  { channel="astro:sun:home:rise#start" }
DateTime Sunset_Time   "Sunset [%1$tH:%1$tM]"   { channel="astro:sun:home:set#start" }

DateTime Sunrise_Time_Ex  "Sunrise_Ex [%1$tH:%1$tM]"  { channel="astro:sun:homeMinus60:rise#start" }
DateTime Sunset_Time_Ex   "Sunset_Ex [%1$tH:%1$tM]"   { channel="astro:sun:homeMinus60:set#start" }

Sitemap:

	Frame label="Bunch of Display Items"  {
		Text label="All Items" icon="none"  {
			Frame label="Display"  {
				Text item=Sunrise_Time 				
				Text item=Sunset_Time 				
				Text item=Sunrise_Time_Ex
				Text item=Sunset_Time_Ex
                        }
                }
        }

When saving the Things, in the log I get:

2017-01-25 21:39:35.361 [temChannelLinkRemovedEvent] - Link 'Sunset_Time => astro:sun:home:set#start' has been removed.
2017-01-25 21:39:35.368 [temChannelLinkRemovedEvent] - Link 'Sunrise_Time => astro:sun:home:rise#start' has been removed.
2017-01-25 21:39:35.711 [ItemStateChangedEvent     ] - Sunrise_Time changed from NULL to 2017-01-25T06:55:00.000-0600
2017-01-25 21:39:35.716 [ItemAddedEvent            ] - Item 'Sunrise_Time' has been added.
2017-01-25 21:39:35.725 [ItemChannelLinkAddedEvent ] - Link 'Sunrise_Time-astro:sun:home:rise#start' has been added.
2017-01-25 21:39:35.736 [ItemStateChangedEvent     ] - Sunset_Time changed from NULL to 2017-01-25T17:06:00.000-0600
2017-01-25 21:39:35.737 [ItemAddedEvent            ] - Item 'Sunset_Time' has been added.
2017-01-25 21:39:35.747 [ItemChannelLinkAddedEvent ] - Link 'Sunset_Time-astro:sun:home:set#start' has been added.
2017-01-25 21:39:35.786 [ItemStateChangedEvent     ] - Sunrise_Time_Ex changed from NULL to 2017-01-25T06:55:00.000-0600
2017-01-25 21:39:35.804 [ItemAddedEvent            ] - Item 'Sunrise_Time_Ex' has been added.
2017-01-25 21:39:35.815 [ItemStateChangedEvent     ] - Sunrise_Time_Ex changed from NULL to 2017-01-25T06:55:00.000-0600
2017-01-25 21:39:35.821 [ItemChannelLinkAddedEvent ] - Link 'Sunrise_Time_Ex-astro:sun:homeMinus60:rise#start' has been added.
2017-01-25 21:39:35.830 [ItemStateChangedEvent     ] - Sunset_Time_Ex changed from NULL to 2017-01-25T17:06:00.000-0600
2017-01-25 21:39:35.830 [ItemAddedEvent            ] - Item 'Sunset_Time_Ex' has been added.
2017-01-25 21:39:35.838 [ItemChannelLinkAddedEvent ] - Link 'Sunset_Time_Ex-astro:sun:homeMinus60:set#start' has been added.
2017-01-25 21:39:35.841 [ItemRemovedEvent          ] - Item 'Sunrise_Time' has been removed.
2017-01-25 21:39:35.851 [ItemStateChangedEvent     ] - Sunrise_Time changed from NULL to 2017-01-25T06:55:00.000-0600
2017-01-25 21:39:35.854 [ItemRemovedEvent          ] - Item 'Sunset_Time' has been removed.
2017-01-25 21:39:35.865 [ItemStateChangedEvent     ] - Sunset_Time changed from NULL to 2017-01-25T17:06:00.000-0600
2017-01-25 21:39:35.865 [ItemRemovedEvent          ] - Item 'Sunrise_Time_Ex' has been removed.
2017-01-25 21:39:35.874 [ItemRemovedEvent          ] - Item 'Sunset_Time_Ex' has been removed.

But if you look at it … the offset is not used (or perhaps just not placed in the DateTime Item). I have not actually put them in a trigger because I wasn’t getting the right values – maybe that doesn’t matter? Here is the output:

By my way of thinking at least the Sunset_Ex value should be 1 hours less than it is.

Hi,

the offset is working when used within a rule. AFAIK the offset has no impact on the DateTime items, but that’s what you already discovered :slight_smile:

Regards
Ingo

1 Like

I got it to work but I found that if you want to have, for example, an event at Sunset and 90 minutes before Sunset you end up needing two Things anyway so I’ve stuck with the +/-15 degrees per hour trick for now since that was already working for me. I’ll probably go back to using the offsets at some point, but if the offset doesn’t adjust the DateTime Items then that wouldn’t work for me as I need both the events and the DateTimes for both Sunset and Sunset - 90 minutes.

1 Like

Do you know if this is going to get fixed?

Thanks!