Who triggers the rule - Can I detect triggering event if the when is "cron" and "channel"?

I have this rule part:

rule "Astro Rollos up"
    when
        Time cron "0 0 9 ? * *" or
        Channel 'astro:sun:Angepasst:rise#event' triggered START
    then

Is there a way to know if cron or the channel has triggered the rule?

I don’t think so,
Anyone else?

You could use two proxy items, one for each event
and then use them to trigger your rules the you can see which item triggered the rule
That means 2 more items and 2 more rules… :rofl:

That is a good question. I’m pretty positive that triggeringItem will be null when the rule triggers with a cron trigger.

I’m less positive that triggeringItem will be null for the channel trigger, but it most likely will be.

I suggest running an experiment. Add a logInfo("test", "triggeringItem is " + triggeringItem). If it says null in both cases then you will know that triggeringItem won’t help you in which case your choices are:

  • take Vincent’s suggestion
  • if(now.isAfter(now.withTimeAtStartOfDay.plusHours(9) && now.isBefore(now.withTimeAtStartOfDay.plusHours(9).plusSeconds(1)) // cron triggered rule

The second requires fewer additions but if by chance the sunrise event occurs between 09:00:00 and 09:00:01 it will think it is is the cron trigger.

Hi Rich.

this is exactly my problem:
“The second requires fewer additions but if by chance the sunrise event occurs between 09:00:00 and 09:00:01 it will think it is is the cron trigger.”

My idea is to monitor a switch which is triggered by a astro rule and check if lastUpdate is younger then 5sec.

rule "Astro Sonnenuntergang erfassen"
    when
        Channel 'astro:sun:Angepasst:set#event' triggered START
    then
        swSonnenaufgangEvent.postUpdate(OFF)
        swSonneuntergangEvent.postUpdate(ON)
end

something like:

       swSonneuntergangEvent.lastUpdate()
or
       swSonneuntergangEvent.updatedSince(now.minusSeconds(5))

I will play with this.

That is functionally the same. If the Astro event and Cron event happens to fall within the five second window it will detect the wrong event.

If my approach won’t work you need to use Vincent’s approach.

Just thinking from the other side: What do you want to achieve with this? perhaps you can just use some channel-definitions and your good already? :wink:
https://docs.openhab.org/addons/bindings/astro/readme.html#channel-config

I thought about this too. I need differnet astro events for workday and other days. Now I implement two astro channels and will see if this work today. I have to wait.

That’ll work! :sunglasses:
If you like your blinds open later at the weekend you could also just add a timer (no thread:sleep! The sleep is only for microseconds).
But with a timer you could open your blinds 30mins/1hour after your configured sunrise:
https://docs.openhab.org/configuration/rules-dsl.html#system-based-triggers

See the example