IF Statement in .rules

Hi ,

I have this setup

.things file

Thing network:pingdevice:Pc1_170 [ hostname="", retry=1, timeout=3000, refreshInterval=6000 ]
Thing network:pingdevice:Pc2_171 [ hostname="", retry=1, timeout=3000, refreshInterval=6000 ]
Thing network:pingdevice:Pc3_172 [ hostname="", retry=1, timeout=3000, refreshInterval=6000 ]


Switch Ping_PC1 "Ping PC1" <switch> ["Switchable"]  { channel="network:pingdevice:Pc1_170:online" }   
Switch Ping_PC2 "Ping PC2" <switch> ["Switchable"]  { channel="network:pingdevice:Pc2_171:online" }   
Switch Ping_PC3 "Ping PC3" <switch> ["Switchable"]  { channel="network:pingdevice:Pc3_172:online" }  


if ( Ping_PC1.state == OFF )  { 
sendCommand(Pc1, OFF)  
sendCommand(Mon_1, OFF) } 

any Idea whats wrong, please ? it dose not run

rule "Ping PC1"
    Item Ping_PC1 changed to OFF
    sendCommand(Pc1, OFF)
    sendCommand(Mon_1, OFF)
1 Like

Obligatory RTFM! :slight_smile:

1 Like

Hi Thanks for the prompt reply :slight_smile:

Ok it’s my fault cos I didn’t exactly copy/paste the rules file I will this time :slight_smile:
i don’t want to switch off exactly when there is no ping cos that will create other
problems . I want to switch the PC & monitor off if there is no ping and when I am switching everything OFF.

rule "Auto_OFF" when  

        Item Pir_Stat changed from ON to OFF  then  
        Led_B1.sendCommand(0) Led_B2.sendCommand(0) Led_B3.sendCommand(0) Led_B4.sendCommand(0) 
        Gl1_1.sendCommand(0)  Gl1_2.sendCommand(0)  Gl1_3.sendCommand(0)  Gl2_1.sendCommand(0)
        Gl2_2.sendCommand(0) Gl2_3.sendCommand(0) Gl2_4.sendCommand(0) 
        sendCommand(Psu_1, OFF)  sendCommand(Psu_2, OFF)  sendCommand(Psu_3, OFF)

        sendCommand(Ce_Fan1, OFF)  sendCommand(Ce_Fan2, OFF)  sendCommand(Es30_1, OFF)
        sendCommand(Es30_1, OFF)  sendCommand(Es30_2, OFF)    sendCommand(Es30_3, OFF)
        sendCommand(Audio, OFF)  sendCommand(Sldr_1, OFF)    sendCommand(Iso_Trf, OFF)
        sendCommand(Tv, OFF)  T_Ext.sendCommand(35)

        if ( Ping_PC1.state == OFF )  { sendCommand(Pc1, OFF)  sendCommand(Mon_1, OFF) }  end
       // if ( Ping_PC2.state  != "ON" &&  Ping_PC3.state  != "ON" )  { sendCommand(W_Plugs, OFF) }  end

So my question is, is it posible to check a switch state with if statement in the .rules file ?

1 Like


If things are not working as you expect, you might have to give a bit more detail about what does happen.

It’s a bit unclear with that formatting, but your rule seems to have two end statements. I’d expect that you’d see an error report if you look in your openhab.log at rules file load time.

1 Like

That was it, the if the statement does not have an end
that’s an absolute beginner fault :slight_smile:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.