Astro binding to move switches at sunset/sunrise

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:

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

Maybe i’m dumb but I remember I copied from the documentation few weeks ago.
I will see tomorrow if it works.

As usually, thanks so much Sihui for the support.

I don’t think so :slight_smile:
As far as I remember they have been in the docs all the time (I copied them too from that place).

Tried again, but no result. This is the rule:

rule "ImpostaNotte"
when
	Channel 'astro:sun:local:set#event'	triggered START
then
	sendCommand(Notte, ON)
end

The string astro:sun:local:rise#event has been copied from paperUI things page, so I suppose it is correct.

Okay, then we have to dig a little deeper:

  1. Check if you have the correct thing:
    In PaperUI, you should see a channel astro:sun:local:set#start
    If you see astro:sun:home:set#start, you need to change your rule to
    Channel 'astro:sun:home:set#event' triggered START

  2. add a loginfo to your rule:

    rule "ImpostaNotte"
    when
    Channel ‘astro:sun:local:set#event’ triggered START
    then
    logInfo(“FILE”,“Sunset event has been triggered”)
    sendCommand(Notte, ON)
    end

(Don’t forget to use the correct name local or home according to your defined thing)

Then take a look in to your openhab.log if it says “Sunset event has been triggered”.
If this is the case your switch definition may be wrong (you could try using Notte.sendCommand(ON)

What do you want to say with this?

If you meant me:
that the name of the channel definition has to match the name of the trigger definition.

Example:

Channel:

astro:sun:local:set#start

rule trigger:

Channel ‘astro:sun:local:set#event’ triggered START

I confirm that the rule was correct, but it started working after the installation of snapshot on 5th february

1 Like

@sihui
Sorry about that. Indeed my question was for you. I didn’t understand what you were trying to explane.
But now it’s all clear to me.
Thanks

Hi, I am trying to get something similar done: 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:local:set#event' triggered START
then
    sendCommand(nightTime, ON)
    sendCommand(dayTime, OFF)
end

It doesn’t seem to work though. The switches never change their states. Where is the error? And are these the right channels for my needs?
I am using openhab version 4.0.8 and the version of astro that gets installed via the paperUI.