Skip to content

Example Occupancy Sensor

Roland B edited this page Mar 20, 2019 · 5 revisions

Properties

Available Properties

To have a Occupancy Sensor Sensor appear in the Home.app showing the presence of a human or any other you can setup a flow to publish occupancy information to the Home.App. The following characteristic properties are available:

Characteristic Optional/Required Characteristic Properties (to enable property)
OccupancyDetected Required {"OccupancyDetected" : 0}
StatusActive Optional {"StatusActive" : true}
StatusFault Optional {"StatusFault" : 0}
StatusTampered Optional {"StatusTampered" : 0}
StatusLowBattery Optional {"StatusLowBattery": 0}

Details

Characteristic Format Accepted Values Notes
OccupancyDetected uint8 0, 1 Value is set to 0 when occupancy is not detected
StatusActive bool true/false {"StatusActive":true} / {"StatusActive":false}
StatusFault uint8 0, 1 Value of 0 indicates that there is no fault / {"StatusFault" : 0}
StatusTampered uint8 0, 1 Value should set to 0 when the accessory has been reset to a non-tampered state / {"StatusTampered" : 0}
StatusLowBattery uint8 0, 1 Value should set to 0 when the battery charges to a level thats above the low threshold /{"StatusLowBattery": 0}

Example

These examples are meant to be copied into your Node-RED system and adapted to your setup.

Simple Presence Sensor

This example is a very simple occupancy sensor without any other functionality:

Bildschirmfoto 2019-03-20 um 16 12 58

It de-/activates only the Occupancy sensor in the Home.app and set the StatusActive to true anytime: Here is the sample code:

[{"id":"491167d6.3b9688","type":"change","z":"1ac5f8da.58656f","name":"Set payload to HkMsg for presence","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.OccupancyDetected","tot":"msg"},{"t":"set","p":"payload.StatusActive","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":360,"wires":[["7712393a.469f98"]]},{"id":"7712393a.469f98","type":"homekit-service","z":"1ac5f8da.58656f","isParent":true,"bridge":"890aedc6.d0b418","parentService":"","name":"RBRx@Home","serviceName":"OccupancySensor","topic":"","filter":false,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number","characteristicProperties":"{\n \"OccupancyDetected\" : 0,\n \"StatusActive\" : false\n}","x":1760,"y":360,"wires":[[]]},{"id":"14d9e017.35bd28","type":"inject","z":"1ac5f8da.58656f","name":"1","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1230,"y":320,"wires":[["491167d6.3b9688"]]},{"id":"56f0d08b.2afce8","type":"inject","z":"1ac5f8da.58656f","name":"0","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1230,"y":400,"wires":[["491167d6.3b9688"]]},{"id":"890aedc6.d0b418","type":"homekit-bridge","z":"","bridgeName":"Node-Red-HAP-Bridge-02","pinCode":"222-22-222","port":"","allowInsecureRequest":false,"manufacturer":"Default Manufacturer","model":"Default Model","serialNo":"Default Serial Number"}]

The Author is using a more comprehensive flow for a use case that is also a simple presence detection of a device. In that flow Node-Red regularly sends the router the MAC address of a smartphone to check whether the device is connected to the local WIFI. Bildschirmfoto 2019-03-20 um 16 31 45

This information is than converted to the payload the occupancy sensor requires. In this example you can assume e. g. that the owner is at home.

The example was inspired by ct-Open-Source/noderedexamples. Thanks to @merlinschumacher

Clone this wiki locally