# Email alert when sensor battery is low

**URL:** <https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525>\
**Category:** General\
**Created:** [14 January 2024 01:03 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525 "2024-01-14T01:03:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkenobi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bkenobi/32/59825_2.png) [@bkenobi](https://discourse.nodered.org/u/bkenobi)\
**Post date:** [14 January 2024 01:03 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/1 "2024-01-14T01:03:24Z")

</div>

I have a flow that processes my Acurite temperature/humidity sensors sent from rtl\_433 via MQTT. One of the fields the sensor provides is a battery\_ok value which is 1 when normal and returns 0 when it drops below a predefined threshold.

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

I have some code that I thought would work but today when this sensor transitioned from 1 to 0 I ended up getting dozens of emails. I am assuming that's because it wasn't a clean transition from 1 to 0. I'd appreciate any recommendations that could be provided.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/753553aab9afd21230c240078b617a6e7c24ac40.png)

This is the battery notification section less the email generation itself.

```auto
[{"id":"95956d64.1c802","type":"switch","z":"b76701c5.7313f","name":"","property":"payload.battery_ok","propertyType":"msg","rules":[{"t":"lt","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1110,"y":260,"wires":[["47cfdca2.e40a04","9eee43be.5f0678"]]},{"id":"47061126.bf4668","type":"comment","z":"b76701c5.7313f","name":"battery notification","info":"","x":850,"y":220,"wires":[]},{"id":"f6e008da.ac0fc","type":"change","z":"b76701c5.7313f","name":"","rules":[{"t":"delete","p":"payload.time","pt":"msg"},{"t":"delete","p":"payload.tempF","pt":"msg"},{"t":"delete","p":"payload.temperature_C","pt":"msg"},{"t":"delete","p":"payload.humidity","pt":"msg"},{"t":"delete","p":"payload.moisture","pt":"msg"},{"t":"delete","p":"payload.moisture_offset","pt":"msg"},{"t":"set","p":"topic","pt":"msg","to":"payload.id","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":260,"wires":[["88ceb81.c18a1c8"]]},{"id":"88ceb81.c18a1c8","type":"rbe","z":"b76701c5.7313f","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload.battery_ok","x":990,"y":260,"wires":[["95956d64.1c802"]]}]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [14 January 2024 01:09 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/2 "2024-01-14T01:09:37Z")

</div>

You can use a delay node to limit the number of emails, for example 1 per day:

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

ps you asked a similar question 6 months ago, I think this answer is better than my suggestion then!

---

<div class="post-metadata">

**Author:** ![bkenobi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bkenobi/32/59825_2.png) [@bkenobi](https://discourse.nodered.org/u/bkenobi)\
**Post date:** [14 January 2024 01:38 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/3 "2024-01-14T01:38:43Z")

</div>

I should have mentioned the previous question and even linked it. I decided not to bump an old thread and rather ask again in a slightly different way (since I now have working code). I used those suggestions here but now that I have an example of a battery dying (first time the code has triggered) I realized that it does not work as I had hoped. Ideally I would have it so the trigger would see the battery\_ok drop below zero and then send 1 message per day. But I think having the property go back up to 1 might reset things. I'll try the delay and see if that helps. So far today I have over 40 notifications that one battery is dying.

---

<div class="post-metadata">

**Author:** ![bkenobi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bkenobi/32/59825_2.png) [@bkenobi](https://discourse.nodered.org/u/bkenobi)\
**Post date:** [14 January 2024 01:53 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/4 "2024-01-14T01:53:23Z")

</div>

I added the delay and can see the battery\_ok oscillating but no new emails. I'm going to reduce the frequency to 10 minutes to test that it's working as intended but it looks like this should be a viable fix. Thanks!

---

<div class="post-metadata">

**Author:** ![bkenobi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bkenobi/32/59825_2.png) [@bkenobi](https://discourse.nodered.org/u/bkenobi)\
**Post date:** [14 January 2024 03:13 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/5 "2024-01-14T03:13:09Z")

</div>

The sensor is being a bit finicky now but it does appear that the 10 minute delay is working. I have a lot of various sensors so will implement this in each location. Thanks for the suggestions (this time and last)!

---

<div class="post-metadata">

**Author:** ![FeliceM](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@FeliceM](https://discourse.nodered.org/u/FeliceM)\
**Post date:** [14 January 2024 07:29 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/6 "2024-01-14T07:29:34Z")

</div>

I have something very similar in place to monitor a Victron ESS installation. I use a couple of variables in context to monitor if the status has changed and a delay node to filter out fast transitions between 0/1. The combination of the two makes it stable.

---

<div class="post-metadata">

**Author:** ![Buckskin](https://avatars.discourse-cdn.com/v4/letter/b/b9e5f3/32.png) [@Buckskin](https://discourse.nodered.org/u/Buckskin)\
**Post date:** [14 January 2024 19:37 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/7 "2024-01-14T19:37:33Z")

</div>

You may want to put in a longer delay before notification, or another notification that the the battery is definitely dead.

I don't know about your sensors but I have an Oregon-THGR810 (temperature/ humidity sensor) that has been claiming a low battery for the last 2 months, and is still going. (same` battery_ok` attribute of 1 or 0)

---

<div class="post-metadata">

**Author:** ![bkenobi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bkenobi/32/59825_2.png) [@bkenobi](https://discourse.nodered.org/u/bkenobi)\
**Post date:** [2 February 2024 03:31 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/8 "2024-02-02T03:31:06Z")

</div>

I don't know the actual dead point but if I could figure it out, I could estimate how long it would take to actually die and then notify once a week until I got to the real critical time and then once per day. And if I really knew what I was doing, have something in the flow that looks for the last time the sensor sent data and if it was more than a threshold value, send a notice saying the sensor's battery died. But then, I tried that and it didn't work. I've got something that appears to be working now so I'll watch it for a while and see if I need to tweak any further.

---

<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:** [2 April 2024 03:31 UTC](https://discourse.nodered.org/t/email-alert-when-sensor-battery-is-low/84525/9 "2024-04-02T03:31:53Z")

</div>

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