Giter Club home page Giter Club logo

Comments (7)

Programie avatar Programie commented on August 17, 2024 1

OK, now I get it.

In my case I'm writing the temperature values into an InfluxDB. But this causes another issue: If there is no change in the value (e.g. target value of the intelligent room controller), I can't see any values if InfluxDB should give me the data of the last few hours but the value hasn't changed in the given time range. Therefore I want to save the data in a constant interval into InfluxDB (e.g. every minute).

My current workaround for that is to use a trigger node between the control-in and influxdb nodes. But this decreases the readability and manageability of my flows as I have to use 4 nodes for each value I want to write into InfluxDB:

[ control-in (specific room + category) ] -> [ trigger (every minute) ] -> [ function ] -> [ influxdb ]

The function node only formats the message for writing it into InfluxDB.

At least I can reuse the function and influxdb for all temperature values. So all trigger nodes are connected to a single function and influxdb node.

My previous flow looked like the following but had the issue of not writing anything to InfluxDB if the value doesn't change:

[ stream-in (category "Temperature") ] -> [ function ] -> [ influxdb ]

So imagined getting something like this (which is not possible by design):

[ inject (every minute) ] -> [ stream-in (category "Temperature") ] -> [ function ] -> [ influxdb ]

Anyway, looks like I have to stay with the "use a trigger for every value"-method.

from node-red-contrib-loxone.

codmpm avatar codmpm commented on August 17, 2024 1

Maybe use nodered's context in a function node which get's triggered to compare the value and give's the unchanged one again to influx.

Nevertheless, grafana handles the "missing" values very well. At least to my experience.

from node-red-contrib-loxone.

Programie avatar Programie commented on August 17, 2024 1

Grafana can handle the missing values. But if you have some values which are not changing every few minutes and, for example, show a graph for the last hour, the graph shows a NULL value till the first change of that value.

Take the following example data for a single value (time stamps at which the data was written to InfluxDB):

2018-01-18 14:00
2018-01-18 14:05
2018-01-18 14:10
2018-01-18 14:40
2018-01-18 14:45
2018-01-18 15:35

Now you show the data in Grafana and select "2018-01-18 15:00" till "2018-01-18 16:00" as time range.

Grafana shows a graph which starts at 15:00 but without any data. The first data point is at 15:35.

If the data is written to InfluxDB in a constant interval, there would be a data point at 15:00 with the data from 14:45 so Grafana can show the data in the correct way.

Of course this would increase the disk usage of the database, but storing a few bytes every minute is not that much these days. You may also aggregate old data to only store the average of 1 hour or something like that.

from node-red-contrib-loxone.

thmeger avatar thmeger commented on August 17, 2024

No Problem. Just use:
Inject -> webservice -> debug

from node-red-contrib-loxone.

codmpm avatar codmpm commented on August 17, 2024

Hey @Programie,

as node-red does not save any of the messages that "come in" via an event, it is up to you to store them if you need them later. The control-in/stream-in nodes get triggered from the miniserver with an event in the websocket connection.
All data is send by the miniserver when node-red-contrib-loxone connects, so thats why you get it on re-deploy/re-connect. Try to not "full-deploy" to not reset the connection every time you change something in your flow.

So as solution you can, as @thmeger suggested, use a webservice-node to trigger a read against the miniserver to get the data when you want. The miniserver "holds" the last value of the event (e.g. read temp).
Or you can - and I think this is the right solution - store the values as you receive them. You can use node-red's context, a flatfile (json?) or a database like sqlite/mysql/influx/mongodb. So you can read them from your database whenever you need them.

Bear in mind, that node-red builds the logic. node-red-contrib-loxone is only the "bridge" to connect the miniserver:

You will get the data from Loxone's websocket as is. There is and will be no abstraction layer!

from node-red-contrib-loxone.

thmeger avatar thmeger commented on August 17, 2024

I have the exact usecase running. Stream-in nodes -> influxDB. This way, you only get data-points in your influxDB if a values has changed. I think, this is ok. You can configure the Grafana diagram to handle them the way you want it to be displayed.

from node-red-contrib-loxone.

Programie avatar Programie commented on August 17, 2024

Storing data in a node's context is probably the best way to solve this issue.

I now did it in the following way:

[ stream-in (category "Temperature") ] + [ inject (repeat every 1 minute, topic: "TriggerFlow") ] -> [ function (see function node 1 bellow) ] -> [ function (see function node 2 bellow) ] -> [ influxdb ]

I'm using the following two function nodes:

Function node 1:

var data = context.get("data") || {};

if (msg.topic == "TriggerFlow") {
    return {
        payload: data
    };
} else {
    if (msg.state == "value" && msg.type == "InfoOnlyAnalog") {
        if (msg.room == "Outside") {
            area = "Outside";
            room = "";
        } else {
            area = "OG";
            room = msg.room;
        }
        
        if (!data.hasOwnProperty(area)) {
            data[area] = {};
        }
        
        if (!data[area].hasOwnProperty(room)) {
            data[area][room] = {};
        }
    
        data[area][room][msg.topic] = msg.payload;
    
        context.set("data", data);
    }
    
    return null;
}

Function node 2:

var points = [];

for (var area in msg.payload) {
    for (var room in msg.payload[area]) {
        for (var name in msg.payload[area][room]) {
            points.push([
                {
                    value: msg.payload[area][room][name]
                },
                {
                    "area": area,
        	    "room": room === "" ? null : room,
        	    "name": name
                }
            ]);
        }
    }
}

return {
    payload: points
};

from node-red-contrib-loxone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.