Beginner, rule, if

Hi every, I am super new to openHAB, using openhabian running openHAB2. So far I was able to figure out everything by myself but now I am stuck at what actually should be an easy rule.
I have a TV (sTV) on a Z-Wave switch and a Light (dBedRoom) hooked up to a Z-Wave dimmer. Furthermore Kodi runs on another Raspberry 3 and I am able to control all instances through openHAB user interface.

I was able to write a rule to dim the light when Kodi receives a “play” command. I wanted to take it a step further and dim the light ONLY while the TV is on. At the same time the light (if greater than 50 percent) should be dimmed to 50 (percent) and 5 seconds later dimmed to 30. If the light is less than 50 percent, it should be dimmed right away to 30 percent. If the TV is is off, the light should not be dimmed at all.
Here are my items:

Group gTV
Switch sTV { channel="zwave:device:KODI:node3:switch_binary" }

Group gLights
Dimmer dBedRoom "Bed room" <dimmablelight-0> (gLights) { channel="zwave:device:KODI:node2:switch_dimmer" }

Group gKodi
Dimmer dKodi_volume { channel="kodi:kodi:541e3ac6-73a9-8f84-907b-93e89b633469:volume" }
Switch sKodi_mute { channel="kodi:kodi:541e3ac6-73a9-8f84-907b-93e89b633469:mute" }
Player dKodi_player "Control" <movecontrol>{ channel="kodi:kodi:541e3ac6-73a9-8f84-907b-93e89b633469:control" }
String sKodi_title { channel="kodi:kodi:541e3ac6-73a9-8f84-907b-93e89b633469:title" }


Here is my rule:

rule    "kodi play"

when
        Item dKodi_player changed from PAUSE to PLAY
then
        if(sTV==ON){
                if(dBedRoom > 50) {
                        sendCommand(dBedRoom, 50)
                        Thread::sleep(5000)
                        sendCommand(dBedRoom, 30)
                }
                else {
                        sendCommand(dBedRoom, 30)
                }
        }
end

Can anybody point me into the right direction?

You don’t say what went wrong, if you haven’t yet found how to check OH logs for error mesages now is the time.
But you probably want to check the .state of your Items in the if().

1 Like

here’s a line from one of rules showing syntax and use of .state

if ((DO_42_24.state==OPEN) && (DO_42_25.state==OPEN) ) {AlarmS1.sendCommand(0.0)}

Thank you, guys.
I modified Wayne´s rule to my needs and booom, it worked!

if ((sTV.state==ON) && (dBedRoom.state > 50) ) {dBedRoom.sendCommand(0.0)}

Thank you again!

1 Like