[HABApp] different trigger times for dusk event in habapp and astro binding

  • Platform information:
    • Hardware: RPi 4B, 4 Gb
    • OS: openhabian 4.0.1
  • Issue of the topic: dusk event triggers different in HABApp and astro binding

i created a habapp rule to close my shutters at sun dusk. actually i use the astro binding, i have defined an item

DateTime    iRolloJaloZu         "Rollos/Jalos schließen um[%1$tH:%1$tM Uhr]"             <shutter>   { channel="astro:sun:local:nauticDusk#start" }

and this item i display in sitemap to know when shutters will close.

in habapp i use this listener to start my rule

        self.listen_event('astro:sun:local:nauticDusk#event', self.check_evening_close,
                          EventFilter(ChannelTriggeredEvent, event='START'))

and this works well.

now i found out that in habapp there is an easier way for the listener:


but this triggers about 5 minutes later then the astro trigger.

i checked the location in habapp config.yml is the same values as in astro.things (lat, long and elev)

i saw in astro i can trigger not only nauticDusk but also civilDusk and astroDusk but there the time differs even more.

triggering 5 minutes later would not be a problem for me, but with the trigger .run.on_sun_dusk i dont know how i could get the time to be able to display it in the sitemap.

perhaps somebody has an idea for me, thanks!

You can register a callback that gets called every time the time changes (and returns the new time which is used by the scheduler).
This is done through job in this example.
You can also set an earliest or latest time which I find very handy

from datetime import datetime
from HABApp import Rule
from HABApp.openhab.items import DatetimeItem

class MyRule(Rule):
    def __init__(self):

        job = self.run.on_sun_dusk(self.check_evening_close)
        self.item_dusk = DatetimeItem.get_item('MyDuskItem')

    def dusk_time_changed(self, dt: datetime):
        return dt
1 Like

amazing, that code looks very nice and works perfect for me, thank you @Spaceman_Spiff i like habapp :+1:

1 Like

FYI here are the docs for the Job

1 Like

Small improvement that will return the new date every time (recommended)

    def dusk_time_changed(self, dt: datetime):
        except Exception:
        return dt
1 Like