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
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.
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
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
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")
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?