`light.turn_on` Service fails when color included in JSON

In Dev Tools/Services, this works:
Service: light.turn_on
Entity: light.0620011084f3eb43a8d0
Service Data:

{
  "entity_id": "light.0620011084f3eb43a8d0",
  "brightness": "255",
  "transition": "2"
}

…but this…
Service Data:

{
  "entity_id": "light.0620011084f3eb43a8d0",
  "brightness": "255",
  "transition": "2",
  "rgb_color": "[255, 255, 255]"
}

…results in “Failed to call service light/turn_on.”

  • I’ve also tried "hs_color": "[0,0]" and "xy_color": "[0.323,0.329]" and get the same failure message.
  • No errors are generated in the log file.
  • All three color attributes are listed in Dev Tools/States:

What am I doing wrong? :sweat:

dont include the brackets. It should be:

"rgb_color": "255,255,255"

Sorry I didn’t mention it in the OP but I tried that too out of desperation and it also failed. :slightly_frowning_face:

I thought CSVs (or at least comma separated numerals) had to be enclosed in brackets…?

I’m sorry I got it wrong.
I just tested it, it should be no quotes…

"rgb_color": [255,255,255]

That’s it! :smiley:

Man, I thought tried every conceivable syntax but I never would have guessed the quotes should be omitted. :sweat_smile:

Thank you, Pippyn. :sunglasses:

1 Like

With quotes, it’s a string, without quotes but with square brackets, it’s an array (of numbers in this case).

I thought the brackets were needed for arrays but I thought the quotes were needed (additionally) as a syntax requirement in JSON. But I guess now that I think about it, the curly brackets {} already designate the data parsed as JSON…?

In brief:

  • quotes: text or attribute name
  • square brackets: array
  • curly brackets: object
  • nothing: numbers or boolean values
1 Like

Ha! So – as I just learned and confirmed by testing – this also works:

“transition”: 2

Great tips. Thanks, m0wlheld. :sunglasses: