Logical AND in rules

Hello. I create rules in dsl and use logical AND, but it doesn’t work. Example of my rule
if(bedroom_night_light_power.state==ON && blink.state==OFF ){
bedroom_night_light_brightness.sendCommand(100)
}
else if(bedroom_night_light_power.state==OFF && blink.state==OFF){
bedroom_night_light_brightness.sendCommand(0)
}
I use OH3

Did you try ’ON’ and ’OFF’?

Well, neither ’ nor " should be needed here.
But anyway I would recommend to make a more clear code:

if(blink.state == OFF) {
    if(bedroom_night_light_power.state == ON) {
        bedroom_night_light_brightness.sendCommand(100)
    } else if(bedroom_night_light_power.state == OFF) {
        bedroom_night_light_brightness.sendCommand(0)
    }
}

In fact, this code could be much shorter:

if(blink.state == OFF) 
    bedroom_night_light_brightness.sendCommand(if(bedroom_night_light_power.state != ON) 0 else 100)

Of course, the result is slightly different, as this rule will also set the light to 0 when bedroom_night_light_power.state is neither ON nor OFF.

Meantime, && is correct for logical AND in a rules if()
Most likely the Item states are not quite what you expected.

1 Like

thank you it works)))

I know) I showed simple rule, that it was easier to understand