I am new here and have Problems with the button. I have a hard time to switch on or off the light. The button is doing what he want’s to do.
I think The button has to be debounced. And the LED should have a state (on|off)
Here is my script.
hope someone can help me.
(I understand German too)
var Lichtstatus = 0
rule "Lichtschalter an"
when
Item button1 changed
then
if (channel1.state == OFF && Lichtstatus == 0){
channel1.sendCommand(ON)
Lichtstatus = 1
}
end
rule "Lichtschalter aus"
when
Item button1 changed
then
if(channel1.state == ON && Lichtstatus == 1){
channel1.sendCommand(OFF)
Lichtstatus = 0
}
end
I have not used the GPIO binding, so I have no experience with this, but according to the documentation (and your items configuration), the input pin that is connected to your button is already “debounced”, i.e. the debouning is taken care of by the binding. You may need to play around with different debounce intervals, though.
I think your problem is more with your rules than with the debounce (or lack thereof).
I am going to assume that your “physical button” is a momentary switch (i.e. a switch with only one stable position). Let’s assume the switch is OPEN when at rest. When you press it, it goes to CLOSED - and then “automatically” moves back to OPEN when you let go.
This means that for any button press (including the “let go”-part) you have two state changes, and your rule triggers on both. I think you should start by changing your rule to only trigger on one of these (that would normally be the “press”-part, i.e. you ignore the “let go”-part).
Try to change the rule trigger of the last rule you published to the following:
when
Item button1 changed to CLOSED
then
(and remove the return statements and the Thread:sleep())
rule "Switch pressed"
when
Item Group_LightSwitches changed from OPEN to CLOSED
then
//received update
Thread::sleep(5) // cant remember why i did this.....
Presence_Home.sendCommand(ON) // If someone pressed a switch someone needs to be home right??
// Some error checking just in case....
val changedSwitch = Group_LightSwitches.members.filter[switchPressed | switchPressed.lastUpdate != null].sortBy[lastUpdate].last
if(changedSwitch == null) logWarn("FILE", "Something is amiss, no Item has a valid lastUpdate!")
val sceneItemTemp = changedSwitch.name.toUpperCase().replace("CONTACT","SCENE") as String
val sceneItem = Group_RoomScenes.members.findFirst[roomName | sceneItemTemp.contains(roomName.name.toUpperCase())] as NumberItem
logInfo("Light switch", "Scene is now " + sceneItem)
if (sceneItem!=null){
if(sceneItem.state == 0){
if (vTimeOfDay.state.toString.contains("NIGHT")){
sceneItem.sendCommand(2)
}
else{
sceneItem.sendCommand(1)
}
}
else {
sceneItem.sendCommand(0)
}
}
end
Dear Openhab community
Thank you for the quick answers, your effort and sharing your knowledge with me.
I did it like Kjetil Asdal said it. The main problem was that I did not use “changed to CLOSED”.
I removed the status variable because it blocked the switch in the basicui.
Thanks for the many thoughts in my troubleshooting
rule "Lichtschalter An"
when
Item button1 changed to CLOSED
then
if (channel1.state ==OFF){
channel1.sendCommand(ON)}
end
rule "Lichtschalter Aus"
when
Item button1 changed to CLOSED
then
if (channel1.state ==ON){
channel1.sendCommand(OFF)}
end