Rule to switch on or of a lamp

  • Platform information: Openhab2.3
    • Hardware: RasberryPI
    • OS: _openhabian
    • Issue of the topic: please be detailed explaining your issue

Dear all,

I started to learn making rules in openhab. So i’m trying to make my first rule. I simpleone to switchon en off a lamp by a contact sensor and a if-if rule. unfortunately it doesn’t work. I tried to figger out the problem and tried a lot of combinations, but i failed :frowning: hopefully some of you can give me a tip. Below you will find my code.

//bureaulamp
rule "bureaulamp aan1"
when
    Item GF_Bathroom_door_contact changed
then
    if (GF_Bathroom_door_contact==CLOSED) {
        FF_Woonkamer_Light_burolampjantine.sendCommand(OFF)
        }
    if (GF_Bathroom_door_contact==OPEN) {
        FF_Woonkamer_Light_burolampjantine.sendCommand(ON)
    }
end

Thanks,
Jantine

1 Like

Change the if statements to:

if (GF_Bathroom_door_contact.state == CLOSED) {

If still having issues please post your items file and what errors are showing in the logs.

Yess the ‘.state’ was indeed the problem. So verry much thanks!

I don’t see an item for GF_Bathroom_door_contact but try adjusting the rule like suggested above e.g.

//bureaulamp
rule "bureaulamp aan1"
when
    Item GF_Bathroom_door_contact changed
then
    if (GF_Bathroom_door_contact.state == CLOSED) {
        FF_Woonkamer_Light_burolampjantine.sendCommand(OFF)
        }
    if (GF_Bathroom_door_contact.state == OPEN) {
        FF_Woonkamer_Light_burolampjantine.sendCommand(ON)
    }
end