What would cause an "Unexpected token l in JSON"

I am trying to get the following flow working but I keep running into an error that is stumping me.

The error occurs in the Template node. I thought I had the formatting correct, but something is causing the error.

I am attempting to use the get entities node to then only change the color temp on lights that are turned on.

I would love some help/feedback.

Thanks

[{"id":"35d525fd.e385ca","type":"tab","label":"Flow 30","disabled":false,"info":""},{"id":"a94a3a4a.970358","type":"poll-state","z":"35d525fd.e385ca","name":"","server":"ea5ed475.5c5908","updateinterval":"10","updateIntervalUnits":"seconds","outputinitially":false,"outputonchanged":false,"entity_id":"sensor.circadian_values","state_type":"str","halt_if":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"x":320,"y":160,"wires":[["d6cd7cd7.63e56"]]},{"id":"135bedd3.051c62","type":"api-call-service","z":"35d525fd.e385ca","name":"On","server":"ea5ed475.5c5908","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.test_lamp\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":730,"y":220,"wires":[[]]},{"id":"d6d648d9.b8ae48","type":"template","z":"35d525fd.e385ca","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n\"data\":\n{\n\"entity_id\": {{payload.entity_id}},\n\"color_temp\": {{flow.testlightcolor}},\n\"transition\": 10\n}\n}\n\n","output":"json","x":560,"y":220,"wires":[["135bedd3.051c62"]]},{"id":"9ea7ceb6.b56ac","type":"ha-get-entities","z":"35d525fd.e385ca","server":"ea5ed475.5c5908","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.test_lamp,light.livingroom_hutch_lamp_1,light.livingroom_hutch_lamp_2,light.olivia_bedroom_lamp,light.jakes_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":350,"y":220,"wires":[["d6d648d9.b8ae48"]]},{"id":"e860c8e.e0d7e38","type":"inject","z":"35d525fd.e385ca","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":220,"wires":[["9ea7ceb6.b56ac"]]},{"id":"d6cd7cd7.63e56","type":"change","z":"35d525fd.e385ca","name":"","rules":[{"t":"set","p":"testlightcolor","pt":"flow","to":"data.attributes.colortemp","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":160,"wires":[["95baec8c.add19"]]},{"id":"95baec8c.add19","type":"debug","z":"35d525fd.e385ca","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":160,"wires":[]},{"id":"ea5ed475.5c5908","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Your template doesn’t output valid JSON. You need quotes around the entity_id and color_temp.

{
  "data": {
    "entity_id": "{{payload.entity_id}}",
    "color_temp": "{{flow.testlightcolor}}",
    "transition": 10
  }
}

Not sure if you’re just testing things out but your current flow can be condensed down.

[{"id":"9682c21.38bdd4","type":"api-call-service","z":"9b043fec.51903","name":"On","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\",\"color_temp\":\"{{entity.sensor.circadian_values.attributes.colortemp}}\",\"transition\":10}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":482,"y":368,"wires":[[]]},{"id":"b82f4fae.a0717","type":"ha-get-entities","z":"9b043fec.51903","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.test_lamp,light.livingroom_hutch_lamp_1,light.livingroom_hutch_lamp_2,light.olivia_bedroom_lamp,light.jakes_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":342,"y":368,"wires":[["9682c21.38bdd4"]]},{"id":"c91bf82e.f69df8","type":"inject","z":"9b043fec.51903","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":172,"y":368,"wires":[["b82f4fae.a0717"]]}]

@Kermit if you ever decide to write a book I will be the first inline. Your solution was just so simple.

Thank you again.

@Kermit I am now trying to adjust the RGB values. But I get this error: “Call-service API error. Error Message: None for dictionary value @ data[‘rgb_color’]”

{"rgb_color":"{{entity.sensor.circadian_values.attributes.rgb_color}}","transition":10} 

missing quotations around 10?

Thanks, I just tried but that’s not the cause. This one works perfectly.

{
    "color_temp": "{{entity.sensor.circadian_values.attributes.colortemp}}",
    "transition": 10
}

[{"id":"3a816701.407698","type":"tab","label":"Color Temp control","disabled":false,"info":""},{"id":"db8e9454.068e28","type":"api-call-service","z":"3a816701.407698","name":"On","server":"ea5ed475.5c5908","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\",\"color_temp\":\"{{entity.sensor.circadian_values.attributes.colortemp}}\",\"transition\":10}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":670,"y":60,"wires":[[]]},{"id":"53201fe2.795e7","type":"ha-get-entities","z":"3a816701.407698","server":"ea5ed475.5c5908","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.test_lamp,light.livingroom_hutch_lamp_1,light.livingroom_hutch_lamp_2,light.olivia_bedroom_lamp,light.jakes_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":370,"y":60,"wires":[["db8e9454.068e28"]]},{"id":"29fe4143.771f1e","type":"inject","z":"3a816701.407698","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":60,"wires":[["53201fe2.795e7","c49de8a1.3dd128"]]},{"id":"c49de8a1.3dd128","type":"ha-get-entities","z":"3a816701.407698","server":"ea5ed475.5c5908","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.livingroom_tv_lamp,light.main_bedroom_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":370,"y":120,"wires":[["26fdbce9.919804"]]},{"id":"26fdbce9.919804","type":"api-call-service","z":"3a816701.407698","name":"On","server":"ea5ed475.5c5908","service_domain":"light","service":"turn_on","data":"{\"rgb_color\":\"{{entity.sensor.circadian_values.attributes.rgb_color}}\",\"transition\":\"10\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":690,"y":140,"wires":[[]]},{"id":"ea5ed475.5c5908","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

@Kermit any suggestions or previous examples on using an array in a json data template?

[{"id":"ac666137.c12c8","type":"api-call-service","z":"6468908e.223b7","name":"On","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\",\"color_temp\":\"{{entity.sensor.circadian_values.attributes.colortemp}}\",\"transition\":10}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":514,"y":64,"wires":[[]]},{"id":"748c4717.306958","type":"ha-get-entities","z":"6468908e.223b7","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.test_lamp,light.livingroom_hutch_lamp_1,light.livingroom_hutch_lamp_2,light.olivia_bedroom_lamp,light.jakes_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":358,"y":64,"wires":[["ac666137.c12c8"]]},{"id":"6542637b.eb0ffc","type":"inject","z":"6468908e.223b7","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":188,"y":64,"wires":[["748c4717.306958","e87057f3.948668"]]},{"id":"e87057f3.948668","type":"ha-get-entities","z":"6468908e.223b7","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.livingroom_tv_lamp,light.main_bedroom_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":358,"y":112,"wires":[["1dc0d22f.96697e"]]},{"id":"af9d2045.af07b","type":"api-call-service","z":"6468908e.223b7","name":"On","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\",\"transition\":\"10\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":802,"y":112,"wires":[[]]},{"id":"4d96940b.0c781c","type":"template","z":"6468908e.223b7","name":"","field":"payload.data","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"rgb_color\": [{{msg.data.attributes.rgb_color}}]\n}","output":"json","x":668,"y":112,"wires":[["af9d2045.af07b"]]},{"id":"1dc0d22f.96697e","type":"api-current-state","z":"6468908e.223b7","name":"circadian","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.circadian_values","state_type":"str","state_location":"","override_payload":"none","entity_location":"data","override_data":"msg","blockInputOverrides":true,"x":524,"y":112,"wires":[["4d96940b.0c781c"]]}]

@Kermit thank you, however, I am still getting this error:

"Call-service API error. Error Message: None for dictionary value @ data['rgb_color']"

change the template to

{
    "rgb_color": [{{payload.attributes.rgb_color}}]
}

@Kermit That is working (when I test it from work)

Now I need to test when I get home tonight. That’s when the theory meets reality.

@Kermit Still testing from work. It seems that we are no longer getting errors. However, looking at debug messages it seems that the template it taking the RGB values of the lights rather than the sensor.

So it seems the lights are being updated with their own values.

This is the debug output from the sensor:


And this is what comes out of the Template:


This what the sensor is outputting:

rgb_color: 255,254.097641774914,250.0214316852721

and the current state of the light is:

[83,185,255]

I got it working (once again in Theory) like this. Very cumbersome, but the concept works.

[{"id":"647ea090.4ed108","type":"tab","label":"Flow 24","disabled":false,"info":""},{"id":"d1672f5f.fa3758","type":"api-call-service","z":"647ea090.4ed108","name":"On","server":"ea5ed475.5c5908","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\",\"color_temp\":\"{{entity.sensor.circadian_values.attributes.colortemp}}\",\"transition\":10}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":430,"y":260,"wires":[[]]},{"id":"f4d38329.563378","type":"ha-get-entities","z":"647ea090.4ed108","server":"ea5ed475.5c5908","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.test_lamp,light.livingroom_hutch_lamp_1,light.livingroom_hutch_lamp_2,light.olivia_bedroom_lamp,light.jakes_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":274,"y":260,"wires":[["d1672f5f.fa3758"]]},{"id":"42b0e9d7.bea618","type":"api-current-state","z":"647ea090.4ed108","name":"","server":"ea5ed475.5c5908","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.livingroom_tv_lamp","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":390,"y":620,"wires":[["4f0dc780.c3f528"]]},{"id":"463d56d7.87bf08","type":"inject","z":"647ea090.4ed108","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":620,"wires":[["42b0e9d7.bea618"]]},{"id":"4f0dc780.c3f528","type":"debug","z":"647ea090.4ed108","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":620,"wires":[]},{"id":"9e873da1.a5858","type":"ha-get-entities","z":"647ea090.4ed108","server":"ea5ed475.5c5908","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.livingroom_tv_lamp,light.main_bedroom_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":410,"y":320,"wires":[["c044fb73.6e5c28"]]},{"id":"9041f01.c10e61","type":"template","z":"647ea090.4ed108","name":"","field":"payload.data","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"rgb_color\": [{{flow.cirrgb}}]\n}\n\n","output":"json","x":900,"y":320,"wires":[["1dd1f083.2478bf"]]},{"id":"a80bd3a.fd27f3","type":"api-current-state","z":"647ea090.4ed108","name":"circadian","server":"ea5ed475.5c5908","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.circadian_values","state_type":"str","state_location":"","override_payload":"none","entity_location":"data","override_data":"msg","blockInputOverrides":true,"x":260,"y":380,"wires":[["e56797cd.e100c8"]]},{"id":"e56797cd.e100c8","type":"change","z":"647ea090.4ed108","name":"","rules":[{"t":"set","p":"cirrgb","pt":"flow","to":"data.attributes.rgb_color","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":380,"wires":[[]]},{"id":"9cb400e7.0a07b","type":"inject","z":"647ea090.4ed108","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":320,"wires":[["cf1fa483.790688","a80bd3a.fd27f3","f4d38329.563378"]]},{"id":"c044fb73.6e5c28","type":"change","z":"647ea090.4ed108","name":"","rules":[{"t":"set","p":"payload.attributes.rgb_color","pt":"msg","to":"cirrgb","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":320,"wires":[["9041f01.c10e61"]]},{"id":"1dd1f083.2478bf","type":"api-call-service","z":"647ea090.4ed108","name":"On","server":"ea5ed475.5c5908","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\",\"transition\":\"10\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1050,"y":320,"wires":[[]]},{"id":"cf1fa483.790688","type":"delay","z":"647ea090.4ed108","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":260,"y":320,"wires":[["9e873da1.a5858"]]},{"id":"ea5ed475.5c5908","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]
[{"id":"d8d6403d.048b8","type":"api-call-service","z":"c174829e.c2228","name":"On","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\",\"color_temp\":\"{{entity.sensor.circadian_values.attributes.colortemp}}\",\"transition\":10}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":430,"y":260,"wires":[[]]},{"id":"de4aae02.c2d68","type":"ha-get-entities","z":"c174829e.c2228","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.test_lamp,light.livingroom_hutch_lamp_1,light.livingroom_hutch_lamp_2,light.olivia_bedroom_lamp,light.jakes_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":274,"y":260,"wires":[["d8d6403d.048b8"]]},{"id":"7e1a2351.005a3c","type":"inject","z":"c174829e.c2228","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":320,"wires":[["de4aae02.c2d68","305970ec.a143b"]]},{"id":"52b1e1b0.c04cd","type":"ha-get-entities","z":"c174829e.c2228","name":"","rules":[{"property":"entity_id","logic":"includes","value":"light.livingroom_tv_lamp,light.main_bedroom_lamp","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":454,"y":320,"wires":[["16518484.31b82b"]]},{"id":"16518484.31b82b","type":"template","z":"c174829e.c2228","name":"","field":"payload.data","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"rgb_color\": [{{cicadian.attributes.rgb_color}}]\n}\n\n","output":"json","x":620,"y":320,"wires":[["93997910.c23d78"]]},{"id":"93997910.c23d78","type":"api-call-service","z":"c174829e.c2228","name":"On","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"{{payload.entity_id}}\",\"transition\":\"10\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":770,"y":320,"wires":[[]]},{"id":"305970ec.a143b","type":"api-current-state","z":"c174829e.c2228","name":"circadian","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.circadian_values","state_type":"str","state_location":"","override_payload":"none","entity_location":"circadian","override_data":"msg","blockInputOverrides":true,"x":268,"y":320,"wires":[["52b1e1b0.c04cd"]]}]