about the rule setting, i have a sensor device and want to trigger when the state value “is less than” or “is greater than” etc. it work when one sensor device, but have one problem i don’t know how to setup, it about the below:
- item event: sensor: was updated : state = any
- item event: switch: was updated : state = any
- item condition: sensor: state is greater than 200
- do anything
in this situation, i want to when sensor trigger , it will checking the condition but when switch trigger. i want to it can ignore the condition checking.
i create the rule via openhab api but it cannot pass the script as element.
have any idea? or only separate two rule or using script to control?
I would use the sensor and switch (state change to any) as trigger for the rule and then check the condition with a script like that. Command will only be send if the value of sensor is greater than 200 OR the switch is turned on (in my example).
You’ll need to use a Script Condition and in there write code (can be Blockly) to check which Item triggered the rule and take the appropriate action. You can’t use a simple condition for this though, it has to be a script.
That’s probably a more complicated way to go about it, not to mention that there is duplicate code. In OP’s case I suspect it’s more than just sending one command to one Item.
Using a Script Condition you’d have something like this (as JS Scripting):
(event.triggeringItemName == "sensor" && parseFloat(event.newState.toString()) > 200)
|| event.triggeringItemName == "switch"
Then in the rule action you know that the rule was either triggered because the sensor changed to a value above 200 or by the switch and don’t have to mess with that in the rule action.
Separating the conditions from the actions can greatly simplify the code of both.
ok, i see. thanks you for help.
it look like can not use rule setup to solve, i will follow using script to solve the problem.
thanks you for your suggestion.
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.