You need to pass the data field into the node, as well. This confused me too when I was first getting started. Below is the code for a sample flow which fetches the state of a light, builds the string for a HA service call node, delays the message 5 seconds, then sets the light state back to what it was when the flow was initiated.
This was a flow I used to help a friend who wanted to have one of his lights change color temporarily when a notification came into Telegram.
You can import this into any flow, it’s short. If you’re going to use any part of it, make sure you modify the server information. If it were me, I wouldn’t deploy this, but you can look through it and see how it is done.
[
{
"id": "2d2a2c5d.038d44",
"type": "template",
"z": "77a95d32.723cc4",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "json",
"syntax": "mustache",
"template": "{\"data\": {\"entity_id\":\"{{data.entity_id}}\",\"brightness\":\"{{data.attributes.brightness}}\"}}",
"output": "str",
"x": 740,
"y": 520,
"wires": [
[
"4f51c2cc.f32b4c"
]
]
},
{
"id": "64c2e48e.e6747c",
"type": "inject",
"z": "77a95d32.723cc4",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 220,
"y": 520,
"wires": [
[
"69dd54c.1e7beac"
]
]
},
{
"id": "69dd54c.1e7beac",
"type": "api-current-state",
"z": "77a95d32.723cc4",
"name": "",
"server": "aad53eb0.732ad",
"halt_if": "",
"override_topic": true,
"override_payload": true,
"entity_id": "light.computer_desk_lights",
"x": 480,
"y": 520,
"wires": [
[
"2d2a2c5d.038d44"
]
]
},
{
"id": "bc9af540.9b59e8",
"type": "api-call-service",
"z": "77a95d32.723cc4",
"name": "",
"server": "aad53eb0.732ad",
"service_domain": "light",
"service": "turn_on",
"data": "",
"mergecontext": "",
"x": 1110,
"y": 520,
"wires": [
[]
]
},
{
"id": "4f51c2cc.f32b4c",
"type": "delay",
"z": "77a95d32.723cc4",
"name": "",
"pauseType": "delay",
"timeout": "5",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"x": 920,
"y": 520,
"wires": [
[
"bc9af540.9b59e8"
]
]
},
{
"id": "aad53eb0.732ad",
"type": "server",
"z": "",
"name": "Home Assistant",
"url": "http://hassio/homeassistant",
"pass": "redacted"
}
]