Call turn_on service doesn't work from NR

I have some node-red flows that used to work but stop working recently and not sure what’s broken.

[{"id":"867367eb.3f9da8","type":"template","z":"845016a6.b38828","name":"template msg","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{ \"data\": {\"entity_id\" : \"light.xxxxx\", \"brightness\": 254, \"rgb_color\" : [0, 153, 0], \"transition\": 2 }}","output":"str","x":740,"y":120,"wires":[["d015d042.04841"]],"icon":"node-red-contrib-color-convert/color-convert.png"},{"id":"d015d042.04841","type":"api-call-service","z":"845016a6.b38828","name":"turn_on","server":"e8b4e59e.644ec8","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"{}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"queue":"none","x":920,"y":120,"wires":[[]]},{"id":"3ae996ce.c18a7a","type":"inject","z":"845016a6.b38828","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":570,"y":120,"wires":[["867367eb.3f9da8"]]},{"id":"e8b4e59e.644ec8","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Above is one of sample flow, it tries to call the turn_on service with certain brightness, rgb_color and transition. The light is SYLVANIA Smart ZigBee strip. It was worked ok before but not working now. When the flow is run, the light doesn’t turn on at all.

Does anyone know what could be wrong?

Thanks.

The paste of the code is not proper YAML (it is truncated at the end), so nobody can try it out to see what’s wrong.

Sorry for that, there are two brackets missing at the end. I’ve corrected it now.
Thanks for pointing it out!

If I need a dynamic call service, I will leave it totally blank and build the entire message in a function node. Note the data field is set to jsonata.

[{"id":"c965535ff376a62c","type":"api-call-service","z":"f80b6c338afd5483","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":true,"domain":"","service":"","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1810,"y":100,"wires":[[]]},{"id":"57e35d40d96c52e1","type":"inject","z":"f80b6c338afd5483","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":200,"wires":[["560a33abf91bde5d"]]},{"id":"560a33abf91bde5d","type":"function","z":"f80b6c338afd5483","name":"","func":"msg.payload = {\n        domain: \"light\",\n        service: \"turn_on\",\n        data: {\n            \"entity_id\": \"light.lefty\",\n\n        }\n    };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":180,"wires":[["9555aeef94994375","c965535ff376a62c"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]
1 Like

The problem is that in your template node you have “Output as” set to “Plain text”. Therefore the payload is a string rather than an object. If you change it to “Parsed JSON” it will work (although I didn’t test).

2 Likes

Yes. The turn_on service is all blank, all these entity_id, rgb, brightness, transition are all dynamic constructed in some previous function nodes, and finally using the template node to collect them. I think I could use a function node as the final node too.

You saved me. Make the change and now it is working. Thanks!

The “plain text” output worked before as I have been using this for my out door light to change colors for the last two Xmas. Maybe one of the recent update broke it.