rule "test1"
when
Item cam1_intrerupator changed
then
if (cam1_sa1.state == ON) {
cam1_sa1.sendCommand(OFF)
}
else if (cam1_sa1.state == OFF) {
cam1_sa1.sendCommand(ON)
}
end
Now…the problem:))
If the light is off and I press on the button, it lights up and remains… if i press press the button to turn off the light, it will not turn off. it will remain off as long as the button is pressed or if I repeatedly pressed on the button (by mistake it goes out)
I really don’t know what to do, i’ve reinstalled the Openhab2 and nothing. I also changed the GPIOs
cam1_intrerupator will change to CLOSED when you push it and OPEN when you release
Change the trigger of your rule to:
rule "test1"
when
Item cam1_intrerupator changed to CLOSED
then
if (cam1_sa1.state == ON) {
cam1_sa1.sendCommand(OFF)
}
else if (cam1_sa1.state == OFF) {
cam1_sa1.sendCommand(ON)
}
end
Now the rule will only trigger when you push the button down. Before, it was also triggering when releasing.
Also I highly recommend that you debounce the switch by editing the file services/gpio.cfg
as such:
same thing…
i’ve seen in the log that the OH2 is running twice the rule.
//After i saved the “home.rules”
2018-11-04 21:08:47.720 [vent.ItemStateChangedEvent] - buc1_intrerupator changed from UNDEF to OPEN
2018-11-04 21:08:47.724 [ome.event.ItemCommandEvent] - Item ‘cam1_sa1’ received command ON
//After i pushed the button once.
2018-11-04 21:09:56.902 [vent.ItemStateChangedEvent] - buc1_intrerupator changed from OPEN to CLOSED
2018-11-04 21:09:56.911 [ome.event.ItemCommandEvent] - Item ‘cam1_sa1’ received command OFF
2018-11-04 21:09:56.922 [vent.ItemStateChangedEvent] - cam1_sa1 changed from ON to OFF
2018-11-04 21:09:57.105 [vent.ItemStateChangedEvent] - buc1_intrerupator changed from CLOSED to OPEN
2018-11-04 21:09:57.120 [ome.event.ItemCommandEvent] - Item ‘cam1_sa1’ received command ON
2018-11-04 21:09:57.132 [vent.ItemStateChangedEvent] - cam1_sa1 changed from OFF to ON
I didn’t had the services/gpio.cfg, i need to have something else on that file beside the debounce=10? I don’t know, some things that needs to be there?
Only use === when null is on one side of the comparison. In all other cases, including NULL you must use ==. The two behave differently and if you use === in some cases you will get the wrong answer.
For example.
val Number testNum = 20
// Lets assume Item Temperature is set to 20
if(Temperature.state === null) // correct answer
if(Temperature.state == null) // potentially can cause an exception
if(Temperature.state === testNum) // incorrect answer, will return false
if(Temperature.state == testNum) // correct answer