Call service node, "expected int for dictionary value @ data" from Change node

Hi

I used Change Node to create a msg with the information that i want to pass onto my light (philips hue) group.

[{"id":"b7d1b257.10eda","type":"change","z":"b5a4f9b1.de8f78","name":"","rules":[{"t":"delete","p":"data","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"},{"t":"set","p":"data.rgb_color","pt":"msg","to":"[255,244,229]","tot":"str"},{"t":"set","p":"data.transition","pt":"msg","to":"30","tot":"num"},{"t":"set","p":"data.brightness","pt":"msg","to":"$number(\"1\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":1340,"wires":[["b68ecf59.c83a3","2e11fe32.ad2b02"]]}]

First i Clean up the payload and data field from the earlyer nodes.
On my debug it looks as expected, with a payload with “on” and my data field with the data expected.

But my call service node will not accept my number brightness as an integer, although I’ve really tried formatting it according to what I could find on google/exambles.

56

Complete test flow below

[{"id":"b68ecf59.c83a3","type":"api-call-service","z":"b5a4f9b1.de8f78","name":"Stuen On","server":"468387c0.b24028","version":1,"service_domain":"light","service":"turn_on","entityId":"light.stuen","data":"{\"brightness\":\"{{payload.brightness}}\",\"rgb_color\":\"{{payload.rgb_color}}\",\"transition\":\"{{payload.transition}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":995,"y":1320,"wires":[[]],"l":false},{"id":"b7d1b257.10eda","type":"change","z":"b5a4f9b1.de8f78","name":"","rules":[{"t":"delete","p":"data","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"},{"t":"set","p":"data.rgb_color","pt":"msg","to":"[255,244,229]","tot":"str"},{"t":"set","p":"data.transition","pt":"msg","to":"30","tot":"num"},{"t":"set","p":"data.brightness","pt":"msg","to":"$number(\"1\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":1340,"wires":[["b68ecf59.c83a3","2e11fe32.ad2b02"]]},{"id":"2e11fe32.ad2b02","type":"debug","z":"b5a4f9b1.de8f78","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":1360,"wires":[]},{"id":"d09e1434.713278","type":"inject","z":"b5a4f9b1.de8f78","name":"Test knap","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":1420,"wires":[["b7d1b257.10eda"]]},{"id":"468387c0.b24028","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

I’m thinking I have a problem, with the JSON field in call service node, where I try to import the data.
Can anyone help?

JSON in call service node

{"brightness":"{{payload.brightness}}","rgb_color":"{{payload.rgb_color}}","transition":"{{payload.transition}}"}

Edit:
Adding the error message as text, so Google can find it for others in the future
“Call-service API error. Error Message: expected int for dictionary value @ data[‘brightness’]”

The error states that this is because your brightness value is not sent as an integer (number) value.
Try sending this in the data field just to check if it works manually:

{“kelvin”:“2700”,“brightness”:“1”}

In the function node you can transform your number into an INT by using:

parseInt()

Hello AlmostSerious

Thanks for your reply!

As I can see, also you sugges tin the other thread, we should use a function node to send the data, instead of using the change node?
I was hoping to use the change node, because i read, that function node had some overhead?

I don’t know about overhead of the function node, but i use several in my automations because of the flexibility they provide :slight_smile: Never had a problem with CPU or RAM usage if this is what you are referring to.

Function Node basically uses Java Script so you can do a lot with this in there.

First i tried using a function block, each with it’s own string, but I was having trouble merging them together with a join node. Then I considered using storing values instead, but having to pull data every minute or more often was not in my interest.

The Change node gave the easy ability to set the data without having to edit javascript each time.

I even tryed in the change node to use the expression function and use the string $number(“1”) and it changed from string to integer, however the service call node still gives an error :frowning:

Hey

If you look at my screenshot, you can see that i made 3 data values in my change node.
One with expressions
one with number as function
and one with string

Only the string value comes out as “2” (string) instead of just 2 (integer)
That’s why I can’t understand why it says it’s not an integer…

I made a more simple setup and made that work:

Using a change node to set payload.data.brightness
It just so happens, that any data in payload is injected into the data field of call service.
payload.data.brightness = 5

[{"id":"80145b19.5e6828","type":"inject","z":"b5a4f9b1.de8f78","name":"Test knap","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":2020,"wires":[["7049f8b9.a10158"]]},{"id":"7049f8b9.a10158","type":"change","z":"b5a4f9b1.de8f78","name":"","rules":[{"t":"delete","p":"data","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.data.brightness","pt":"msg","to":"5","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":2020,"wires":[["22259ba5.ce5ac4","5cec941d.a4cfdc"]]},{"id":"22259ba5.ce5ac4","type":"debug","z":"b5a4f9b1.de8f78","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":570,"y":2000,"wires":[]},{"id":"5cec941d.a4cfdc","type":"api-call-service","z":"b5a4f9b1.de8f78","name":"Stuen On","server":"468387c0.b24028","version":1,"service_domain":"light","service":"turn_on","entityId":"light.stuen","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":580,"y":2040,"wires":[[]]},{"id":"468387c0.b24028","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

A function block will do the same thing
With the following in the function:

msg.payload = { data: { ‘brightness’: 255 } };

return msg;

[{"id":"8973b848.c76e58","type":"function","z":"b5a4f9b1.de8f78","name":"funk","func":"msg.payload = { data: { 'brightness': 255 } };\n\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":2120,"wires":[["353754dc.824d4c","3ea28175.918eee"]]},{"id":"664e3b84.1c0494","type":"inject","z":"b5a4f9b1.de8f78","name":"Test knap","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":2120,"wires":[["8973b848.c76e58"]]},{"id":"3ea28175.918eee","type":"api-call-service","z":"b5a4f9b1.de8f78","name":"Stuen On","server":"468387c0.b24028","version":1,"service_domain":"light","service":"turn_on","entityId":"light.stuen","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":575,"y":2145,"wires":[[]]},{"id":"353754dc.824d4c","type":"debug","z":"b5a4f9b1.de8f78","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":570,"y":2100,"wires":[]},{"id":"468387c0.b24028","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

Sending 2 values to call service node
Brightness and rgb_color

Both able to do with change node and function node
In the change node, for array [255,0,0] use expression input

[{"id":"80145b19.5e6828","type":"inject","z":"b5a4f9b1.de8f78","name":"Test knap","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":2020,"wires":[["7049f8b9.a10158"]]},{"id":"7049f8b9.a10158","type":"change","z":"b5a4f9b1.de8f78","name":"","rules":[{"t":"delete","p":"data","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.data.brightness","pt":"msg","to":"5","tot":"num"},{"t":"set","p":"payload.data.rgb_color","pt":"msg","to":"[255,0,0]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":2020,"wires":[["22259ba5.ce5ac4","5cec941d.a4cfdc"]]},{"id":"22259ba5.ce5ac4","type":"debug","z":"b5a4f9b1.de8f78","name":"Change Node Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":620,"y":2000,"wires":[]},{"id":"5cec941d.a4cfdc","type":"api-call-service","z":"b5a4f9b1.de8f78","name":"Stuen On","server":"468387c0.b24028","version":1,"service_domain":"light","service":"turn_on","entityId":"light.stuen","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":580,"y":2040,"wires":[[]]},{"id":"468387c0.b24028","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]
[{"id":"8973b848.c76e58","type":"function","z":"b5a4f9b1.de8f78","name":"funk","func":"msg.payload = { data: { 'brightness': 255, 'rgb_color': [255,0,0] } };\n\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":2120,"wires":[["353754dc.824d4c","3ea28175.918eee"]]},{"id":"664e3b84.1c0494","type":"inject","z":"b5a4f9b1.de8f78","name":"Test knap","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":2120,"wires":[["8973b848.c76e58"]]},{"id":"3ea28175.918eee","type":"api-call-service","z":"b5a4f9b1.de8f78","name":"Stuen On","server":"468387c0.b24028","version":1,"service_domain":"light","service":"turn_on","entityId":"light.stuen","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":575,"y":2145,"wires":[[]]},{"id":"353754dc.824d4c","type":"debug","z":"b5a4f9b1.de8f78","name":"Funk Test Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":2100,"wires":[]},{"id":"468387c0.b24028","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

I just created a flow with a msg.brightness and the function node to show you how to address the payload with it.

[{"id":"e734666c.b836a8","type":"inject","z":"68d52ff7.9182a","name":"","topic":"msg.brightness","payload":"3","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":480,"y":420,"wires":[["3a7d2297.cacfbe"]]},{"id":"13cbdb5c.946935","type":"api-call-service","z":"68d52ff7.9182a","name":"","server":"2fba4297.e4145e","version":1,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_right","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":850,"y":420,"wires":[[]]},{"id":"3a7d2297.cacfbe","type":"function","z":"68d52ff7.9182a","name":"Set Volume","func":"newmsg = {}\n\nnewmsg.payload = { data: { \"brightness\":(msg.brightness)} }\n\nreturn newmsg;\n","outputs":1,"noerr":0,"x":670,"y":420,"wires":[["13cbdb5c.946935"]]},{"id":"2fba4297.e4145e","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Passing 3 values and tested with philips hue lights

Call service node with function or change node

[{"id":"80145b19.5e6828","type":"inject","z":"b5a4f9b1.de8f78","name":"Test knap","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":2020,"wires":[["7049f8b9.a10158"]]},{"id":"7049f8b9.a10158","type":"change","z":"b5a4f9b1.de8f78","name":"","rules":[{"t":"delete","p":"data","pt":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.data.brightness","pt":"msg","to":"5","tot":"num"},{"t":"set","p":"payload.data.rgb_color","pt":"msg","to":"[0,255,0]","tot":"jsonata"},{"t":"set","p":"payload.data.transition","pt":"msg","to":"15","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":2020,"wires":[["22259ba5.ce5ac4","5cec941d.a4cfdc"]]},{"id":"22259ba5.ce5ac4","type":"debug","z":"b5a4f9b1.de8f78","name":"Change Node Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":620,"y":2000,"wires":[]},{"id":"5cec941d.a4cfdc","type":"api-call-service","z":"b5a4f9b1.de8f78","name":"Stuen On","server":"468387c0.b24028","version":1,"service_domain":"light","service":"turn_on","entityId":"light.stuen","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":580,"y":2040,"wires":[[]]},{"id":"8973b848.c76e58","type":"function","z":"b5a4f9b1.de8f78","name":"funk","func":"msg.payload = { data: { 'brightness': 255, 'rgb_color': [255,0,0], 'transition': 15 } };\n\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":2120,"wires":[["353754dc.824d4c","3ea28175.918eee"]]},{"id":"664e3b84.1c0494","type":"inject","z":"b5a4f9b1.de8f78","name":"Test knap","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":2120,"wires":[["8973b848.c76e58"]]},{"id":"3ea28175.918eee","type":"api-call-service","z":"b5a4f9b1.de8f78","name":"Stuen On","server":"468387c0.b24028","version":1,"service_domain":"light","service":"turn_on","entityId":"light.stuen","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":true,"x":575,"y":2145,"wires":[[]]},{"id":"353754dc.824d4c","type":"debug","z":"b5a4f9b1.de8f78","name":"Funk Test Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":2100,"wires":[]},{"id":"468387c0.b24028","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

I can’t import your flow :frowning:

But I still wish I could from Call Service Node take the data from msg that I wanted and pass the rest along…

Sorry seems i deleted a

[

in the beginning. Its fixed now :slight_smile: