Invalid Trigger Definition for Astro Channel Item

  • Platform Information
  • Hardware: Raspberry Pi 3B+
  • OS: Raspberry Pi OS (32 Bit - Buster)
  • Java Runtime Environment:
  • openjdk version “1.8.0_152”
  • OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
  • OpenJDK Client VM (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 25.152-b76, mixed mode, Evaluation)
  • Jython 2.7.0
  • openHAB 2.5.5 (Release Build)

Hello Community,

I’m migrating my rules to the NGRE, and I ran across across a warning that the rule was not created due to an invalid trigger definition. Can anyone tell me why the trigger definition is invalid? For reference, I’ve listed the original (and now archived) Rules DSL rule as well.

Warning

2020-06-08 20:39:57.044 [WARN ] [jsr223.jython.core.triggers         ] - when: "Channel astro:sun:local:civilDusk#start triggered START" could not be parsed because Channel "astro:sun:local:civilDusk#start" is not a trigger
2020-06-08 20:39:57.050 [WARN ] [jsr223.jython.core.rules            ] - rule: not creating rule [Front Porch Lights On at Civil Dusk] due to an invalid trigger definition

Items

DateTime    Civil_Dusk_Start_Time    "Civil Dawn Start Time [%1$tH:%1$tM]"    { channel="astro:sun:local:civilDusk#start" }
Switch    Front_Porch_Lights    "Front Porch Lights"    <switch>    (gInsteon)    { channel="insteon:device:23F01B:switch" }

NGRE Rule (Python)

from core.rules import rule
from core.triggers import when
from core.actions import ScriptExecution

@rule("Front Porch Lights On at Civil Dusk")
@when("Channel astro:sun:local:civilDusk#start triggered START")
def front_porch_lights_on_at_civil_dusk(event):
    events.sendCommand("Front_Porch_Lights", "ON")
    front_porch_lights_on_at_civil_dusk.log.info("Rule: 'Front Porch Lights On at Civil Dusk' fired.")

Rules DSL Rule // Original Rule (Archived)

rule "Front Porch Off at Dawn"
  when
    Channel 'astro:sun:local:civilDawn#event' triggered START
  then
    Front_Porch_Lights.sendCommand(OFF)
  end

Regards,
Burzin

This is a Trigger Channel.

This is not a Trigger Channel, so the validation fails and the rule is not loaded. The astro binding provides these Trigger Channels…

I attempted to explain the difference in the docs…

https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Triggers.html#channel-event

I’m still missing something. What am I missing?

https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Triggers.html#channel-event says:

Channel triggers allow you to catch events from bindings using Channels. You can find Channel names and events in the documentation for the binding.

Note Only trigger Channels can be used with this trigger, same as in the rules DSL. If not using a trigger Channel, you will receive a validation error when saving the script. The binding documentation will identify which Channels, if any, are trigger Channels.

Python
@when(“Channel CHANNEL:NAME triggered [EVENT]”)

The above seems clear enough, I must not be using a trigger channel defined in the binding. However, the Astro binding list CivilDusk as a trigger channel

https://www.openhab.org/addons/bindings/astro/#trigger-channels says:

Trigger Channels

  • thing sun
    • group rise, set, noon, night, morningNight, astroDawn, nauticDawn, civilDawn, astroDusk, nauticDusk, civilDusk, eveningNight, daylight
      • event START, END

These are the rule Triggers that can be used for the civilDusk Channels…

@when("Channel astro:sun:local:civilDusk#event triggered START")
@when("Channel astro:sun:local:civilDusk#event triggered END")

All of the astro Trigger Channels end with #event.

1 Like

Better to look at it that CivilDusk has a trigger channel, as well as some state channels.

A complete channel definition
astro:sun:local:civilDusk#start
That one is not a trigger channel
astro:sun:local:civilDusk#event
This one is a trigger channel

Thank you @5iver and @rossko57. It makes sense now.

I also have a question on this subject. My rule looks like this:

from core.rules import rule 
from core.triggers import when 
@rule("system_daylight", description="Daylight dummy switch", tags=["system", "daylight"]) 
@when("Channel astro:sun:local:set#event triggered START") 
@when("Channel astro:sun:local:rise#event triggered START") 
def daylight(event): 
     events.sendCommand(daylight, "dummy_daylight" if "rise" in str(event.channel).split(":") else "OFF") 

At event Channel astro:sun:local:set#event triggered START the switch should go to ON, at event Channel astro:sun:local:rise#event triggered START the switch should go to OFF.

I have adopted this rule and adapted it to my needs, but it doesn’t work. I understand the line of code itself, but what i’m missing somehow, where is the switch turned on?

events.sendCommand(daylight, "dummy_daylight" if "rise" in str(event.channel).split(":") else "OFF") 

Many thanks for your help!
Christoph

I have now found the solution in a post from rlkoshak:

This is my working rule:

from core.rules import rule
from core.triggers import when

@rule("system_daylight", description="dummy_switch daylight", tags=["system", "dummy", "daylight"])
@when("Channel astro:sun:local:set#event triggered START")
@when("Channel astro:sun:local:rise#event triggered START")
def daylight(event):
  events.sendCommand("dummy_daylight", "ON" if "rise" in str(event.channel).split(":") else "OFF")

I have to correct myself, unfortunately the rule still doesn’t work. I see the astro-channel trigger in my log-file, but nothing happens after that. @rlkoshak maybe do you have any idea why that could be?

May we see that, for confirmation?

Of course @rossko57 :

2021-07-07 05:27:00.002 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:rise#event triggered START
2021-07-07 21:09:00.005 [INFO ] [openhab.event.ChannelTriggeredEvent ] - astro:sun:local:set#event triggered START

Is there actually a way to manually trigger the channel so that i can test it without waiting for sunrise or sunset?