tjarco
(tjarco Boerkoel)
May 9, 2022, 6:13am
1
Hi,
I’m using OH3.1 on win2019 server and can’t get the rules “but only if” section to work.
I have some trigger condition for lights (when updated item[‘dark’] == on),
and the ‘but only if’ when an switch item != “On” within a script .
I can trigger the rule manually but it doesn matter if I put in the script any of the following code lines:
(false == true)
Or
("ON" == "OFF")
Or
(false)
Or
return false;
It’s always evaluated as true, the rule is always executed when I start a manual rule trigger
Someone an idea?
Can you show us the whole rule? Is this UI or file? What language?
bastler
(stefan)
May 9, 2022, 6:34am
3
would be much easier to help if you post the rule. i suppose DSL?
the perhaps try not to put the ON
in quotations, like:
if (youritem.state == ON){
....
tjarco
(tjarco Boerkoel)
May 9, 2022, 7:14am
4
I notice that the “run script” button doesn’t take the “but only if” condition.
I’ve set a cron timer job to trigger the rule every minute and I’m able to block or allow the rule by using only a “false” or a “true” in the ‘but only if’ condition.
But when I’m making things more complex, there’s not action.
This is the “but only if” content for emacs script:
( (items["LGweb_Power"] == "ON") | (items["Sleeptime"] != "ON") )
first equation is false, second condition is true, so it should run every minute (but doesn’t). Or should it ‘return’?
Complete rule:
triggers:
- id: "1"
configuration:
time: 06:03
type: timer.TimeOfDayTrigger
- id: "5"
configuration:
itemName: Donker
state: ON
type: core.ItemStateUpdateTrigger
- id: "8"
configuration:
cronExpression: 0 * * * * ? *
type: timer.GenericCronTrigger
conditions:
- inputs: {}
id: "6"
configuration:
type: application/javascript
script: ( (items["LGweb_Power"] == "ON") | (items["Sleeptime"] != "ON") )
type: script.ScriptCondition
actions:
- inputs: {}
id: "2"
configuration:
itemName: LightsOnCondition
command: ON
type: core.ItemCommandAction
- inputs: {}
id: "4"
configuration:
itemName: Night
command: ON
type: core.ItemCommandAction
- inputs: {}
id: "9"
configuration:
itemName: Lighting_long
command: ON
type: core.ItemCommandAction
- inputs: {}
id: "10"
configuration:
itemName: Lighting
command: ON
type: core.ItemCommandAction
- inputs: {}
id: "11"
configuration:
icon: Light
severity: Warn
message: Triggered rule lights on
type: notification.SendExtendedBroadcastNotification
tjarco
(tjarco Boerkoel)
May 9, 2022, 7:31am
5
Found it!
The OR statement was made by ‘|’, but must be a double pipe for JavaScript ‘||’.
And now it works!