Trying to chart high/low temp

hi i'm trying to make a chart for highest and lowest temperatures outside from an mqtt sensor. but am failing miserably, any sugestions where im going wrong would be great thanks
martin

[
    {
        "id": "558a976d1540e55c",
        "type": "group",
        "z": "d3637ed3c66aa0d7",
        "style": {
            "stroke": "#999999",
            "stroke-opacity": "1",
            "fill": "none",
            "fill-opacity": "1",
            "label": true,
            "label-position": "nw",
            "color": "#a4a4a4"
        },
        "nodes": [
            "e1cc8e5dcfa599e4",
            "8dc4a744a869b740",
            "6a492259f74bde19",
            "9e7148d9a5fcbfae",
            "b6ed25afa97b9f26",
            "5ae30d57abb32fac",
            "5269df838f656cd0"
        ],
        "x": 14,
        "y": 159,
        "w": 692,
        "h": 162
    },
    {
        "id": "e1cc8e5dcfa599e4",
        "type": "mqtt in",
        "z": "d3637ed3c66aa0d7",
        "g": "558a976d1540e55c",
        "name": "outside",
        "topic": "zone0/text",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "dc0340c9643bd396",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 90,
        "y": 240,
        "wires": [
            [
                "5269df838f656cd0",
                "5ae30d57abb32fac"
            ]
        ]
    },
    {
        "id": "8dc4a744a869b740",
        "type": "bar-chart-data2",
        "z": "d3637ed3c66aa0d7",
        "g": "558a976d1540e55c",
        "name": "bar-chart-data2",
        "x_interval": "days",
        "x_size": 24,
        "unit": "c",
        "precision": 2,
        "is_meter_reading": "False",
        "agg_by": "max",
        "x": 420,
        "y": 200,
        "wires": [
            [
                "6a492259f74bde19"
            ]
        ]
    },
    {
        "id": "6a492259f74bde19",
        "type": "ui_chart",
        "z": "d3637ed3c66aa0d7",
        "g": "558a976d1540e55c",
        "name": "",
        "group": "b5f7f90a2f77ea3d",
        "order": 4,
        "width": 18,
        "height": 5,
        "label": "lowest outside",
        "chartType": "bar",
        "legend": "true",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 600,
        "y": 200,
        "wires": [
            []
        ]
    },
    {
        "id": "9e7148d9a5fcbfae",
        "type": "bar-chart-data2",
        "z": "d3637ed3c66aa0d7",
        "g": "558a976d1540e55c",
        "name": "bar-chart-data2",
        "x_interval": "days",
        "x_size": 24,
        "unit": "c",
        "precision": 2,
        "is_meter_reading": "False",
        "agg_by": "max",
        "x": 420,
        "y": 280,
        "wires": [
            [
                "b6ed25afa97b9f26"
            ]
        ]
    },
    {
        "id": "b6ed25afa97b9f26",
        "type": "ui_chart",
        "z": "d3637ed3c66aa0d7",
        "g": "558a976d1540e55c",
        "name": "",
        "group": "b5f7f90a2f77ea3d",
        "order": 3,
        "width": 18,
        "height": 5,
        "label": "highest outside",
        "chartType": "bar",
        "legend": "true",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 600,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "5ae30d57abb32fac",
        "type": "smooth",
        "z": "d3637ed3c66aa0d7",
        "g": "558a976d1540e55c",
        "name": "lowest",
        "property": "payload",
        "action": "min",
        "count": "10",
        "round": "",
        "mult": "single",
        "reduce": true,
        "x": 270,
        "y": 200,
        "wires": [
            [
                "8dc4a744a869b740"
            ]
        ]
    },
    {
        "id": "5269df838f656cd0",
        "type": "smooth",
        "z": "d3637ed3c66aa0d7",
        "g": "558a976d1540e55c",
        "name": "highest",
        "property": "payload",
        "action": "max",
        "count": "10",
        "round": "",
        "mult": "single",
        "reduce": true,
        "x": 260,
        "y": 280,
        "wires": [
            [
                "9e7148d9a5fcbfae"
            ]
        ]
    },
    {
        "id": "dc0340c9643bd396",
        "type": "mqtt-broker",
        "name": "",
        "broker": "192.168.0.107",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "b5f7f90a2f77ea3d",
        "type": "ui_group",
        "name": "Group 1",
        "tab": "eaa84631f407bcd4",
        "order": 1,
        "disp": true,
        "width": "18",
        "collapse": false,
        "className": ""
    },
    {
        "id": "eaa84631f407bcd4",
        "type": "ui_tab",
        "name": "daily temperatures",
        "icon": "dashboard",
        "order": 5,
        "disabled": false,
        "hidden": false
    },
    {
        "id": "5ef6f7ccfc351005",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-contrib-dashboard-bar-chart-data2": "0.9.101",
            "node-red-dashboard": "3.6.6",
            "node-red-node-smooth": "0.1.2"
        }
    }
]





Hi.

Sorry for my short reply as I am about to go out for today.

So you get your value and want to put the highest and lowest values on a chart.

Looking at what you have in the last picture, here's my thought/s.

The values need to be reset daily. Or the pervious day's values with taint (have an affect) on TODAY'S.

I'm not sure how good you are with node-red (no offence meant) but maybe a function node.

(Off the top of my head)

if (msg.topic == "NEWDAY")
{
    // You need to reset values
    //  you need to add stuff here.
    context.set('previous_max',0)
    context.set('previous_min',100)
    return   // exit.
}

let previous_max = context.get('previous_max) || 0
let previous_min = context.get('previous_min) || 100

//  get the temperature.
const temperature = msg.payload.

if (temperature > previous_max)
{
    //
    context.set('previous_max',temperature)
    msg.topic = 'maximum'
    return msg
}

if (temperature < previous_min)
{
    //
    context.set('previous_min',temperature)
    msg.topic = 'minimum'
    return msg
}

That was done here, now. Not in node-red.
So please check it a bit more than just hoping it works.
(Sorry.)

That is a starting point.

Each day at midnight, you need to send a message into the node with a topic NEWDAY to reset the values.

I did a quick attempt to set them.

Hope it helps get you on the way.

1 Like

I'll give it a try thanks
martin

Can you describe in more detail what you mean by that? The highest and lowest for the day? The highest and lowest over each hour? Or what?

Edit: Also, are the values coming in from mqtt at a regular interval?

hi the highest and lowest temperature for the day,
and yes temperature arrives every two minutes from mqtt.
the message is

(I'm back.)

From that function node, you send the data through a switch node to separate the max from min values.

Sorry I didn't explain that but I was kinda rushed.

Doesn't that need an else round the rest of the function if topic is NEWDAY, in order to stop the payload in that message being interpreted as a temperature?

An improvement might be to have two outputs and send the value to one for min and the other for max.

The if returns nothing if NEWDAY is matched, which will exit the function.

@Trying_to_learn 2 outputs would be a good idea to avoid a switch node, also the min/max values should be more like max -99 min 99, just to be on the safe side, as MQTT shows negative values.

That is the correct behaviour. Sending in the newday topic resets the context variables so when the next value comes in it will be handled. I am assuming that the newday topic will not have a value from mqtt in it.

However, there is another case not handled, the first sample after the reset should send to both max and min outputs.

@Colin ,

Yes, you are right and THE first message after the NEWDAY should send both Max and Min values.

Maybe 2 outputs would be better, that way 2 messages could be sent.

(Not at /to you)
The code I posted was an EXAMPLE to show the structure of what to do.

I'm not sure if missing one message per day would be a deal breaker in this scenario.

@montyfert ,

Just wondering how it's going?

hi thanks for the quick responses, unfortunately I'ts a bit over my head i tried adding the script to a function node , but received an error

Looks like you are missing the closing single quote on the name of your context variable.

2 Likes

There are two mistakes in the code I posted.
That one and the line with previous_Min in it too.
I didn't close the ' at the end of the line like with this line.

Sorry.

1 Like

no worries , ive done that but still getting warning ,

if (msg.topic == "NEWDAY") {
    // You need to reset values
    //  you need to add stuff here.
    context.set('previous_max', 0)
    context.set('previous_min', 100)
    return   // exit.
}

let previous_max = context.get('previous_max') || 0
let previous_min = context.get('previous_min') || 100

//  get the temperature.
const temperature = msg.payload.

    if(temperature > previous_max)
{
    //
    context.set('previous_max', temperature)
    msg.topic = 'maximum'
    return msg
}

if (temperature < previous_min) {
    //
    context.set('previous_min', temperature)
    msg.topic = 'minimum'
    return msg
}

What warning?

1 Like

hi


remove the . after payload

2 Likes

Sorry folks.

I am running a few different formatting rules and sometimes the punctuation rule sneaks in and adds . at the end of lines.

Sometimes good, sometimes not.

1 Like

thanks all for all the help your stars.
martin

Curious.

How did you solve it?