# Ideas for comparing week-over-week values

**URL:** <https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799>\
**Category:** General\
**Created:** [16 September 2022 11:30 UTC](https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799 "2022-09-16T11:30:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [16 September 2022 11:30 UTC](https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799/1 "2022-09-16T11:30:24Z")

</div>

Hello. We have an ammonia tank that get depleted over about 8 weeks, then refilled. The tank has a meter that transmits its status once a week (every Friday about 16:33). The data looks like this:

```auto
array[1]
0: object
LastReported: "2022-09-09T16:33:58"
LastReportedPercent: 75

```

We grab this info via Node-RED, store it in Influx, and display in Grafana as a gauge.

We ran into an issue where the meter failed (stopped transmitting). As a result, the LastReportedPercent value did not change for several weeks, went unnoticed, and we ran out of ammonia.

There are probably many ways to prevent this from happening (including Influx or Grafana alerts), but I would like to keep this in the Node-RED camp, such as:

- Store LastReportedPercent in context and compare with incoming value every Friday at 16:33. If it has not changed vs the value stored in context, send off an email alert to someone.
- If no value received in 8 days, send off an email alert to someone.

Can anyone suggest another (easy) way to catch this using standard Nodes if possible?....I can muster my way through javascript if I have to.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 September 2022 11:53 UTC](https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799/2 "2022-09-16T11:53:23Z")

</div>

You should be able to do this with a simple trigger node set something like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/91547f5c506e895d4ef930d316efd6276c70c260.png)

An inbound update will cause the trigger to reset and if another message isn't received in just over a week, it will send a msg to the second output port.

---

<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:** [16 September 2022 12:23 UTC](https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799/3 "2022-09-16T12:23:11Z")

</div>

In order to cope better with things like node red restarts you could run a completely separate watchdog flow that runs daily that looks at the most recent records in influx and

1. Checks that it is not more than 8 days since the last update.
2. Checks that the difference between the last two samples is sensible.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [16 September 2022 12:50 UTC](https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799/4 "2022-09-16T12:50:51Z")

</div>

Thanks to both of you.

I should have clarified that we do not currently store the LastReported date in Influx. I think I tried once, but I think I needed to fix something with the datatype (date vs. string-that-looks-like-a-date). I will revisit and use Colin's approach, but will also set up Julian's dead-simple method (and btw, I never would have thought to use a trigger node).

---

<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:** [16 September 2022 13:20 UTC](https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799/5 "2022-09-16T13:20:20Z")

</div>

> [@grant1](#):
>
> we do not currently store the LastReported date in Influx

And you shouldn't need to. You just need to look at the timestamps of the last two records.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/grant1/32/49890_2.png) [@grant1](https://discourse.nodered.org/u/grant1)\
**Post date:** [16 September 2022 13:25 UTC](https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799/6 "2022-09-16T13:25:07Z")

</div>

Oh brilliant! I don't know why I did not make that connection. Will write the Flux query shortly...

---

<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:** [15 November 2022 13:25 UTC](https://discourse.nodered.org/t/ideas-for-comparing-week-over-week-values/67799/7 "2022-11-15T13:25:31Z")

</div>

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