How to configure motion sensors (PIR's)

I am reading data from a database for the channels so how do I create a proxy item. In my case how do I create a proxy item.

A proxy item is just an Item without a binding that you put on your sitemap. The behavior that runs when you trigger the item gets implemented in a rule. So, for example, you can have a Switch Item that is a proxy for a light switch. You put the Proxy on your sitemap and create a rule triggered by that proxy Switch received command. In the rule you might do some extra work and tests (e.g. check the state of a motion sensor, check time of day, send a notification, etc.) and then sendCommand to the actual Switch bound to the light switch.

Hi federic. I too am trying to work with PIR motion sensor. On using

when
Item MotionSensor changed
then
sendCommand(RaspiLED, ON)
end

turns the LED on whenever i turn on the switch for my motion sensor and not when motion is detected by the sensor. Can you please share the rule that worked for you.

Hi,
Can you share your items’ file line for MotionSensor?
What do you mean by “when you turn on the switch for” your sensor, do you mean a physical switch on the sensor?

Switch MotionSensor{ gpio =“pin:18” }

i have created a switch for the motion sensor in openhab. when i turn the switch on from openhab, it turns the gpio pin to high the sensor starts working. but i want that when motion is detected my led should glow and not when the sensor is turned on

Hi,
your rule turns LED on with every change of the motion sensor. This means, the LED is switched on by detection of movement AND is switched on by detection of no movement.
You need your rule to differentiate between turning on and off.

rule "Motion detected, turn LED on"
when
  Item MotionSensor changed from OFF to ON
then
  RaspiLED.sendCommand(ON)
end

rule "no Motion detected, turn LED off"
when
  Item MotionSensor changed from ON to OFF
then
  RaspiLED.sendCommand(OFF)
end

Sometimes you get in trouble with using sendCommand action, so it is advised to use the method of your item. (see sendCommand() Documentation)

Andreas

1 Like

Can you try modifying
Switch MotionSensor{ gpio ="pin:18" }
by
Contact MotionSensor{ gpio ="pin:18" }

hi andreas,
my LED doesnt turn on when motion is detected, it simply gets turned on when i switch my sensor from OFF to On

and what should be the rule federic?

I’m not sure how your PIR works, does it send an ON and OFF signal? First try the original rule you had, but that should only switch the LED ON and never OFF. Then you can try to change the rule to:

when 
  Item MotionSensor changed to ON
then
  sendCommand(RaspiLED, ON)
end

if that doesn’t work you need to inspect the state of Motion sensor to see if it is producing ON/OFF states or some numerical value, you can do that in the console or by printing the state in the log.

if that worked, then you need to add code to your rule to turn the light OFF either based on a timer or based on the sensor switching back to its OFF state.

no
changed to ON didnt work for me

How can i inspect state of my pir sensor?

does the original rule work?

when 
  Item MotionSensor changed
then
  sendCommand(RaspiLED, ON)
end

No. It doesnt turn LED ON.

Are you sure you have wired the PIR correctly and that it is working?
If you want to inspect the state of an item you can do so by:
telnet ip.address.of.openhb 5555
then
openhab status MotionSensor
typing openhab will provide a list of available commands.

However, I think your PIR may not be wired properly or to the correct GPIO

when i do gpio -g read 18, it shows 1 when motion is detected otherwise 0. can i equate MotionSensor value to 1 in my rule?

By the way, I haven’t used the GPIO binding myself but did you follow the installation process and made sure your addons folder has the binding jar file? Can you verify with another item that the binding works (is RaspiLED also a gpio item?)?

yes the gpio binding is working fine since i tested with the RaspiLED.

1 Like

After reading the binding documentation the states should be OPEN/CLOSED.
try to define your item like this:
Contact MotionSensor { gpio="pin:18 activelow:yes" }
and try to inspect its state through the console

no. didnt work.

can i define a rule that when gpio pin is 1…raspiLED should turn ON?

I don’t think so, the binding should translate that to OPEN/CLOSED

what is the output of the console when you do:
openhab status MotionSensor