Webhook to change RGB of light

I am trying to get a webhook to turn on and change the RGB color of a light entity.

Currently the automation is:

alias: 1 Test Bulb 1 Webhook
description: ""
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: false
    webhook_id: "-webhook_id"
condition: []
action:
  - service: light.turn_on
    data:
      rgb_color: "{{ value_json.data[rgb].val }}"
      entity_id: light.test_bulb_1
mode: single

and the webhook is:

curl -X POST -H "Content-Type: application/json" -d '{"rgb":[255,0,0]}' http://homeassistant.local:8123/api/webhook/-webhook_id

Without the rgb_color: “{{ value_json.data[rgb_color].val }}” line it turns the light on when the webhook is sent in a terminal.

With that line in place, the light does not come on and the trace gives me this:

Executed: March 8, 2024 at 4:34:00 PM
this:
  entity_id: automation.1_test_bulb_1_webhook
  state: 'on'
  attributes:
    id: '1709930669830'
    last_triggered: '2024-03-08T21:33:40.282485+00:00'
    mode: single
    current: 0
    friendly_name: 1 Test Bulb 1 Webhook
  last_changed: '2024-03-08T21:32:49.353065+00:00'
  last_updated: '2024-03-08T21:33:40.288174+00:00'
  context:
    id: 01HRFZRV1SVM0GTT3B7GBWC62K
    parent_id: null
    user_id: null
trigger:
  platform: webhook
  webhook_id: '-webhook_id'
  json:
    rgb:
      - 255
      - 0
      - 0
  query:
    __type: <class 'multidict._multidict.MultiDictProxy'>
    repr: <MultiDictProxy()>
  description: webhook
  id: '0'
  idx: '0'
  alias: null

So the data is there, I just can’t get it to create the correct

rgb_color:
  - 255
  - 0
  - 0

code in the automation when triggered. Any help?

you have value_json? i wasn’t aware that was set in this sort of trigger. where did you see that?

in mine, i use something more like: {{ trigger.json[‘rgb’] }}"

if you haven’t already, you should try taking a look at the download trace. it gives the full json info (not truncated like the trace you have above) and you can see the json values and what variables they are assigned to.

I am pretty novice at the use of json on automations, so I have been just trying anything. If I use your example, and change to the automation to:

id: '1709930669830'
alias: 1 Test Bulb 1 Webhook
description: ''
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: false
    webhook_id: '-webhook_id'
condition: []
action:
  - service: light.turn_on
    data:
      rgb_color: '{{ trigger.json[rgb] }}'
      entity_id: light.test_bulb_1
mode: single

I changed your “{{ trigger.json[‘rgb’] }}” to the code above because I get an error in the editor “Message malformed: template value should be a string for dictionary value @ data[‘action’][0][‘data’]” with the quotes inside the brackets.

It still doesn’t work and I get the following download trace:

	{
	  "trace": {
		"last_step": "action/0",
		"run_id": "b43dc65e969b854e2ba0ab587f9cbe98",
		"state": "stopped",
		"script_execution": "error",
		"timestamp": {
		  "start": "2024-03-08T23:02:22.936543+00:00",
		  "finish": "2024-03-08T23:02:22.955104+00:00"
		},
		"domain": "automation",
		"item_id": "1709930669830",
		"error": "None for dictionary value @ data['rgb_color']",
		"trigger": "webhook",
		"trace": {
		  "trigger/0": [
			{
			  "path": "trigger/0",
			  "timestamp": "2024-03-08T23:02:22.936700+00:00",
			  "changed_variables": {
				"this": {
				  "entity_id": "automation.1_test_bulb_1_webhook",
				  "state": "on",
				  "attributes": {
					"id": "1709930669830",
					"last_triggered": "2024-03-08T23:01:41.357312+00:00",
					"mode": "single",
					"current": 0,
					"friendly_name": "1 Test Bulb 1 Webhook"
				  },
				  "last_changed": "2024-03-08T23:01:13.519164+00:00",
				  "last_updated": "2024-03-08T23:01:41.364343+00:00",
				  "context": {
					"id": "01HRG4T0BCST6WFQD4Q428H99Q",
					"parent_id": "01HRG4T0BBWSX2VPTHMPNPSNCA",
					"user_id": null
				  }
				},
				"trigger": {
				  "platform": "webhook",
				  "webhook_id": "-webhook_id",
				  "json": {
					"rgb": [
					  255,
					  0,
					  0
					]
				  },
				  "query": {
					"__type": "<class 'multidict._multidict.MultiDictProxy'>",
					"repr": "<MultiDictProxy()>"
				  },
				  "description": "webhook",
				  "id": "0",
				  "idx": "0",
				  "alias": null
				}
			  }
			}
		  ],
		  "action/0": [
			{
			  "path": "action/0",
			  "timestamp": "2024-03-08T23:02:22.941754+00:00",
			  "changed_variables": {
				"context": {
				  "id": "01HRG4V8YRQRZZ583SRCX4EMB1",
				  "parent_id": null,
				  "user_id": null
				}
			  },
			  "error": "None for dictionary value @ data['rgb_color']",
			  "result": {
				"params": {
				  "domain": "light",
				  "service": "turn_on",
				  "service_data": {
					"rgb_color": "",
					"entity_id": "light.test_bulb_1"
				  },
				  "target": {}
				},
				"running_script": false
			  }
			}
		  ]
		},
		"config": {
		  "id": "1709930669830",
		  "alias": "1 Test Bulb 1 Webhook",
		  "description": "",
		  "trigger": [
			{
			  "platform": "webhook",
			  "allowed_methods": [
				"POST",
				"PUT"
			  ],
			  "local_only": false,
			  "webhook_id": "-webhook_id"
			}
		  ],
		  "condition": [],
		  "action": [
			{
			  "service": "light.turn_on",
			  "data": {
				"rgb_color": "{{ trigger.json[rgb] }}",
				"entity_id": "light.test_bulb_1"
			  }
			}
		  ],
		  "mode": "single"
		},
		"blueprint_inputs": null,
		"context": {
		  "id": "01HRG4V8YRQRZZ583SRCX4EMB1",
		  "parent_id": null,
		  "user_id": null
		}
	  },
	  "logbookEntries": [
		{
		  "name": "1 Test Bulb 1 Webhook",
		  "message": "triggered by webhook",
		  "source": "webhook",
		  "entity_id": "automation.1_test_bulb_1_webhook",
		  "context_id": "01HRG4V8YRQRZZ583SRCX4EMB1",
		  "when": 1709938942.936985,
		  "domain": "automation"
		}
	  ]
	}

I see the error at line 72, but I don’t know how to remedy. Thanks for the help and I think this should be fairly easy one I get the formatting down to include the json load.

so the trace has this:

			"trigger": {
				  "platform": "webhook",
				  "webhook_id": "-webhook_id",
				  "json": {
					"rgb": [
					  255,
					  0,
					  0
					]
				  },

so i think you do have the json load now (when you used my version w/ the quotes right)

i believe the issue is now exactly what the error message says…
“should be a string for dictionary value @ data[‘action’][0][‘data’]” with the quotes inside the brackets.

alias: 1 Test Bulb 1 Webhook
description: ""
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: false
    webhook_id: "-webhook_id"
condition: []
action:
  - service: light.turn_on
    data:
      rgb_color: "{{ trigger.json['rgb'] }}"
      entity_id: light.test_bulb_1
mode: single

This format worked. Tried it local and with the nabu.casa webhook url and it works great! Thank you. Thanks for the input and info on the download trace!