# Retrieve the maximum temperature values for each month of the year

**URL:** <https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636>\
**Category:** General\
**Created:** [17 December 2020 10:37 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636 "2020-12-17T10:37:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 10:37 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/1 "2020-12-17T10:37:59Z")

</div>

Hello, I am a beginner, and I am trying to memorize the temperature of my sensor (max value) for each month.  
example:  
January: max temp 6.5 ° c  
february: max temp 12.4 °

I found the way to get the month and the temperature, but to link the 2? I appeal to you.  
thank you

```auto
[
    {
        "id": "9a301321.5665b",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": ""
    },
    {
        "id": "5d664bd2.b9a2d4",
        "type": "inject",
        "z": "9a301321.5665b",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 130,
        "y": 80,
        "wires": [
            [
                "f70b6c5.13fa81"
            ]
        ]
    },
    {
        "id": "3184516d.c808d6",
        "type": "debug",
        "z": "9a301321.5665b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 470,
        "y": 200,
        "wires": []
    },
    {
        "id": "f70b6c5.13fa81",
        "type": "function",
        "z": "9a301321.5665b",
        "name": "reccup mois",
        "func": "var now = new Date(); \nvar month = now.getMonth()+1; \nmsg.payload = month;\nmsg.topic = \"mois\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 310,
        "y": 80,
        "wires": [
            [
                "dc7a1b4.c9138e8"
            ]
        ]
    },
    {
        "id": "ed0fbb30.809c",
        "type": "inject",
        "z": "9a301321.5665b",
        "name": "",
        "topic": "",
        "payload": "15",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 90,
        "y": 240,
        "wires": [
            [
                "c4e9c65d.26937"
            ]
        ]
    },
    {
        "id": "dc7a1b4.c9138e8",
        "type": "function",
        "z": "9a301321.5665b",
        "name": "valeurs max",
        "func": "context.data = context.data || new Object();\nswitch (msg.topic) {\n case \"mois\":\n context.data.mois = msg.payload;\n msg = null;\n break;\n case \"valeur\":\n context.data.valeur = msg.payload;\n msg = null;\n break; \n default:\n msg = null;\n \tbreak;\n}\n\nlet valeur_max;\nif(context.data.mois == 12 && context.data.valeur >= valeur_max ) {\n valeur_max=valeur;\n msg.payload = msgOut;\n\treturn msg;\n} \n",
        "outputs": 1,
        "noerr": 0,
        "x": 310,
        "y": 200,
        "wires": [
            [
                "3184516d.c808d6"
            ]
        ]
    },
    {
        "id": "c4e9c65d.26937",
        "type": "function",
        "z": "9a301321.5665b",
        "name": "valeur",
        "func": "\nmsg.payload = msg.payload;\nmsg.topic = \"valeur\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 170,
        "y": 300,
        "wires": [
            [
                "dc7a1b4.c9138e8"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 December 2020 11:07 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/2 "2020-12-17T11:07:33Z")

</div>

Let me try to help you figure out the problem yourself. First off remove the interval in the `inject` node (so you don't flood the sidebar debug) then put a `debug` node on the output of the 'reccup mois' `function` node and on the output of the 'valeur' `function` node to make sure data is coming from both.

Next add a node.warn() in the 'valeurs max' `function` node after the first line. formate the node.warn like this: `node.warn("context.data = "& context.data)` so the first two lines are:

```auto
context.data = context.data || {};
node.warn("context.data = "& context.data)

```

deploy and run the your flow pressing each inject node.

What do the results tell you?

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 11:12 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/3 "2020-12-17T11:12:43Z")

</div>

thank you for helping me, but I have a lot of trouble understanding (I don't speak English, and I use translate)

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 11:21 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/4 "2020-12-17T11:21:00Z")

</div>

I'm not sure if I followed your recommendations, but on output I get "0" every second?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 December 2020 11:21 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/5 "2020-12-17T11:21:25Z")

</div>

voir si cela a plus de sens (See if this makes more sense.)

First off remove the interval in the `inject` node (so you don't flood the sidebar debug)  
Change  
 ![Screen Shot 2020-12-17 at 6.16.10 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/4127a2c7412fe0db49beac22e7e089ad21545f37.png)  
to  
 ![Screen Shot 2020-12-17 at 6.16.25 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/467dd2d88546350786732d3f21d5bd5ad3218bbf.png)

Next put a `debug` node on the output of the 'reccup mois' `function` node and on the output of the 'valeur' `function` node to make sure data is coming from both.

 ![Screen Shot 2020-12-17 at 6.20.30 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/0028bd4f13bb4c6b74d4b7bfde724120adb2b6f1.png)

Next add a node.warn() in the 'valeurs max' `function` node after the first line. formate the node.warn like this: `node.warn("context.data = "& context.data)` so the first two lines are:

```auto
context.data = context.data || {};
node.warn("context.data = "& context.data)

```

deploy and run the your flow pressing each inject node.

What do the results tell you?

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 11:23 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/6 "2020-12-17T11:23:30Z")

</div>

ok I redo your diagram, I will come back immediately

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 11:27 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/7 "2020-12-17T11:27:54Z")

</div>

if I click on time, I have output 0 and 12  
if i click on 15, i have output 0 and 15

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 11:31 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/8 "2020-12-17T11:31:02Z")

</div>

I'm sorry, I have to go eat (I'll be back at 1:00 p.m.)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 December 2020 12:02 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/9 "2020-12-17T12:02:59Z")

</div>

So the 12 and 15 are correct, but the output of the node.warn is 0.

So what do you expect `context.data` to be?

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 12:38 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/10 "2020-12-17T12:38:20Z")

</div>

I don't know, I'm lost!  
if I validate that the first ms.payload (the 2 others inactivated) with 1 pulse on time.stamp I have 0 and 12 on output; if a pulse on "15" then I only have 0 in output?  
I don't know what to think?

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 12:40 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/11 "2020-12-17T12:40:50Z")

</div>

in output of max value I always have 0 in output! either with input 15 or input time

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 12:41 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/12 "2020-12-17T12:41:47Z")

</div>

```auto
[
    {
        "id": "9a301321.5665b",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": ""
    },
    {
        "id": "5d664bd2.b9a2d4",
        "type": "inject",
        "z": "9a301321.5665b",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 100,
        "y": 160,
        "wires": [
            [
                "f70b6c5.13fa81"
            ]
        ]
    },
    {
        "id": "3184516d.c808d6",
        "type": "debug",
        "z": "9a301321.5665b",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 470,
        "y": 220,
        "wires": []
    },
    {
        "id": "f70b6c5.13fa81",
        "type": "function",
        "z": "9a301321.5665b",
        "name": "reccup mois",
        "func": "var now = new Date(); \nvar month = now.getMonth()+1; \nmsg.payload = month;\nmsg.topic = \"mois\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 230,
        "y": 100,
        "wires": [
            [
                "dc7a1b4.c9138e8",
                "18accb5a.f7085d"
            ]
        ]
    },
    {
        "id": "ed0fbb30.809c",
        "type": "inject",
        "z": "9a301321.5665b",
        "name": "",
        "topic": "",
        "payload": "15",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 90,
        "y": 240,
        "wires": [
            [
                "c4e9c65d.26937"
            ]
        ]
    },
    {
        "id": "dc7a1b4.c9138e8",
        "type": "function",
        "z": "9a301321.5665b",
        "name": "valeurs max",
        "func": "\ncontext.data = context.data || {};\nnode.warn(\"context.data = \"& context.data)",
        "outputs": 1,
        "noerr": 0,
        "x": 290,
        "y": 220,
        "wires": [
            [
                "3184516d.c808d6"
            ]
        ]
    },
    {
        "id": "c4e9c65d.26937",
        "type": "function",
        "z": "9a301321.5665b",
        "name": "reccup mois",
        "func": "\nmsg.payload = msg.payload;\nmsg.topic = \"valeur\"\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 190,
        "y": 300,
        "wires": [
            [
                "dc7a1b4.c9138e8",
                "47ed9bc7.b47a0c"
            ]
        ]
    },
    {
        "id": "18accb5a.f7085d",
        "type": "debug",
        "z": "9a301321.5665b",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 440,
        "y": 100,
        "wires": []
    },
    {
        "id": "47ed9bc7.b47a0c",
        "type": "debug",
        "z": "9a301321.5665b",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 420,
        "y": 340,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 13:22 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/13 "2020-12-17T13:22:54Z")

</div>

I apologize, but I would like to move forward in my project. Thank you for kindly showing me the solution to my problem, but I have a lot of trouble understanding you (problem of different languages) could you give me the final solution (I don't think there is much code?) I will then try to understand the instructions and use it for similar functions. it would save me a lot of time (I am on a project and here I am at a standstill)  
thank you for your understanding and above all for your help.  
this is in no way a criticism or reproach towards the forum, but I am blocked

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 13:34 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/14 "2020-12-17T13:34:33Z")

</div>

I added "return msg;" at the end of the "max value" function, now if I click on time I have 0 and 12 and if I click on 15 I have 0 and 15.  
this means, that when the "max value" function receives an information, it reads the 2 inputs but the input information is not stored (hence the value 0). I don't know how to fix it?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 December 2020 13:44 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/15 "2020-12-17T13:44:00Z")

</div>

in the function node:

```auto
context.data = context.data || new Object();
switch (msg.topic) {
    case "mois":
        context.data.mois = msg.payload;
        msg = null;
        break;
    case "valeur":
        context.data.valeur = msg.payload;
        msg = null;
        break;   
    default:
        msg = null;
    	break;
}

let valeur_max;
if(context.data.mois == 12 && context.data.valeur >= valeur_max ) {
    valeur_max=valeur;
    msg.payload = msgOut; <========== 
	return msg;
} 

```

MsgOut n'a jamais été défini. Voulez-vous enregistrer la valeur\_max la plus élevée et la mettre dans msg.payload?  
qu'est-ce que valeur\_max, vous ne l'avez jamais défini sur quoi que ce soit?

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 13:47 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/16 "2020-12-17T13:47:03Z")

</div>

I have a temperature sensor which gives me data every minute, I would like to record the max values ​​for each month of the year.  
January =\> 5 ° c  
February =\> 12 ° c  
for example

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 13:49 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/17 "2020-12-17T13:49:09Z")

</div>

hence my mini program with 2 inputs (time and a digital input) output I would like to have (12 outputs with the maximum values ​​that I will display)

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 13:50 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/18 "2020-12-17T13:50:30Z")

</div>

I'm coming back in 30 minutes (I'm going to pick up my daughter from school) and I'm back.  
Thanks again for your help !

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [17 December 2020 14:13 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/19 "2020-12-17T14:13:59Z")

</div>

Give me a few minutes

---

<div class="post-metadata">

**Author:** ![roro50](https://avatars.discourse-cdn.com/v4/letter/r/d6d6ee/32.png) [@roro50](https://discourse.nodered.org/u/roro50)\
**Post date:** [17 December 2020 14:36 UTC](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636/20 "2020-12-17T14:36:24Z")

</div>

hello i am

[Next page](https://discourse.nodered.org/t/retrieve-the-maximum-temperature-values-for-each-month-of-the-year/37636.md?page=2)
