Professional presense detector

Please @jrb5665 , can you share your Thing and transformation (occupancy.js) code?
I only got lumen information on Aqara but not the status and none at all for Mijia sensor
Wonder if a phisical sensor problem
Here my code


Thing topic testmotionsensor "MotionSensor Test Aqara" {
    Channels:
        Type switch : motion "Motion" [ stateTopic="zigbee2mqtt/testmovesensor", transformationPattern="JS:sensor.js"]
        Type number : brightness "Brightness" [ stateTopic="zigbee2mqtt/testmovesensor", transformationPattern="JSONPATH:$.illuminance"]
    Type number : voltage "Voltage" [ stateTopic="zigbee2mqtt/testmovesensor", transformationPattern="JSONPATH:$.voltage"]
    Type number : battery "Battery" [ stateTopic="zigbee2mqtt/testmovesensor", transformationPattern="JSONPATH:$.battery"]
        Type number : linkquality "RSSI" [ stateTopic="zigbee2mqtt/testmovesensor", transformationPattern="JSONPATH:$.linkquality" ]
    }

Thing topic testmotionsensor2 "MotionSensor Test Mijia" {
    Channels:
        Type switch : motion "Motion" [ stateTopic="zigbee2mqtt/testmovesensor2", transformationPattern="JS:sensor.js"]
    Type number : voltage "Voltage" [ stateTopic="zigbee2mqtt/testmovesensor2", transformationPattern="JSONPATH:$.voltage"]
    Type number : battery "Battery" [ stateTopic="zigbee2mqtt/testmovesensor2", transformationPattern="JSONPATH:$.battery"]
        Type number : linkquality "RSSI" [ stateTopic="zigbee2mqtt/testmovesensor2", transformationPattern="JSONPATH:$.linkquality" ]
    }

Items

 // Movement Sensor1 (Aqara)
Group gMotionSens1
Contact MotionSens1 "Sensore Aqara [%s]" (gMotionSens1)  {channel="mqtt:topic:mosquitto:testmotionsensor:motion" }
Number Brighmotionsensor "Luminosità [%d lumen]"(gMotionSens1)  {channel="mqtt:topic:mosquitto:testmotionsensor:brightness"}
Number Voltmotionsensor  "Voltaggio Voltage [%d mV] " (gMotionSens1) {channel="mqtt:topic:mosquitto:testmotionsensor:voltage"}
Number LinkQuality  "Quality [%d] " (gMotionSens1) {channel="mqtt:topic:mosquitto:testmotionsensor:linkquality"}
Number Battmotionsensor  "Stato Batteria [%.1f %%] " (gMotionSens1) {channel="mqtt:topic:mosquitto:testmotionsensor:battery"}

// Movement Sensor2 (Mijia)
Group gMotionSens2
Contact MotionSens2 "Sensore Mijia [%s]"  (gMotionSens2) {channel="mqtt:topic:mosquitto:testmotionsensor2:motion" }
Number Voltmotionsensor2  "Voltaggio Voltage [%d mV] " (gMotionSens2) {channel="mqtt:topic:mosquitto:testmotionsensor2:voltage"}
Number LinkQuality2  "Quality [%d] " (gMotionSens2) {channel="mqtt:topic:mosquitto:testmotionsensor2:linkquality"}
Number Battmotionsensor2  "Stato Batteria [%.1f %%] " (gMotionSens2) {channel="mqtt:topic:mosquitto:testmotionsensor2:battery"}

JS

(function(x){

    var result = "";
 
    var json = JSON.parse(x);  
    if (json.occupancy) 
    {
        result="OFF";
    } 
    else 
    {
        result="ON";
    }
    return result;
    
})(input)

I’m not sure I can help you. I am currently in the middle of migrating most of my system off OpenHAB to a combination of Node-Red and deconz.

In my OH 2.3 system the devices are currently paired to the Xiaomi Gateway and the thing definition is just done through the Xiaomi Binding and PaperUI. I included a screenshot above.
My rules (which is what I think you are meaning by transformation) are handled by node-red and the mqtt-eventbus and any transformation required between types is handled in node-red, but that reads the status from OH not sends it to OH.
Or if you just mean how to get the value of ON or OFF, this is handled by the Xiaomi Binding as the Motion Status channel is a Switch.

I don’t use zigbee2mqtt.

1 Like

Well this is a very late reply but it’s useful for your scenario so I thought i should share it for future reference :slightly_smiling_face:
You can make a very reliable and simple presence indicator with a PIR (I use the Xiaomi) and some other sensor (another PIR is fine) to indicate entry/exit.

  1. Create a proxy switch item to indicate presence in the room, then create a rule that will command the proxy on if motion is detected and proxy is not already on. Save the time to another proxy.
  2. Create a rule that starts a timer every time entry/exit happens, the timer should be long enough that your entry/exit detector has time to reset and your rules from step one has time to detect you. I use six minutes but that’s a bit overkill.
  3. When the timer runs out it should check if there has been motion after the last entry/exit + reset period. So for my case I check if there has been motion during the last five minutes (six minus one for reset). Edit: Forgot to say: If there has been no motion, turn off the presence proxy.
  4. Use the proxy item state to command your lights and other things in the room.

Analysis:
Very stable as only entry/exit events can turn off presence state.
For faster response you can also command the proxy on when an entry/exit event occurs.
If you sit down and remain very still within the reset period of your entry/exit sensor the system will assume you didn’t stay, however if you wave or do some detectable motion once, the system will assume you are in the room until the next entry/exit event.
I use five minutes to make sure the system will find me, however depending on your sensors this can of course be greatly reduced.
If you have multiple doors you need a sensor for each door.
If the system should handle you climbing out the window you need sensors on windows too.

1 Like

Old post, sorry but I just saw it…

What if you head to the kitchen, but half way you “forgot” something and turn around, (notice,this is a time question). Will the motion detector still turn of the light ?

Nope, if I turn around (which happens frequently), then I have to manually turn the light off by tripping the motion sensor a second time or just asking Google. It’s not a big deal, so I don’t worry about it.

FYI, the sensor is a Belkin Wemo Motion. It was one of their first products in the Wemo line, and one of the few good Wemos I’ve used. Which, of course, means that they discontinued it (along with the Wemo Maker that I use to control my gas fireplace).

What’s nice about the Wemo Motion is that it returns to an OFF state about three seconds after it no longer detects motion. So if I stand in front of it and wait for it to return to OFF, I can immediately trip it again. This wouldn’t work as well with sensors that take more than a few seconds to return to OFF.

Thats what I thought :slight_smile:

Thats the reason why I prefere to use alarm PIR´s. They re-trigger very fast (1-2 seconds). And then use the logic in openhab (or my IHC controller) to do whatever timing is needed.
I have a few other PIR´s (battery devices). They´re real pain sometime, because they dont retrigger, or they spend alot of seconds before they retrigger…

1 Like