Beginner: test on a variable

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 !

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

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

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

working here,


you must be doing something wrong, it would help to post your flow.
export your flow and post it between backticks like below
```
code
```

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.

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

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

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

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

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


click the icon by my cursor </> in the image.

thank you and sorry, I am completely lost!

No problem

your issue is the injects are both payload.

but inthe function you are checking payload1

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

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

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

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

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

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.