GPIO - Event listener not working

i think i finally found the bug in my system:

	echo unexporting all

sudo sh -c 'echo "2" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "3" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "4" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "17" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "27" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "22" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "10" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "9" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "11" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "5" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "6" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "13" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "19" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "26" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "14" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "15" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "18" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "23" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "24" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "25" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "8" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "7" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "12" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "16" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "20" > /sys/class/gpio/unexport'	
sudo sh -c 'echo "21" > /sys/class/gpio/unexport'	

echo Done unexporting

this how the unexporting script needs to look like, note the differnces between " and ’

I don’t understand why but it works now, at least for time being…

And thanks joroen, i think I also will add the buzzer to my setup… My only problem now is that I have run out of GPIO’s, so I might have to add arduino or something else:)

Thanks for all the help

Now it stopped working again…

I took a closer look at the log file:

  2015-09-18 18:49:31.355 [ERROR] [m.r.internal.engine.RuleEngine] - Error during the execution of startup rule 'Initialize light states': Could not invoke method: org.openhab.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.Number) on instance: null
2015-09-18 18:49:32.193 [ERROR] [m.r.internal.engine.RuleEngine] - Error during the execution of startup rule 'Initialize heating states': Could not invoke method: org.openhab.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.Number) on instance: null
2015-09-18 18:49:32.966 [ERROR] [m.r.internal.engine.RuleEngine] - Error during the execution of startup rule 'Initialize contact states': Could not invoke method: org.openhab.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.Number) on instance: null

this is what I see as user rights in gpio before i start openhab

pi@raspberrypi ~ $ ls -l /sys/class/gpio/
total 0
-rwxrwx--- 1 root gpio 4096 Oct  9 09:22 export
lrwxrwxrwx 1 root gpio    0 Jan  1  1970 gpiochip0 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
-rwxrwx--- 1 root gpio 4096 Oct  9 09:23 unexport

and this is after:

pi@raspberrypi ~ $ ls -l /sys/class/gpio/
total 0
-rwxrwx--- 1 root gpio 4096 Oct  9 09:42 export
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio10 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio10
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio11 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio11
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio12 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio12
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio16 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio16
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio17 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio17
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio19 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio19
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio20 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio20
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio21 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio21
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio22 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio22
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio26 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio26
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio27 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio27
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio4 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio4
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio5 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio5
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio6 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio6
lrwxrwxrwx 1 root gpio    0 Oct  9 09:42 gpio9 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpio9
lrwxrwxrwx 1 root gpio    0 Jan  1  1970 gpiochip0 -> ../../devices/platform/soc/3f200000.gpio/gpio/gpiochip0
-rwxrwx--- 1 root gpio 4096 Oct  9 09:42 unexport

and this is my output from the terminal

2015-10-09 09:41:15.949 [INFO ] [runtime.busevents             ] - Heating_FF_Bath state updated to Undefined
2015-10-09 09:41:16.015 [INFO ] [runtime.busevents             ] - Light_Module2 state updated to Undefined
2015-10-09 09:41:16.037 [INFO ] [runtime.busevents             ] - Light_Module1 state updated to Undefined
2015-10-09 09:41:16.063 [INFO ] [runtime.busevents             ] - Light_Balcony state updated to OFF
2015-10-09 09:41:16.170 [INFO ] [runtime.busevents             ] - Light_Module1 state updated to OFF
2015-10-09 09:41:16.674 [INFO ] [runtime.busevents             ] - Light_Module2 state updated to OFF

so what am I doing wrong? I now start and stop openhab by using

sudo sh resetGpio.sh
sudo sh /home/pi/openhab/start.sh

I now moved the whole openhab file folder from /home/pi/ to /etc/ but its the same result…

maybe i can do like here and define my item

Switch Lamp_LV_Standing "Standing Lamp" {exec=">[OFF:sudo /opt/rc-switch/switchOff.sh 1] >[ON:sudo /opt/rc-switch/switchOn.sh 1]"}

which in my case will be something like

Switch Module2  "Module 2" {exec=">[OFF:sudo echo "0" > /sys/class/gpio/gpio2/value 1] >[ON:sudo echo "1" > /sys/class/gpio/gpio2/value 1]"}

From your mail I cannot see what the issue is (I am also new to OH) - how do your items and rules look like?

PS: I would not move the openhab folders from the default folders to your own home dir.

So which folder do you have openhab installed under? I read a tutorial saying that I should have it under /home/pi/openhab and others say etc/openhab.

Maybe I just try to reinstall debian, and openhab then, should i also migrate to openhab2?

There are a lot of tutorials out there with all sorts of instructions for how and where to put it. Most are out of date.

The preferred installation approach on Debian based Linux machines (Raspbian, Ubuntu, Mint, etc) is to use apt-get as described here. This will create the openhab user and group, set openhab to start as a service, let you upgrade b

oth openHAB and addons automatically, and put the various parts of openhab in standardized locations

  • Config: /etc/openhab
  • openHAB home: /usr/share/openhab
  • addons: /usr/share/openhab/addons
  • webapps (where Habmin goes, location of icons): /usr/share/openhab/webapps
  • logs: /var/log/openhab

Will reinstall it tonight and try it out again, I had it installed in /home/pi everything… Because that was what a probably outdated tutorial on instructables said…

Send me a link to that Instructables or post it here. I know @watou has contacted the author of at least one Instructable author about his outdated instructions but I don’t think this was the same one. At a minimum I can put a comment on it pointing to the more up to date instructions.

Thanks

here is one that refers to 1.5 version
and here

this one is good
and this is also superb

Couldn’t find the one with /home/pi right now, have it bookmarked on my personal laptop somwhere.

A final note, how do I change the state of a gpio in my rule, sendCommand(Module1, ON) does not do the the trick if its ON and i want to set it to off.

Thanks guys!

Reinstalling seems so far to work, thanks rlkoshak:) However how can I send the command to turn on my light from my switch, the log file shows that its detected state change but this sendCommand(Light_Kitchen_Item, ON) does not turn it on.

It should just be a matter of configuring the item correctly. Unfortunately I’ve not used GPIO from openHAB so I have no experience to draw upon to help.

Sounds like command is send but not executed on GPIO level. Can you see input from GPIO or switch anything on/off?

How is Light_Kitchen as Item defined?

Below is my item file:

Switch Light_Kitchen 		"Ceiling"  					(Group_Kitchen,Lights)				{ gpio="pin:6" } //Relay 4
/*Contact*/
Contact Contact_LivingRoom1  "Switch Living Room"  (Home, Switches)   {gpio="pin:18 debounce:1500 activelow:yes"}

here is my sitemap:

Frame label="Debug" {
	Group item=Lights icon="light"
	Group item=Switches label="Contacts" icon="kitchen"
	Group item=Heating label="Heating" icon="bath"
	Group item=rgb label="RGB Switch"
}

and this is my rule file:

import org.openhab.core.library.type.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openab.core.types.command
import org.openhab.core.items.genericitem
import java.util.Date
import java.text.SimpleDateFormat

rule "Switch detection"
when 
Item Contact_LivingRoom1 received update
then
	var String Timestamp = String::format( "%1$tH:%1$tM:%1$tS %1$tY-%1$tm-%1$td", new Date() )
	logInfo("test", "Contact_LivingRoom1 state change. State = " + Contact_LivingRoom1.state)
	sendCommand("Light_Kitchen", "ON")
	executeCommandLine("echo halla")
	sendMail("skatun@gmail.com", "Contact_LivingRoom1 state received: (" + Contact_LivingRoom1.state + ")", "Contact switched at " + Timestamp)
	
end



rule "HAG system start"
when
System started
then
var String Timestamp = String::format( "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", new Date() )
sendMail("skatun@gmail.com", "HAG system started", "The HAG system started on: " + Timestamp)
end

Thanks for all the tips.

Try SendCommand without " so … sendCommand(Light_Kitchen, ON)

Also easy to use is raspi-gpio get to see actual status

Thanks, I updated the rules now, but I need to go home to actually test it since I then physically need to push the button:)

raspi-gpio get does not work, i get command not found…

Also how can I see the status of my switches in the GUI?

And is there a way of toggle the light switch instead of sending ON/Off?

Thanks

See the Sitemap wiki page and look at the demo sitemap. You basically just need to create a sitemap and add your switches to it.

You can create a rule that sends an ON, sleeps half a sec, then sends an OFF.

Hi, thanks. Maybe toggle was the wrong word,

I tried googling, but couldnt find anything helpful. My rule file looks like this now, what I am missing?

if(Light_Kitchen.state == OFF)
	{
	sendCommand(Light_Kitchen, ON)
	Light_Kitchen.state = ON
    }
if(Light_Kitchen.state == ON)
    {
    sendCommand(Light_Kitchen, OFF)
	Light_Kitchen.state = OFF
    }

thanks for all the help, its been great.

From what I see, depending on what triggers this rule if Light_Kitchen is OFF the rule will immediately turn it back ON and visa versa. Not sure why you would want to do this.

What triggers this rule? If it is Item Light_Kitchen received update or something similar you may have found the most efficient way to lock openHAB into an infinite loop I can think of. :smile: This is what would happen. Light_Kitchen is set to OFF, rule triggers because it received an update, rule sets the light to ON, rule triggers because it received an update, rules sets light to OFF, … forever.

Perhaps it would help if I understood why you want to immediately reset the switch.

The lines where you call Light_Kitchen.state = don’t do anything. To set the state call either sendCommand or postUpdate.

hi
Thanks for the feedback

indeed I used:

 rule "Switch detection"
when 
Item Contact_LivingRoom1 received update
then

well I have a push button, spring loaded,
This is what i want to achieve…
so if my light is on and i push it will switch it off,
Then I go to my laptop for instance, switch it back on,
then i push my button , lights off. Then i ush my button again, lights on.

I just want my physically switch to change the light state, if its on then off, if its off then on and so on. But this should also be reflected in the GUI…