Pushbutton to turn on and off light

Hi
I have Openhab running on RPI and its working nicely. I have a pushbutton connected to GPIO 12 and the light connected to GPIO 22.

I can control the light through web or android, but i would also like to use the push button to do this. Is there a way to do this? Should i use the contact item?

Cheers

Set up GPIO 12 as a Switch. Then write a rule that triggers when your GPIO_12 switch receives a command and toggle the state of the GPIO 22 switch.

Thanks, will head home and try it out now.

Hi,
well it was working for a while, however now it stopped working. It turns the gpio off every 15s, see log below, any idea why? I unexported all gpio before launching the run time and also set the gpio permisson to

chgrp -R dialout /sys/class/gpio
chmod -R g+rw /sys/class/gpio


2015-09-24 20:58:32.976 [INFO ] [runtime.busevents             ] - Heating_FF_Bath state updated to OFF
2015-09-24 20:58:33.478 [INFO ] [runtime.busevents             ] - Heating_FF_Office state updated to OFF
2015-09-24 20:58:33.958 [INFO ] [runtime.busevents             ] - Heating_FF_Bed state updated to OFF
2015-09-24 20:58:44.007 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'demo.sitemap'
2015-09-24 20:58:44.037 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'demo.items'
2015-09-24 20:58:44.065 [INFO ] [runtime.busevents             ] - Light_GF_Tv state updated to Undefined
2015-09-24 20:58:44.071 [INFO ] [runtime.busevents             ] - Light_FF_Bath_Ceiling state updated to Undefined
2015-09-24 20:58:44.078 [INFO ] [runtime.busevents             ] - Light_GF_Glass state updated to Undefined
2015-09-24 20:58:44.109 [INFO ] [runtime.busevents             ] - Heating_FF_Bed state updated to Undefined
2015-09-24 20:58:44.141 [INFO ] [runtime.busevents             ] - Heating_FF_Bath state updated to Undefined
2015-09-24 20:58:44.147 [INFO ] [runtime.busevents             ] - Light_GF_Elefant state updated to Undefined
2015-09-24 20:58:44.155 [INFO ] [runtime.busevents             ] - Light_SF_Corridor_Door state updated to Undefined
2015-09-24 20:58:44.197 [INFO ] [runtime.busevents             ] - Heating_GF_Kitchen state updated to Undefined
2015-09-24 20:58:44.205 [INFO ] [runtime.busevents             ] - Light_GF_Bar state updated to Undefined
2015-09-24 20:58:44.241 [INFO ] [runtime.busevents             ] - Heating_FF_Office state updated to Undefined
2015-09-24 20:58:44.247 [INFO ] [runtime.busevents             ] - Light_GF_Center state updated to Undefined
2015-09-24 20:58:44.280 [INFO ] [runtime.busevents             ] - Heating_GF_Living state updated to Undefined
2015-09-24 20:58:44.309 [INFO ] [runtime.busevents             ] - Heating_GF_Corridor state updated to Undefined
2015-09-24 20:58:44.315 [INFO ] [runtime.busevents             ] - Light_GF_Living_Table state updated to Undefined
2015-09-24 20:58:44.596 [INFO ] [runtime.busevents             ] - Light_GF_Living_Table state updated to OFF
2015-09-24 20:58:45.107 [INFO ] [runtime.busevents             ] - Light_GF_Center state updated to OFF
2015-09-24 20:58:45.611 [INFO ] [runtime.busevents             ] - Light_GF_Tv state updated to OFF
2015-09-24 20:58:46.115 [INFO ] [runtime.busevents             ] - Light_GF_Bar state updated to OFF
2015-09-24 20:58:46.620 [INFO ] [runtime.busevents             ] - Light_GF_Elefant state updated to OFF
2015-09-24 20:58:47.124 [INFO ] [runtime.busevents             ] - Light_GF_Glass state updated to OFF

What am I missing?

Unfortunately I have no experience with GPIO through openHAB though there have been other postings from people seeing a similar behavior.

Thanks, I already read those, but still i get this undefined state, even after i added this to my start.sh file. I will keep digging, its started to get annoying sitting in the dark…

   cd /sys/class/gpio

echo Initializing

chgrp -R dialout /sys/class/gpio
chmod -R g+rw /sys/class/gpio

sh -c "echo 2 > unexport"	

sh -c "echo 2 > export"

sh -c "echo out > gpio2/direction"

echo  Setting all gpio high

sh -c "echo 1 > gpio2/value"

sleep 20

echo unexporting all

sh -c "echo 2 > unexport"