I am about to get rid of my calls to Astro action from jython scripts. My need is that I can query the value of astro event times (like sunset start). But I also wants to get notified when the event actually occurs.
To fullfil the above I created a module that can publish (astro) events to different subscribers. That all seems to work great when I use a combination of a item and a ChannelEvent trigger.
I also wanted to have a trigger at a specific time each day. So I just enhanced the above with a CronTrigger option. So far everything is still great…
The problem arises when I get a CronEvent. For ChannelEvents I get an event object in the callback and thus I can nicely backtrack to the channel that caused the event to trigger, and publish a notification to all subscribers to that event. For CronTriggers this object is not set, so I don’t really know what Crontrigger that caused the event (assuming that there can be more). I tried to set the triggername, but that doesn’t seem to work.
Is there a way to get the link between the cronevent that triggered the call, so that I can backtrace. Maybe I can set some metadata that will be returned in call.
I can always create a list/dictionary of CronTriggers and then loop through this list to identify the one that triggered the event. Any better suggestions?
BTW. I am using the new Rule Binding
UPDATE: The above problem seems to be somewhat related to this post:
In my ephem_tod script which does pretty much exactly what you describe, instead of using cron triggers, I use Items.
I have a script that can be used to initialize Items with a DateTime used to boot strap the time for the Items that are replacing the cron triggers. The Astro Items of course are linked to Astro Channels. The rule then generates Timers to generate an event at the right times.
I’m not an expert but I believe the lack of which cron trigger caused the rule to trigger in event is either because of limitations in the underlying rules engine or by design.
You are probably right, but when having more Cron triggers, where it matters if it is trigger 1 or trigger2, then it would be nice to know the trigger name or other metadata
But I think Rich has pointed me in a usefull direction
I have now cerated a pull request to the opehab-helper library with a new library called Event Manager. It solves the above as well as it also offers (yet another) TimeOfDay mechanishm. It build as a Publish/Subscriber DesignPattern, where you define your events in the configuration and then from python cxan subscribe to an event (both Astro and Cron is possible).
If anybody wants to try it the code can be found here: