Motion sensor basic rule not working

Purchased a zw6302 the other day and after a bit finally got it initialized. Now i am trying to setup a basic rule to proof the concept then work in more complex items depending on other variables. So here is where i am now…

rule "Motion Sensed"

when
	Item MotionSensor_Alarm changed to Alarm
then
	sendMail("me@gmail.com", "Motion Test", "Living Room Motion detected")

end

there are 3 channels in the sensor: battery, binary, and alarm. below is the info for the two relevant here.

So my question is how should my rule be worded? I have tried all variations i can think of. I have done the Alarm channel “changed to Alarm” and “changed to ON”, i have done the Binary channel “changed to Triggered” and “changed to ON”. Nothing triggers the test email. I have even tried them both as just changed without a specified state to see if i saw something. And yes my emails are working. It seems straight forward but it’s kicking my butt.

i can see the changes if i have Habmian open and look at the thing channels. The states change.

Little bit of a side note, what the heck is the difference between binary and alarm?

Thanks for any help.

  {
    "link": "http://192.168.5.5:9080/rest/items/MotionSensor_Alarm",
    "state": "NULL",
    "stateDescription": {
      "readOnly": true,
      "options": [
        {
          "value": "OFF",
          "label": "Ok"
        },
        {
          "value": "ON",
          "label": "Alarm"
        }
      ]
    },
    "type": "Contact",
    "name": "MotionSensor_Alarm",
    "label": "Motion_Alarm",
    "category": "Motion",
    "tags": [],
    "groupNames": []
  },
  {
    "link": "http://192.168.5.5:9080/rest/items/MotionSensor_BinaryOutput",
    "state": "NULL",
    "stateDescription": {
      "readOnly": true,
      "options": [
        {
          "value": "ON",
          "label": "Triggered"
        },
        {
          "value": "OFF",
          "label": "Untriggered"
        }
      ]
    },
    "type": "Contact",
    "name": "MotionSensor_BinaryOutput",
    "label": "Motion Sensor",
    "category": "Motion",
    "tags": [],
    "groupNames": []
  },

If you can see the state changes in habmin, that would indicate that the sensor is working. It does however look like you have a Contact item, in which case the trigger should be changed to CLOSED.

I will try closed as it can’t hurt but where would such a state come from? I see nothing in the sensors json that would indicate that as being a viable state of the sensor.

http://docs.openhab.org/concepts/items.html#enum-types

I have seen that page. It tells me that ON and OFF are valid state, and OPEN and CLOSED are valid states. I dont see anywhere that ties a type of contact to a stle of response though. Is the contact category only going to accept OPEN and CLOSED? In that case is OPEN == OFF and CLOSED == ON?

I am just trying to understand the logic so i can better make future rules. I have been trying to make this one for days and done more searches than is reasonable and have never come across anything that says that in my digital journey.

Thanks for your assistance.

edit. in items it states the type, then down lower it states the accepted values for that type. I got where you are coming from. just waiting for the timeout of the sensor to see if i can trigger the email using OPEN and CLOSED so i know which state equates to ON/OFF.

edit2 Still no trigger with “changed to CLOSED”

A Switch item has the states ON and OFF

A Contact item has the states OPEN and CLOSED

Furthermore a contact item is read-only and a switch can be controlled by the user.

Have you looked into the logs? If you are using openhabian, go into the openhabian-config and install frontail, then you can see the logs in a browser by visiting http://openhabian-address:9001

If you can see the state changes there, at least the items are working.

Are you sure that it’s not the sendMail action that fails?

got it to trigger.

Your comment and some more searching based on that idea lead me to this thread.
https://community.openhab.org/t/on-off-vs-open-close-contact-item-cannot-get-it-to-work/11322/7

In there Chris Jackson states that an item HAS to be set to the right Item Type based on the items configuration. Because the XML shows on and off i changed my item type to switch even though the leading opinion when searching was that it should be contact because it’s read only.

Set my rule up as “changed to ON” and it fired off an email as soon as the timeout for motion lapsed and the device re-triggered.

Learn something new every day. Thanks very much for assistance in helping me get that part down. Now to try and frame the rest of the rule up.

Glad to hear. :smile:

When reading in the forum I have noticed that different motion sensors aren’t consistent in what item types they should be connected to. Some require contact and some require switch, so you need to - as you did - check what the channel says to use.