GPIO Contacts not updating


(Mike Baker) #1

I have openHAB 2 installed on Raspberry pi 3. I am using it to turn on and off 10 small amplifiers for a whole house audio system I built. I have control of 11 outputs. 10 turning the amps on and off and 1 turns on cooling fans if any of the other 10 are on. This works great using a site map on my cell phone. I also have 10 momentary push buttons wired to 10 GPIO pins. The push buttons allow me to turn on or off each amplifier without my cell phone. I have created rules and this is working with one problem I can’t solve. The GPIO inputs do not always update. The contacts are set up as activelow:yes so the are open and close when the button is pushed and the contact is closed and 3.3V is applied to the GPIO pin. I have 10K pull down resistors installed. The contacts do not update all of the time. I push the button the contact will change from open to closed, when I release the button the contact shows closed and will not update until I push a different push button or the same push button several times. I have tried playing with the debounce with no luck. It seems like the system is not actually reading the state of the input until another input is activated. The system will read a GPIO input as closed with no voltage at the input pin and the pin is grounded to the ground pin.

Items and rule files are below. Any help advice would be great.


//This Is the Items File

Contact button1 "Button 1[%s]" {gpio="pin:17 debounce:5 activelow:yes"}
Contact button2 "Button 2[%s]" {gpio="pin:18 debounce:5 activelow:yes"}
Contact button3 "Button 3[%s]" {gpio="pin:19 debounce:5 activelow:yes"}
Contact button4 "Button 4[%s]" {gpio="pin:20 debounce:5 activelow:yes"}
Contact button5 "Button 5[%s]" {gpio="pin:21 debounce:5 activelow:yes"}
Contact button6 "Button 6[%s]" {gpio="pin:22 debounce:5 activelow:yes"}
Contact button7 "Button 7[%s]" {gpio="pin:23 debounce:5 activelow:yes"}
Contact button8 "Button 8[%s]" {gpio="pin:24 debounce:5 activelow:yes"}
Contact button9 "Button 9[%s]" {gpio="pin:25 debounce:5 activelow:yes"}
Contact button10 "Button 10[%s]" {gpio="pin:26 debounce:5 activelow:yes"}


Switch fan "Fan" {gpio="pin:12 activelow:yes initialValue:high"}
Switch zone1 "Deck Speakers" {gpio="pin:10 activelow:yes initialValue:high"}
Switch zone2 "Hot Tub Speakers" {gpio="pin:11 activelow:yes initialValue:high"}
Switch zone3 "Pool Deck Speakers" {gpio="pin:2 activelow:yes initialValue:high"}
Switch zone4 "Front Porch Speakers" {gpio="pin:3 activelow:yes initialValue:high"}
Switch zone5 "Garage Speakers" {gpio="pin:4 activelow:yes initialValue:high"}
Switch zone6 "Laundry Room Speakers" {gpio="pin:5 activelow:yes initialValue:high"}
Switch zone7 "Kitchen Speakers" {gpio="pin:6 activelow:yes initialValue:high"}
Switch zone8 "Shop Speakers" {gpio="pin:7 activelow:yes initialValue:high"}
Switch zone9 "Master Bedroom Speakers" {gpio="pin:8 activelow:yes initialValue:high"}
Switch zone10 "Master Bathroom Speakers" {gpio="pin:9 activelow:yes initialValue:high"}
//This is the rules file

rule "zone1pb"
when
        Item button1 changed from OPEN to CLOSED
then
        if (zone1.state==OFF)   {
                         zone1.sendCommand(ON)
        } else {
                zone1.sendCommand(OFF)
        }
end

rule "zone2pb"
when
        Item button2 changed from OPEN to CLOSED
then
        if (zone2.state==OFF)   {
                         zone2.sendCommand(ON)
        } else {
                zone2.sendCommand(OFF)
        }
end

rule "zone3pb"
when
        Item button3 changed from OPEN to CLOSED
then
        if (zone3.state==OFF)   {
                         zone3.sendCommand(ON)
        } else {
                zone3.sendCommand(OFF)
        }
end

rule "zone4pb"
when
        Item button4 changed from OPEN to CLOSED
then
        if (zone4.state==OFF)   {
                         zone4.sendCommand(ON)
        } else {
                zone4.sendCommand(OFF)
        }
end

rule "zone5pb"
when
        Item button5 changed from OPEN to CLOSED
then
        if (zone5.state==OFF)   {
                         zone5.sendCommand(ON)
        } else {
                zone5.sendCommand(OFF)
        }
end

rule "zone6pb"
when
        Item button6 changed from OPEN to CLOSED
then
        if (zone6.state==OFF)   {
                         zone6.sendCommand(ON)
        } else {
                zone6.sendCommand(OFF)
        }
end

rule "zone7pb"
when
        Item button7 changed from OPEN to CLOSED
then
        if (zone7.state==OFF)   {
                         zone7.sendCommand(ON)
        } else {
                zone7.sendCommand(OFF)
        }
end

rule "zone8pb"
when
        Item button8 changed from OPEN to CLOSED
then
        if (zone8.state==OFF)   {
                         zone8.sendCommand(ON)
        } else {
                zone8.sendCommand(OFF)
        }
end

rule "zone9pb"
when
        Item button9 changed from OPEN to CLOSED
then
        if (zone9.state==OFF)   {
                         zone9.sendCommand(ON)
        } else {
                zone9.sendCommand(OFF)
        }
end

rule "zone10pb"
when
        Item button10 changed from OPEN to CLOSED
then
        if (zone10.state==OFF)   {
                         zone10.sendCommand(ON)
        } else {
 	   zone10.sendCommand(OFF)
        }
end

rule "fan on"
when
        Item zone1 changed from OFF to ON or
        Item zone2 changed from OFF to ON or
        Item zone3 changed from OFF to ON or
        Item zone4 changed from OFF to ON or
        Item zone5 changed from OFF to ON or
        Item zone6 changed from OFF to ON or
        Item zone7 changed from OFF to ON or
        Item zone8 changed from OFF to ON or
        Item zone9 changed from OFF to ON or
        Item zone10 changed from OFF to ON
then
        fan.sendCommand(ON)
end

rule "fan off"
when
        Item zone1 changed from ON to OFF or
        Item zone2 changed from ON to OFF or
        Item zone3 changed from ON to OFF or
        Item zone4 changed from ON to OFF or
        Item zone5 changed from ON to OFF or
        Item zone6 changed from ON to OFF or
        Item zone7 changed from ON to OFF or
        Item zone8 changed from ON to OFF or
        Item zone9 changed from ON to OFF or
        Item zone10 changed from ON to OFF

then
        if (zone1.state==OFF)  {
        if (zone2.state==OFF)  {
        if (zone3.state==OFF)  {
        if (zone4.state==OFF)  {
        if (zone5.state==OFF)  {
        if (zone6.state==OFF)  {
        if (zone7.state==OFF)  {
        if (zone8.state==OFF)  {
        if (zone9.state==OFF)  {
        if (zone10.state==OFF)  {

                        fan.sendCommand(OFF)
        }
        }
        }
        }
        }
        }
        }
        }
        }
        }
end

(Vincent Regaud) #2

Hello,

Please use the code fences