# Compare Meter Reading with InfluxDB Function

**URL:** <https://discourse.nodered.org/t/compare-meter-reading-with-influxdb-function/69253>\
**Category:** General\
**Tags:** database, function-node, mqtt\
**Created:** [19 October 2022 11:38 UTC](https://discourse.nodered.org/t/compare-meter-reading-with-influxdb-function/69253 "2022-10-19T11:38:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Starfoxfs](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/starfoxfs/32/69119_2.png) [@Starfoxfs](https://discourse.nodered.org/u/Starfoxfs)\
**Post date:** [19 October 2022 11:38 UTC](https://discourse.nodered.org/t/compare-meter-reading-with-influxdb-function/69253/1 "2022-10-19T11:38:56Z")

</div>

Hi,

I have a big problem. I am a newbie and would like to compare the total meter reading from the influxdb with the electricity meter. If the value of the electricity meter is 0 (because of a power failure, for example), all newly collected values ​​of the electricity meter should be added to the value from the InfluxDB.

Thanks in advance

---

<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:** [19 October 2022 12:03 UTC](https://discourse.nodered.org/t/compare-meter-reading-with-influxdb-function/69253/2 "2022-10-19T12:03:32Z")

</div>

Which bits of that do you not know how to do?

---

<div class="post-metadata">

**Author:** ![Starfoxfs](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/starfoxfs/32/69119_2.png) [@Starfoxfs](https://discourse.nodered.org/u/Starfoxfs)\
**Post date:** [19 October 2022 12:56 UTC](https://discourse.nodered.org/t/compare-meter-reading-with-influxdb-function/69253/3 "2022-10-19T12:56:26Z")

</div>

All 😀

I create a Node for Query for Read the "Total" Energy Consumption from the InfluxDB

Query Node is this:

```auto
msg.query='SELECT wh_total FROM "xx" ORDER BY time DESC LIMIT 1'
return msg;

```

Ok now i have the Query as an Array out of the Database.

Now i have to compare current Data from Shelly with InfluxDB Data

something like:

```auto
if (wh_total == 0)
{
Add Data from Influxdb and add actually wh_total data on top of this
}else
its ok do nothing
}

```

---

<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:** [19 October 2022 20:41 UTC](https://discourse.nodered.org/t/compare-meter-reading-with-influxdb-function/69253/4 "2022-10-19T20:41:33Z")

</div>

In order to do what you ask it is necessary to get the data from the query and that from the meter into one message. See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

However, there may be a better way of solving the problem. Can I ask a question? Why do you need to know the total consumption (since some arbitrary time in past, presumably)? Is it in fact the case that you don't need to know the absolute running total, but what you want to know is how much has been used today, or last year, or similar?

---

<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:** [18 December 2022 20:42 UTC](https://discourse.nodered.org/t/compare-meter-reading-with-influxdb-function/69253/5 "2022-12-18T20:42:05Z")

</div>

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