# Trying to chart high/low temp

**URL:** <https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775>\
**Category:** Dashboard\
**Created:** [25 November 2025 18:43 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775 "2025-11-25T18:43:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![montyfert](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@montyfert](https://discourse.nodered.org/u/montyfert)\
**Post date:** [25 November 2025 18:43 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/1 "2025-11-25T18:43:01Z")

</div>

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

```auto
[
    {
        "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"
        }
    }
]

```

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/e/5e696d9e2ea2fefdcfb552869a58945389f8fe65.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b7666a3b4fd043a74279fa7e4fb10e9ad60e0461.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/178fd21852eec312383fdd422b3a385151bd1968.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/9/5961efcb1b79afcd1b25270e639427006d278e0a.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/5014662d3900e7097fefe0bb244116bad0fb4ee1.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [25 November 2025 20:47 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/2 "2025-11-25T20:47:38Z")

</div>

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)

```auto
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.

---

<div class="post-metadata">

**Author:** ![montyfert](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@montyfert](https://discourse.nodered.org/u/montyfert)\
**Post date:** [25 November 2025 20:59 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/3 "2025-11-25T20:59:18Z")

</div>

I'll give it a try thanks  
martin

---

<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:** [25 November 2025 21:04 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/4 "2025-11-25T21:04:58Z")

</div>

> [@montyfert](#):
>
> make a chart for highest and lowest temperatures

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?

---

<div class="post-metadata">

**Author:** ![montyfert](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@montyfert](https://discourse.nodered.org/u/montyfert)\
**Post date:** [25 November 2025 23:45 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/5 "2025-11-25T23:45:44Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/67fa11ebe63dc316a0d07e2e9e92f9f78952550c.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [26 November 2025 06:07 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/6 "2025-11-26T06:07:37Z")

</div>

(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.

---

<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:** [26 November 2025 09:34 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/7 "2025-11-26T09:34:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [26 November 2025 13:53 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/8 "2025-11-26T13:53:18Z")

</div>

> [@Colin](#):
>
> Doesn't that need an `else`

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.

---

<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:** [26 November 2025 15:12 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/9 "2025-11-26T15:12:33Z")

</div>

> [@Sean-McG](#):
>
> The if returns nothing if NEWDAY is matched, which will exit the function.

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [27 November 2025 20:44 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/10 "2025-11-27T20:44:36Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![montyfert](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@montyfert](https://discourse.nodered.org/u/montyfert)\
**Post date:** [28 November 2025 01:10 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/11 "2025-11-28T01:10:29Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [28 November 2025 02:33 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/12 "2025-11-28T02:33:02Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 November 2025 03:49 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/13 "2025-11-28T03:49:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![montyfert](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@montyfert](https://discourse.nodered.org/u/montyfert)\
**Post date:** [28 November 2025 13:37 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/14 "2025-11-28T13:37:56Z")

</div>

no worries , ive done that but still getting warning ,

```auto
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
}

```

---

<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:** [28 November 2025 14:04 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/15 "2025-11-28T14:04:29Z")

</div>

What warning?

---

<div class="post-metadata">

**Author:** ![montyfert](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@montyfert](https://discourse.nodered.org/u/montyfert)\
**Post date:** [28 November 2025 14:19 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/16 "2025-11-28T14:19:33Z")

</div>

hi

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c54d5419f5bfa667697a9a4d368a7842849bb98d.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/6/d634fb8239e826739997f4a6a4d1c7d7f313a533.png)

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [28 November 2025 14:45 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/17 "2025-11-28T14:45:44Z")

</div>

> [@montyfert](#):
>
> `const temperature = msg.payload.`

remove the . after payload

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [28 November 2025 20:36 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/18 "2025-11-28T20:36:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![montyfert](https://avatars.discourse-cdn.com/v4/letter/m/54ee81/32.png) [@montyfert](https://discourse.nodered.org/u/montyfert)\
**Post date:** [30 November 2025 20:59 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/19 "2025-11-30T20:59:52Z")

</div>

thanks all for all the help your stars.  
martin

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [1 December 2025 05:18 UTC](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775/20 "2025-12-01T05:18:29Z")

</div>

Curious.

How did you solve it?

[Next page](https://discourse.nodered.org/t/trying-to-chart-high-low-temp/99775.md?page=2)
