# Newbie query - How to design flow for RF sensor?

**URL:** <https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985>\
**Category:** General\
**Created:** [9 October 2020 10:45 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985 "2020-10-09T10:45:29Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![epicurean](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@epicurean](https://discourse.nodered.org/u/epicurean)\
**Post date:** [9 October 2020 10:45 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/1 "2020-10-09T10:45:30Z")

</div>

I was advised to ask in this Node Red forum,as I could not design a rule in Openhab for RF sensors that gives out more than just open and close codes.  
I have 2 Kerui RF window sensors which gives 4 distinct codes  
1)Left Window  
48B5EE open  
48B5E7 closed  
48B5EB tamper  
48B5EF low battery

2)Top Window  
BDAC1E open  
BDAC17 closed  
BDAC1B tamper  
BDAC1F low battery

I use a sonoff RF bridge to receive the RF signals

How do I design a flow that alerts me when ether of the batteries is low, and if the windows are open between 10pm and 6am?

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [9 October 2020 13:55 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/2 "2020-10-09T13:55:33Z")

</div>

First, what is the form of the data received from the RF bridge? Is it just a string? Formatted some way? You are using the stock firmware image? Not a customized image on the bridge?

I happen to have a Bond Bridge for control of my fans, which use 303.875 MHz common in US versus 433 MHz is often more common in UK from what I read. But I digress. I ask about the RF bridge, does it have a published API?

Customized firmware for RF bridge you have, I think only supports MQTT communication, not the stock firmware? If the stock firmware publishes status via HTTP/HTTPS REST API or MQTT or something else we can capture via NR, that is the place to start, I would think.

I find several examples where people have changed the bridge firmware to basically hack the bridge to get some type of communication method NR can understand. I would rather not go that route if possible, or at least initially.

In the case of my Bond Bridge, the firm that produces it, publishes a very nice API, with the expectation that it would be leveraged as needed.

I found that there is apparently a published API for your bridge [http://developers.sonoff.tech/sonoff-diy-mode-api-protocol.html](http://developers.sonoff.tech/sonoff-diy-mode-api-protocol.html). Since this API is a REST API, with a bit of work, should be able to get the alert data into NR.

What is your experience with NR?

---

<div class="post-metadata">

**Author:** ![epicurean](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@epicurean](https://discourse.nodered.org/u/epicurean)\
**Post date:** [10 October 2020 06:46 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/3 "2020-10-10T06:46:01Z")

</div>

RF bridge is flashed with Tasmota. data looks like this after opening and closing the windows  
"07:43:55 MQT: tele/sonoff/bridge2/RESULT = {"Time":"2020-10-10T07:43:55","RfReceived":{"Sync":9540,"Low":310,"High":940,"Data":"48B5E7","RfKey":"None"}}  
07:43:59 MQT: tele/sonoff/bridge2/RESULT = {"Time":"2020-10-10T07:43:59","RfReceived":{"Sync":9480,"Low":310,"High":940,"Data":"48B5E7","RfKey":"None"}}  
07:44:01 MQT: tele/sonoff/bridge2/RESULT = {"Time":"2020-10-10T07:44:01","RfReceived":{"Sync":8170,"Low":320,"High":940,"Data":"245AF7","RfKey":"None"}}

regards

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [10 October 2020 13:08 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/4 "2020-10-10T13:08:18Z")

</div>

Oh, cool. So you do have MQTT communication. Well that makes things a lot easier. So the next question is how do you want the notifications to be done? Email, SMS, popup window on dashboard, something else?

The logical place to start, is to understand how NR handles and process messages, since that is what you are receiving as MQTT communication from your bridge right?

MQTT [https://cookbook.nodered.org/mqtt/connect-to-broker](https://cookbook.nodered.org/mqtt/connect-to-broker)  
Working with Messages [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![epicurean](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@epicurean](https://discourse.nodered.org/u/epicurean)\
**Post date:** [11 October 2020 00:20 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/5 "2020-10-11T00:20:59Z")

</div>

I would like the notifications sent to me via telegram. This notification seems to works reliably with the other non RF tasmota devices I have.

Yes, what I posted earlier is the usual data sent by the sonoff RF bridge upon opening and closing of the windows

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 October 2020 08:25 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/6 "2020-10-11T08:25:09Z")

</div>

Have you checked what is in the message you are sending to the telegram node?

---

<div class="post-metadata">

**Author:** ![epicurean](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@epicurean](https://discourse.nodered.org/u/epicurean)\
**Post date:** [12 October 2020 02:50 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/7 "2020-10-12T02:50:37Z")

</div>

Frankly, I have not sent any messages of any kind to the RF sensors because I do not know where to start to design the flow. Which is why I am seeking help in this forum.

For a typical tasmota mqtt rule, say for one of my tasmota switches, it will be something like this:

val mqttActions = getActions("mqtt", "mqtt:broker:mosquitto")

rule "OP1 Monitor to OFF"  
when  
Time cron "0 0 19 1/1 \* ? \*"  
then  
mqttActions.publishMQTT("cmnd/sonoff-AEI-op1/POWER", "Off")  
val telegramAction = getActions("telegram","telegram:telegramBot:xxxxxxx")  
telegramAction.sendTelegram("OP1 Monitor is switched OFF")  
logInfo("Info","OP1 Monitor OFF Rule fired")

And the telegram message will come on my phone without issues

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 October 2020 06:16 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/8 "2020-10-12T06:16:30Z")

</div>

I don't recognise the syntax you are using for rules, it doesn't look like anything I have seen in node red.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [12 October 2020 06:50 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/9 "2020-10-12T06:50:28Z")

</div>

I think best way for anybody to be able to help you is that we start with the basis. Create a simple flow like below (I guessed the topic, you have to put in the correct topic to pick up the events) with a MQTT in node that connects to your MQTT broker

Open close the windows a couple of times, notice the events coming into Node-RED and show us the results

Once done, we can take it from there

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae9d33900608da8fa1669ef00830de42e2863fa9.png)

---

<div class="post-metadata">

**Author:** ![epicurean](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@epicurean](https://discourse.nodered.org/u/epicurean)\
**Post date:** [12 October 2020 10:07 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/10 "2020-10-12T10:07:59Z")

</div>

Sorry, this syntax is the rules in Openhab, not in node red.

---

<div class="post-metadata">

**Author:** ![epicurean](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@epicurean](https://discourse.nodered.org/u/epicurean)\
**Post date:** [12 October 2020 10:13 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/11 "2020-10-12T10:13:27Z")

</div>

Something like this?

```auto
[{"id":"27d1839a.8c260c","type":"tab","label":"MBR Windows RF Flow","disabled":false,"info":""},{"id":"b7f640b2.ef338","type":"mqtt in","z":"27d1839a.8c260c","name":"","topic":"tele/sonoff/bridge2/RESULT","qos":"2","datatype":"auto","broker":"4606d9fb.a64278","x":142,"y":850,"wires":[["d0f8db9f.685b28"]]},{"id":"d0f8db9f.685b28","type":"json","z":"27d1839a.8c260c","name":"","property":"payload","action":"","pretty":false,"x":308,"y":947,"wires":[["56253c5d.49a5a4"]]},{"id":"56253c5d.49a5a4","type":"function","z":"27d1839a.8c260c","name":"Window Sensors","func":"// Code below is for the rf door sensor at front door\n\nvar on = \"CLOSED\";\nvar off = \"OPEN\";\nvar tamper = \"TAMPER\"\nvar lowbat = \"LOW BATTERY\"\n\nmsg1={};\n\n// Left Window Sensor\nif (msg.payload.RfReceived.Data==\"48B5E7\"){\n msg1.payload = on;\n return [msg1,null,null,null]}\n else if (msg.payload.RfReceived.Data==\"48B5EE\"){\n msg1.payload = off;\n return [msg1,null,null,null]}\n else if (msg.payload.RfReceived.Data==\"48B5EB\"){\n msg1.payload = tamper;\n return [msg1,null,null,null]}\n else if (msg.payload.RfReceived.Data==\"48B5EF\"){\n msg1.payload = lowbat;\n return [msg1,null,null,null]} \n// Middle Top Window Sensor\nelse if (msg.payload.RfReceived.Data==\"BDAC17\"){\n msg1.payload = on;\n return [null,msg1,null,null]}\n else if (msg.payload.RfReceived.Data==\"BDAC1E\"){\n msg1.payload = off;\n return [null,msg1,null,null]}\n else if (msg.payload.RfReceived.Data==\"48B5EB\"){\n msg1.payload = tamper;\n return [msg1,null,null,null]}\n else if (msg.payload.RfReceived.Data==\"48B5EF\"){\n msg1.payload = lowbat;\n return [msg1,null,null,null]} \n","outputs":2,"noerr":0,"x":523,"y":976,"wires":[["bb60227b.bfad6"],["37fe65b6.3e1bca"]]},{"id":"bb60227b.bfad6","type":"mqtt out","z":"27d1839a.8c260c","name":"Left Window","topic":"tele/sonoff/bridge2/RESULT","qos":"","retain":"true","broker":"4606d9fb.a64278","x":815,"y":782,"wires":[]},{"id":"37fe65b6.3e1bca","type":"mqtt out","z":"27d1839a.8c260c","name":"Middle Top Window","topic":"tele/sonoff/bridge2/RESULT","qos":"","retain":"true","broker":"4606d9fb.a64278","x":804,"y":970,"wires":[]},{"id":"4606d9fb.a64278","type":"mqtt-broker","z":"","name":"mosquitto","broker":"192.168.0.150","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"1","birthRetain":"true","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [12 October 2020 13:02 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/12 "2020-10-12T13:02:47Z")

</div>

Well, in that flow you are just sending the messages for each window back to the MQTT broker, I guess that is not what you want to do?

I assume you receive correct messages now for each window?? Did you check with a debug node?

Let's start with some thoughts about your requirements

> [@epicurean](#):
>
> How do I design a flow that alerts me when ether of the batteries is low, and if the windows are open between 10pm and 6am?

When a window is opening/closing, the tamper alarm goes on or the battery is low, I assume you will get a message _only_ when they happens? Best is to store current states for the opening/closing since you will need to keep that when you evaluate if you shall send an alert or not. If the window is opened outside 10pm and 6am and kept open, you want to get informed "later" when the time is within the valid range. The other messages for tamper and battery will be sent immediately around the clock. So since you seem to feel pretty familiar with function nodes and javascript, I have made an example below with function nodes and code. There are many other node types available that could be used instead like gates, cron+, switch, change etc etc. Plenty of room for alternatives....

The rbe nodes in the flow is to prevent repeated messages during 10pm to 6am 😉

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d433078560b6984f0c3135ddd2eec96a34274091.png)

```auto
[{"id":"b7f640b2.ef338","type":"mqtt in","z":"27d1839a.8c260c","name":"","topic":"tele/sonoff/bridge2/RESULT","qos":"2","datatype":"auto","broker":"4606d9fb.a64278","x":170,"y":140,"wires":[["d0f8db9f.685b28"]]},{"id":"d0f8db9f.685b28","type":"json","z":"27d1839a.8c260c","name":"","property":"payload","action":"","pretty":false,"x":380,"y":140,"wires":[["56253c5d.49a5a4"]]},{"id":"56253c5d.49a5a4","type":"function","z":"27d1839a.8c260c","name":"Window Sensors","func":"// Code below is for the rf door sensor at front door\n\n\n// Left Window Sensor\nif (msg.payload.RfReceived.Data==\"48B5E7\"){\n flow.set('Left_Window_Sensor',\"CLOSED\")\n}\nif (msg.payload.RfReceived.Data==\"48B5EE\"){\n flow.set('Left_Window_Sensor',\"OPEN\")\n}\nif (msg.payload.RfReceived.Data==\"48B5EB\"){\n return [{payload:\"TAMPER\"},null,null,null]}\nif (msg.payload.RfReceived.Data==\"48B5EF\"){\n return [{payload:\"LOW BATTERY\"},null,null,null]} \n\n// Middle Top Window Sensor\nif (msg.payload.RfReceived.Data==\"BDAC17\"){\n flow.set('Middle_Top_Window',\"CLOSED\")\n}\nif (msg.payload.RfReceived.Data==\"BDAC1E\"){\n flow.set('Middle_Top_Window',\"OPEN\")\n}\nif (msg.payload.RfReceived.Data==\"BDAC1B\"){\n return [null,{payload:\"TAMPER\"},null,null]}\nif (msg.payload.RfReceived.Data==\"BDAC1F\"){\n return [null,{payload:\"LOW BATTERY\"},null,null]} \n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":600,"y":140,"wires":[["7815fd50.235484"],["4bdce9ca.39ead8"]]},{"id":"d20c6df8.53f2c","type":"inject","z":"27d1839a.8c260c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":290,"wires":[["3ef83812.dd2f68"]]},{"id":"3ef83812.dd2f68","type":"function","z":"27d1839a.8c260c","name":"h >= 22 || h < 6","func":"var h = new Date(msg.payload).getHours();\n//node.warn(h);\n\nif (h >= 22 || h < 6){\n if (flow.get('Left_Window_Sensor') == \"OPEN\"){\n node.send([{payload:\"Left Window OPEN\"},null]);\n }\n else{\n node.send([{payload:\"Left Window CLOSED\"},null]);\n }\n if (flow.get('Middle_Top_Window') == \"OPEN\"){\n node.send([null,{payload:\"Middle Top Window OPEN\"}]);\n }\n else{\n node.send([null,{payload:\"Middle Top Window CLOSED\"}]);\n }\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":350,"y":290,"wires":[["8103e63f.f50498"],["3ac173b2.049a1c"]]},{"id":"8d38725.02ed89","type":"debug","z":"27d1839a.8c260c","name":"Left Window open alerts","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":260,"wires":[]},{"id":"7815fd50.235484","type":"debug","z":"27d1839a.8c260c","name":"Left window","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":100,"wires":[]},{"id":"4bdce9ca.39ead8","type":"debug","z":"27d1839a.8c260c","name":"Middle top window","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":180,"wires":[]},{"id":"8cb6cef1.ea121","type":"comment","z":"27d1839a.8c260c","name":"Tamper & Battery alerts","info":"","x":860,"y":60,"wires":[]},{"id":"a090f6e.b37c408","type":"comment","z":"27d1839a.8c260c","name":"Tamper & Battery alerts","info":"","x":860,"y":140,"wires":[]},{"id":"8103e63f.f50498","type":"rbe","z":"27d1839a.8c260c","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":560,"y":260,"wires":[["8d38725.02ed89"]]},{"id":"3fba7250.7ba2ce","type":"debug","z":"27d1839a.8c260c","name":"Middle Top Window open alerts","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":320,"wires":[]},{"id":"3ac173b2.049a1c","type":"rbe","z":"27d1839a.8c260c","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":560,"y":320,"wires":[["3fba7250.7ba2ce"]]},{"id":"6c7cbb6a.1c5654","type":"inject","z":"27d1839a.8c260c","name":"48B5EE","props":[{"p":"payload.RfReceived.Data","v":"48B5EE","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":380,"y":40,"wires":[["56253c5d.49a5a4"]]},{"id":"36e5b508.b3096a","type":"inject","z":"27d1839a.8c260c","name":"48B5E7","props":[{"p":"payload.RfReceived.Data","v":"48B5E7","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":380,"y":80,"wires":[["56253c5d.49a5a4"]]},{"id":"4606d9fb.a64278","type":"mqtt-broker","z":"","name":"mosquitto","broker":"192.168.0.150","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"1","birthRetain":"true","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![baldfox](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/baldfox/32/30169_2.png) [@baldfox](https://discourse.nodered.org/u/baldfox)\
**Post date:** [13 October 2020 09:48 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/13 "2020-10-13T09:48:32Z")

</div>

Here's a write up I did recently regarding working with Telegram notifications. I'm taking sensor readings from Home-Assistant into Node-red, it should be pretty easy for you to swap in your MQTT payload. It might be of interest....

> **[A Guide to using Telegram with Node-red and Home-Assistant](https://www.thesmarthomebook.com/2020/10/13/a-guide-to-using-telegram-with-node-red-and-home-assistant/)**
>
> I thought I’d publish a post to show you how to use Telegram with Node-red. Telegram is an instant messaging platform with a great channel feature. It means that not only can you receive noti…

---

<div class="post-metadata">

**Author:** ![epicurean](https://avatars.discourse-cdn.com/v4/letter/e/7cd45c/32.png) [@epicurean](https://discourse.nodered.org/u/epicurean)\
**Post date:** [13 October 2020 12:37 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/14 "2020-10-13T12:37:47Z")

</div>

Thanks so much!  
Actually I am unfamiliar with anything node red . But I am trying to learn and understand the logic. Let me try to digest what you just shared.

regards

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 October 2020 13:49 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/15 "2020-10-13T13:49:34Z")

</div>

> [@epicurean](#):
>
> I am unfamiliar with anything node red

In that case please spend an hour or two watching the excellent Node Red Essentials videos linked from the node red docs pages. It will save much time in the long run.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 October 2020 13:49 UTC](https://discourse.nodered.org/t/newbie-query-how-to-design-flow-for-rf-sensor/33985/16 "2020-10-27T13:49:46Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
