Astro binding to move switches at sunset/sunrise

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!

Itā€™s not a bug, just a missing feature :slight_smile:

If you need in addition to the trigger the DateTime, go with

works like a charme.

Thanks @sihui, but Iā€™ll stick with the OH1 binding until itā€™s added.

Then I guess you have to open a feature request:

https://github.com/openhab/openhab2-addons/issues

I have the stable release of Openhab2 and my rule still doesnā€™t work. Can someone confirm if the trigger

when
	Channel astro:sun:local:set#event triggered START
then

is still unavailable?

You are missing the apostropheā€™s:

when
	Channel 'astro:sun:local:set#event' triggered START
then