Hi, i have recently started working with OpenHAB. I have an LED and a PIR Motion Sensor connected to my Raspberry Pi. I want to define a rule so that whenever motion is detected by the sensor, the LED is turned on. 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. Any help would be appreciated.
You really need to specify your configuration a little more to get help. For instance, how are the ‘switch for motion sensor’ and ‘motion is detected by the sensor’ defined in the items file, and how are they actually triggered.
One thing is noticeable though, is that the line
Item MotionSensor changed
will trigger the command when the motion sensor item goes from true to false and false to true. I think most motion sensors will be true when motion is detected so should read
rule "MotionDetected"
when
Item MotionSensor changed to TRUE
then
sendCommand(RaspiLED, ON)
end
but neither changed to True or On worked for me. I tried with MotionSensor as a Contact and defined in terms of changed to OPEN, but that also didnt work for me
so when the sensor is on, it shows nothing in log when motion takes place. Although from pi terminal i can read the value of gpio pin to have changed from 0 to 1 when motion takes place.
when i turn on or off the switch of sensor from openhab , it shows "Received unknown command ‘TOGGLE’ for MotionSensor
rule "LED"
when
Item MotionSensor changed
then
if (MotionSensor.state == OPEN) {
RaspiLED.sendCommand(ON) }
else {
RaspiLED.sendCommand(OFF) }
end
And finally for the sitemap:
Switch RaspiLED
Text MotionSensor
The sitemap should show a switch which represents the state of the LED (ON or OFF).
The MotionSensor is displayed as text with its state “OPEN” or “CLOSED”.
Tests:
toggling the switch should set the LED on or off.
with detected motion of your PIR the state should change from “CLOSED” to “OPEN” (or vice versa dependent to the voltage Levels at the PIR-Output)
The rule should change the LED when Motion is detected
my led is working perfectly fine and also in accordance with the rules i defined for led. Only the sensor is not turning on the LED when motion is detected