# Beginner: test on a variable

**URL:** <https://discourse.nodered.org/t/beginner-test-on-a-variable/36284>\
**Category:** Dashboard\
**Created:** [21 November 2020 10:50 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284 "2020-11-21T10:50:06Z")\
**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:** [21 November 2020 10:50 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/1 "2020-11-21T10:50:06Z")

</div>

hello again, new question:  
I get the data from openweathermap and I would like to test if the site announces water within 10 minutes, if so: I would like to display a message on the "rain" dasboard otherwise do not display a message

for that I use a "template" block that I program as follows:

```
<div layout="column" style="padding:10px" layout-align="center center">
<span if="msg.payload.minutely[0].weather[0].0.precipitation!=='0' || msg.payload.current.weather[0].1.precipitation!=='0'" style="color:#F89606;font-size:30px!important">Pluie dans 10mn </span>

```

I know this is wrong, syntax error and such? ? but I don't know this language.  
thank you for completing my example "as a model" I will then adapt it for my application.

it is all the more difficult for me who does not know English! I use Translate

merci !

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 November 2020 11:59 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/2 "2020-11-21T11:59:53Z")

</div>

Here is an example of how to do something like you require.

```auto
[{"id":"8b40e32d.d25c28","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"payload1","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":70,"y":1920,"wires":[["1f45c3d1.ba19d4"]]},{"id":"1f45c3d1.ba19d4","type":"function","z":"8d22ae29.7df6d","name":"","func":"if (msg.payload !== 0 || msg.payload1 !== 0){\n msg.payload =\"this_or_that\" ;\n}else{\n msg.payload =\"someting_else\";\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":100,"y":1980,"wires":[["dbfc5111.f750f"]]},{"id":"dbfc5111.f750f","type":"template","z":"8d22ae29.7df6d","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<div layout=\"column\" style=\"padding:10px\" layout-align=\"center center\">\n<span {{payload}} style=\"color:#F89606;font-size:30px!important\">Pluie dans 10mn </span>","output":"str","x":280,"y":2000,"wires":[["5e1bd60c.64727"]]},{"id":"9a2456c2.50e52","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"payload1","v":"0","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":70,"y":2040,"wires":[["1f45c3d1.ba19d4"]]},{"id":"5e1bd60c.64727","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":1980,"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:** [21 November 2020 13:11 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/3 "2020-11-21T13:11:55Z")

</div>

thank you for your answer, I understand the principle but it does not work?  
I always have the same message at the exit of the "if" block  
"this or that " whatever the entries at 0 or 1?  
it's like the test doesn't work? too much space? less? I do not see ? ? ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 November 2020 13:28 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/4 "2020-11-21T13:28:43Z")

</div>

working here,

 ![Screenshot_20201121-132641](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/4/8406a94349541660d1005505f21c23b8cdc108c7.png)  
you must be doing something wrong, it would help to post your flow.  
export your flow and post it between backticks like below  
```  
code  
```

---

<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:** [21 November 2020 13:45 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/5 "2020-11-21T13:45:53Z")

</div>

I put the ms.playload in output of the function block "f" in if I click on "1" or "0" in input, I still have "this\_or\_that" in output?

note: the 3 blocks below I do not? but i think this is normal.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 November 2020 13:49 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/6 "2020-11-21T13:49:35Z")

</div>

Post your flow. We need to see it to help.

---

<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:** [21 November 2020 13:53 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/7 "2020-11-21T13:53:05Z")

</div>

```auto
[
    {
        "id": "32101327.45e60c",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "e8088b08.89c7e",
        "type": "inject",
        "z": "32101327.45e60c",
        "name": "",
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 70,
        "y": 120,
        "wires": [
            [
                "5982aa54.8a682c"
            ]
        ]
    },
    {
        "id": "5982aa54.8a682c",
        "type": "function",
        "z": "32101327.45e60c",
        "name": "",
        "func": "if (msg.payload !== 0 || msg.payload1 !== 0){\n msg.payload =\"yes\" ;\n}else{\n msg.payload =\"no\";\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 100,
        "y": 180,
        "wires": [
            [
                "fe3f8bb1.9f187",
                "87adfc8.da81"
            ]
        ]
    },
    {
        "id": "fe3f8bb1.9f187",
        "type": "template",
        "z": "32101327.45e60c",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "<div layout=\"column\" style=\"padding:10px\" layout-align=\"center center\">\n<span {{payload}} style=\"color:#F89606;font-size:30px!important\">Pluie dans 10mn </span>",
        "output": "str",
        "x": 280,
        "y": 200,
        "wires": [
            []
        ]
    },
    {
        "id": "cd271618.49753",
        "type": "inject",
        "z": "32101327.45e60c",
        "name": "",
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 70,
        "y": 240,
        "wires": [
            [
                "5982aa54.8a682c"
            ]
        ]
    },
    {
        "id": "87adfc8.da81",
        "type": "debug",
        "z": "32101327.45e60c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 490,
        "y": 180,
        "wires": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 November 2020 13:54 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/8 "2020-11-21T13:54:45Z")

</div>

It is corrupt as you failed to post between backticks or \</\> tags. please edit it

---

<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:** [21 November 2020 13:54 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/9 "2020-11-21T13:54:51Z")

</div>

I think I did a bad trick?  
I copy the script and paste in the answer?

---

<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:** [21 November 2020 13:59 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/10 "2020-11-21T13:59:49Z")

</div>

how to place the tags  
at the beginning I tried \<\> and at the end \</\> but it is not that? ? ?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [21 November 2020 14:02 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/11 "2020-11-21T14:02:26Z")

</div>

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 November 2020 14:05 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/12 "2020-11-21T14:05:39Z")

</div>

![Screenshot_20201121-140428](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/2851be92238f9d5c2b04c752da1138920c4d79ea.png)  
click the icon by my cursor \</\> in the image.

---

<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:** [21 November 2020 14:07 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/13 "2020-11-21T14:07:59Z")

</div>

thank you and sorry, I am completely lost!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 November 2020 14:10 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/14 "2020-11-21T14:10:09Z")

</div>

No problem

your issue is the injects are both payload.

but inthe function you are checking payload1

---

<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:** [21 November 2020 14:10 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/15 "2020-11-21T14:10:26Z")

</div>

with the little modification I made, I still get yes on output?

---

<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:** [21 November 2020 14:17 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/16 "2020-11-21T14:17:23Z")

</div>

[quote="E1cid, post:14, topic:36284, full:true"]  
No problem

and in short, what does that mean?  
if I use 2 variables that I set to 1 or 0 and I perform the "if" test, it works.  
So I tried to load a var1 like this:  
Let var1 = msg.payload.minutely [0] .weather [0] .0.precipitation;  
but I have an error? ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 November 2020 14:21 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/17 "2020-11-21T14:21:06Z")

</div>

show us a complete message object of a debug node after the openweathermap returns it's json, as your path is incorrect .0. is invalid

---

<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:** [21 November 2020 14:24 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/18 "2020-11-21T14:24:32Z")

</div>

```auto
21/11/2020 à 15:23:18node: 36b1116f.d8be2e
msg.payload : Object
object
lat: 49.02
lon: -0.94
timezone: "Europe/Paris"
timezone_offset: 3600
current: object
minutely: array[61]
[0 … 9]
0: object
dt: 1605968580
precipitation: 0
1: object
dt: 1605968640
precipitation: 0
2: object

```

---

<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:** [21 November 2020 14:27 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/19 "2020-11-21T14:27:33Z")

</div>

oui, weather[0]. est en trop !  
je ré essaye !

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 November 2020 14:27 UTC](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284/20 "2020-11-21T14:27:56Z")

</div>

can you expand  
current object and minutely array.

In the debug if you hover to right of object you get an option to copy path.

[Next page](https://discourse.nodered.org/t/beginner-test-on-a-variable/36284.md?page=2)
