Looking for correct syntax help

Hello everyone,
I am quite new to HA and am trying out a few things. Next is getting some Node-Red flows up and running.

I am struggling a bit with the syntax as it is now different from the yaml syntax.

So, I am trying something simle:
If an entity changes its state, I would like a notification to my phone with some information.

I have an events:state node for each entity. Then I would normally go directly to a call:service node.
I was thinking about adding a function node in between, but not sure if I really need it or not.

The idea is:
If entity state changes Then send notification with entitiy_id and new state.

I would have thought that this would work with

{
    "message": [
        "{{entity_id}}",
        "{{payload}}"
    ]
}

But clearly I am mistaken. Could someone help me out? I am also not sure what is Node-Red syntax, what is JSON and what is then sepcific to HA.

Thank you :slight_smile:
Alex

This is one of my function nodes:

msg.payload = {
        "data":{
            "message": "Beräknas hemma om cirka " + msg.waze + " minuter",
            "title": "Andreas på väg hem",
            "data": {
                "icon_url": "https://play-lh.googleusercontent.com/muSOyE55_Ra26XXx2IiGYqXduq7RchMhosFlWGc7wCS4I1iQXb7BAnnjEYzqcUYa5oo=s180-rw",
            }
        }
    };

return msg;

And it feeds in to a call service node

[{"id":"3e49cb4.b328234","type":"function","z":"c513d12c.45645","name":"","func":"\n\n    msg.payload = {\n        \"data\":{\n            \"message\": \"Beräknas hemma om cirka \" + msg.waze + \" minuter\",\n            \"title\": \"Andreas på väg hem\",\n            \"data\": {\n                \"icon_url\": \"https://play-lh.googleusercontent.com/muSOyE55_Ra26XXx2IiGYqXduq7RchMhosFlWGc7wCS4I1iQXb7BAnnjEYzqcUYa5oo=s180-rw\",\n            }\n        }\n    };\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2480,"y":540,"wires":[["a9614066.452ea","599006e3.29f9c8"]]},{"id":"a9614066.452ea","type":"api-call-service","z":"c513d12c.45645","name":"","server":"4bbca37b.1700ec","version":1,"debugenabled":false,"service_domain":"notify","service":"mobile_app_andreas","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2710,"y":500,"wires":[[]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

image

Thank you @Hellis81 .

You have msg.waze in your function. What does that relate to?

I am asking because I am wondering if my approavh is even possible. Does the event:state node just pass thr payload itself or does it also inform the function about the origin of the payload? So is it even possible to pass on the entity_id?

Msg.waze comes from a current state node.
The node saves the driving time to home in msg.waze and is joined in to the message.

Use the debug node set to complete message and connect it to the event state node.
You should see the message in the debug window.

All items are accessible using the format msg.payload.something.item

I am making some small progress.
So, the entity_id is passed as “topic”.

So I found a working code using the function node based on your code above :slight_smile:

I will open a separate thread for a different, related problem.