- Platform information:
- Hardware: Raspi 4
- OS: Linux openhabian 5.10.63-v7l+ #1496 SMP Wed Dec 1 15:58:56 GMT 2021 armv7l
- openHAB version: 3.2
- add-ons: only “JSScripting” installed, no Groovy or JRuby
- upgraded with openhabian-config - upgrade
Hi all
with the help of this forum I could always solve my problems in the past and so I ask for help with the following very simple rule which I want to transfer from DSL to JScripting.
Item Definition:
Number:Power SchalterWZHifiPower “Power” {channel=“tplinksmarthome:hs110:1825AF:power”}
The old rule in DSL looks like this:
rule “Power Check”
when
Item SchalterWZHifiPower changed
then
if(SchalterWZHifiPower.state < 20|“W”)
Fernseh_OpState.postUpdate(0)
else Fernseh_OpState.postUpdate(2)
end
The new one looks like that, but of course it is not running as expected:
var opstate = items.getItem(“Fernseh_OpState”);
var runtime = (typeof(require) === “function”) ? require("@runtime") : {
events: events,
items: items,
};
if(runtime.items[“SchalterWZHifiPower”].state < “20|W”){
console.log(“Power below 20 W”)
//Post an update
opstate.postUpdate(0);
} else {
console.log(“Power above 20 W”)
opstate.postUpdate(2);
}
If I run the rule the result is like this:
2022-01-06 09:58:11.528 [WARN ] [le.handler.ItemStateConditionHandler] - Received a QuantityType state ‘8.648 W’ with unit for item SchalterWZHifiPower, but the condition is defined as a plain number without unit (20), please consider adding a unit to the condition.
2022-01-06 09:58:11.632 [INFO ] [org.openhab.automation.script ] - Power above 20 W
2022-01-06 09:58:11.636 [DEBUG] [org.openhab.automation.script.items ] - Posted update 2 to Fernseh_OpState
Based on the error / warning I can see two problems:
- the condition seems to be defined as a plain number, which I do not understand since I added the
< 20|“W”)
condition - the rule itself does not work, the postupdate will always “2”
Thank you for your effort to point me into the right direction.
best regards
Marcus