# Trigger periodically a value to database

**URL:** <https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798>\
**Category:** General\
**Created:** [26 January 2021 16:38 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798 "2021-01-26T16:38:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [26 January 2021 16:38 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798/1 "2021-01-26T16:38:13Z")

</div>

Hi !

is it possible to trigger a value every day at 0:00h and write it to influxdb ?

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7a4220c49bb4744ef8b9f762652866e56ba36c5.png)

this are the values from the integrated heat meter of my heat pump.

I would like to build the consumption of every month / year.

January: value of 1.2. - value of 1.1. = ...

if influx is not necessary... even better 😉

greetings

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [26 January 2021 20:25 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798/2 "2021-01-26T20:25:44Z")

</div>

The built-in `inject` node has an option to send its message at a given time on selected days...

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

Wire that to the logic that reads the kWh value and pushes it to the database. InfluxDb is not the only database you could use, but it is nice for time-series data, like this. Since you want to keep a long-term history, I would say a database is the right tool, especially if you plan to query for the data later in order to build reports or graphs.

A lighter-weight solution would be to write the data into a CSV file, or a local file-based database like sqlitedb. Search the [flows.nodered.org](http://flows.nodered.org) site for example flows that do something similar...

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [27 January 2021 17:23 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798/3 "2021-01-27T17:23:04Z")

</div>

thx.  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b8117424c1b163e6dc0aa522cd4370a7ce607df5.png)  
so I can feed Influxdb every day 0:00 🙂

is it possible to calculate with the values in Grafana ?

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [29 January 2021 10:24 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798/4 "2021-01-29T10:24:20Z")

</div>

does somebody know how to get the values from influxdb back in Node Red ?

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

I have no idea, and every thing I found doesn´t work.

---

<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:** [29 January 2021 10:38 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798/5 "2021-01-29T10:38:20Z")

</div>

Which version of influx are you using (1.8 or 2.0)?

I see you have selected, in the influx node, v1.8 using the flux query language. Unless you want to use flux then just select 1.8 (assuming you are using 1.8). Then you can query the database using the SQL like query language. [Influx Query Language (InfluxQL) | InfluxDB OSS 1.8 Documentation](https://docs.influxdata.com/influxdb/v1.8/query_language/)

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [29 January 2021 13:15 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798/6 "2021-01-29T13:15:39Z")

</div>

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d54fe148822acc95ed0057213a5b5bb8883f1943.png)

I got the values, I had to change the server from 1,8 to 1,x.

Does anybody know how to calculate the values by time series?

I want: value of 2021-02-01 "-" value of 2021-01-01 = \_\_\_\_\_ calculate.

---

<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:** [29 January 2021 13:53 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798/7 "2021-01-29T13:53:10Z")

</div>

I don't think that influx 1.8 supports that, though I believe 2.0 does. I think it is possible in grafana using timeshift but I don't know exactly how.

I have avoided this problem by also storing the difference from the last value in the influx record. Then you can use cumulativeSum to add them up between two times.

---

<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:** [30 March 2021 13:53 UTC](https://discourse.nodered.org/t/trigger-periodically-a-value-to-database/39798/8 "2021-03-30T13:53:24Z")

</div>

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