hi guys,
while trying to convert some of my rules I’m facing the first problems regarding triggers
…
in Rule DSL I had some channel based rule triggers:
when
Channel "harmonyhub:hub:HarmonyHub:activityStarted" triggered or
Item LightScene received command
I searched for a similar solution in the docs but only found
triggers.ChannelEventTrigger('astro:sun:local:rise#event', 'START')
and
triggers.ItemCommandTrigger('my_item', 'OFF')
the ItemCommand
fires the rule without any argument but the ChannelEventTrigger
not!
here the full script (ECMAScript 262 Edition 11):
const {log, rules, triggers} = require("openhab");
rules.JSRule({
name: "Script - DisplayState",
description: "see if TV is turned on or off",
triggers: [
triggers.ChannelEventTrigger('harmonyhub:hub:HarmonyHub:activityStarted'),
triggers.ItemCommandTrigger('LightScene')
],
execute: data => {
const display = items.getItem("DisplayState");
const harmony = items.getItem("HQHub_CurrentActivity");
console.log("Display", "Rule Activated");
if(harmony.state === "Fernsehen" || harmony.state === "ShieldTV"){
if(display.state !== "ON"){
display.sendCommand("ON");
console.log("Display", "Switching Display State "+display.state);
}
}
if(harmony.state !== "Fernsehen" && harmony.state !== "ShieldTV"){
if(display.state !== "OFF"){
display.sendCommand("OFF");
console.log("Display", "Switching Display State "+display.state);
}
}
},
tags: []
});
Do I really have to add every argument (state) which the channel offers to get the trigger activated?
And another question is, I realized that the rule is only created when I manually run the script after openHAB restarts - this confuses me a bit, is this normal behavior?