About

Commercial RF PIR sensors for detecting human (and animal) presence are mainly designed to send a signal whenever presence is detected but are not intended to continuously detect presence.

Such RF PIR sensors are used in general to perform an action when a presence is detected, however they do not continuously emit a signal when the presence is still around. This means that in order to be sure that the presence is still around, a timeout based on a timer that can be reset should be used.

With the help of some logic in Node Red a flow can be created, based on a timeout, to invert the condition such that a signal is emitted whenever the presence has vanished after a configurable amount of time.

Requirements

For the testing environment, Sonoff based products have been used that have been then flashed with the Tasmota firmware in order to connect everything to an MQTT bus.

  • RF PIR sensor working on $433MHz$,

  • a $433MHz$ bridge - the Sonoff RF Bridge 433 was used.

  • an MQTT server,
  • Node-Red

Setting Up

The following sample diagram illustrate the working order of the components:

+----------------+
| 433 MHz Device +------+
+----------------+      |
                        |
+----------------+      |      +-----------+         +-------------+
| 433 MHz Device +------+----->+ RF Bridge +-------->| MQTT Broker |
+----------------+      |      +-----------+         +-------------+
                        |
+----------------+      |
| 433 MHz Device +------+
+----------------+
  • all devices will emit an RF signal on $433 MHz$,
  • the RF bridge intercepts the $433 MHz$ signal and,
  • a message is sent to the MQTT broker indicating the value of the RF signal received.

The RF Bridge itself used in this setup was a Sonoff RF Bridge 433 and the device was flashed with the Tasmota firmware. Commonly, the other RF devices, including the PIR sensor do not need to be flashed - the devices emit the signal and do not require any special kind of setup (in some cases, not needed for this usage case, some devices need to be paired with the RF bridge).

Flashing the Sonoff RF Bridge with Tasmota

The process of flashing the Sonoff RF bridge with the Tasmota firmware is similar to all other Sonoff devices. The Sonoff RF Bridge contains a 5 pin header next to a switch that can be used together with a FTDI USB-to-Serial device to program the hardware.

The procedure to flash the Sonoff RF Bridge is as follows:

  1. move the switch to the OFF position marked on the PCB (towards the 5 pin header),
  2. connect $3V$ to $3V$ straight through, $RX$ to $TX$ on the FTDI, $TX$ to $RX$ on the FTDI and $GND$ to $GND$ on the FTDI - all other pins are not used,
  3. hold down the push button on the Sonoff bridge PCB and connect power from the FTDI device and NOT via USB (the push button must be held down),
  4. flash the Tasmota firmware

With the firmware flashed, the device can be disconnected and powered via USB. Once the Sonoff RF Bridge powers up, the Tasmota firmware starts in AP mode such that a wireless device can connect to the Sonoff RF Bridge and configure parameters.

The first step is to configure the WiFi which should vary depending on your configuration.

Next, the Tasmota firmware must be told what device it is currently running on and, for the Sonoff RF Bridge, the option ConfigurationConfigure ModuleModule type must be set to Sonoff Bridge (25) with no other GPIO settings.

Finally, the MQTT settings must be made to match your setup.

Presence Detection

With the setup in place, the Tasmota firmware console is accessed to see what the PIR sensor is sending once presence is detected:

RESULT = {"Time":"2021-07-13T06:29:39","RfReceived":{"Sync":12470,"Low":420,"High":1220,"Data":"D2882E","RfKey":"None"}}

Looking at the payload, it seems that the PIR sensor identifies itself as D2882E, an identifier that is passed by the RF bridge to the MQTT broker whenever presence is detected. That being said, Node-Red has to intercept the message on the MQTT broker, switch on the D2882E and interrupt a countdown timer whenever a message is received.

Node Red

The Node-Red logic is rather simple to understand but a little more complex to understand - the following operations will happen, in order:

  1. a timer is started counting to 1 hour,
  2. in case a presence is detected by the PIR sensor, the timer is reset and rescheduled for 1 hour,
  3. once the 1 hour interval elapses, a message is sent out.

The logic ensures that there is plenty of time for the PIR sensor to be idle and not detect any presence.

A description of the nodes is as follows:

  • the MQTT node is responsible for intercepting the messages received from the RF bridge,
  • the message payload is then converted to a JavaScript object via the json node,
  • the switch node checks that the D2882E identifier is present inside the newly converted RfReceived json object,
  • the message is then sent to the Reset node that sends a reset signal the the $1h$ timer in order to reset the timer,
  • an additional message is sent to clear the current message object and then reschedule the $1h$ timer,
  • the Init node is responsible for scheduling the $1h$ timer when the flow is reset or node-red restarts,
  • in case the $1h$ delay expires, meaning that no presence has been detected in the $1h$ time interval, a feedback loop resets the timer and reschedules the $1h$ timer

In effect the nodes emulate a functionality similar to the UNIX alarm call such that a timeout is reached when no additional signal is received by the logic.

Node Red Flow Export

[{"id":"2d2c81fc.1c9a2e","type":"tab","label":"Presence","disabled":false,"info":""},{"id":"96e0b3c9.63f27","type":"mqtt in","z":"2d2c81fc.1c9a2e","name":"","topic":"sonoff/bridge-0188/RESULT","qos":"2","datatype":"auto","broker":"725ed69c.6d76a8","x":250,"y":200,"wires":[["662044f7.e8cfdc","f86dff35.560708"]]},{"id":"662044f7.e8cfdc","type":"debug","z":"2d2c81fc.1c9a2e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":510,"y":200,"wires":[]},{"id":"1b42edd8.8adbb2","type":"delay","z":"2d2c81fc.1c9a2e","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"hours","rate":"1","nbRateUnits":"1","rateUnits":"hour","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":940,"y":460,"wires":[["82068931.99f68","d7b67abb.519d68","203c64dd.06205c","e818733c.be18d"]]},{"id":"85214bf5.2ca828","type":"switch","z":"2d2c81fc.1c9a2e","name":"","property":"payload.RfReceived.Data","propertyType":"msg","rules":[{"t":"eq","v":"D1582E","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":460,"wires":[["203c64dd.06205c"]]},{"id":"203c64dd.06205c","type":"change","z":"2d2c81fc.1c9a2e","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":460,"wires":[["1b42edd8.8adbb2","ed5aaaf9.8d28c","5d1de1b.717bd2"]]},{"id":"fb63c175.7bef38","type":"change","z":"2d2c81fc.1c9a2e","name":"Timeout","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":280,"wires":[["1b42edd8.8adbb2"]]},{"id":"82068931.99f68","type":"ui_text","z":"2d2c81fc.1c9a2e","group":"48d6388c.a33ac8","order":4,"width":0,"height":0,"name":"Presence","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":1140,"y":460,"wires":[]},{"id":"d7b67abb.519d68","type":"debug","z":"2d2c81fc.1c9a2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1130,"y":400,"wires":[]},{"id":"f82ff46f.cdc4e","type":"inject","z":"2d2c81fc.1c9a2e","name":"Init","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"1","x":630,"y":520,"wires":[["203c64dd.06205c"]]},{"id":"ed5aaaf9.8d28c","type":"debug","z":"2d2c81fc.1c9a2e","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":940,"y":560,"wires":[]},{"id":"f86dff35.560708","type":"json","z":"2d2c81fc.1c9a2e","name":"","property":"payload","action":"","pretty":false,"x":490,"y":460,"wires":[["85214bf5.2ca828"]]},{"id":"21bd208d.b6cad8","type":"delay","z":"2d2c81fc.1c9a2e","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":760,"y":340,"wires":[["fb63c175.7bef38"]]},{"id":"5d1de1b.717bd2","type":"function","z":"2d2c81fc.1c9a2e","name":"Clear","func":"msg = {}\n\nreturn msg","outputs":1,"noerr":0,"x":770,"y":400,"wires":[["21bd208d.b6cad8"]]},{"id":"e818733c.be18d","type":"link out","z":"2d2c81fc.1c9a2e","name":"","links":["4a95ffa4.a9e498"],"x":1095,"y":340,"wires":[]},{"id":"725ed69c.6d76a8","type":"mqtt-broker","z":"","name":"iot.internal","broker":"iot.internal","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"48d6388c.a33ac8","type":"ui_group","z":"","name":"Office Controls","tab":"a4498652.0868f","disp":true,"width":"6","collapse":false},{"id":"a4498652.0868f","type":"ui_tab","z":"","name":"Vault 101","icon":"dashboard","disabled":false,"hidden":false}]

Practical Applications

The main applications would consist in devices that would need to be triggered whenever no presence has been detected for a given time interval - in this case, for a $1h$ time period. Such devices or usage cases could include situations where certain devices should be powered down in order to not consume electricity or triggering some maintenance routines when no presence has been detected.

Usage scenarios:

  • using Zzz to power down a computer when no human presence has been detected at the computer,
  • starting a Roomba to clean up the floors whenever no human presence has been detected for a $1h$ time interval - possibly even making the Roomba dock in case a presence has been detected,
  • batch-turning all arcade cabinets off at an Arcade parlor whenever no human presence has been detected for a given time span.
  • etc…

iot/rf_pir.txt · Last modified: 2022/04/19 08:28 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.