I’m new at HA and I’m having an issue with a simple templated automation.
Any help would be much appreciated.
What I’m trying to achieve:
An http GET request gets sent to a server when a given light is turned off. Said request must contain a query parameter that only refers to that light and will be used by the server
What I have done:
1- In customize.yaml, I have associated a test lamp’s device_id with its specific query parameter:
# customize.yaml
# Test Lamp
light.wiz_rgbww_tunable_08aae2:
lamp_id: 1234567
2-In configuration.yaml, I have defined a generic action to be used by any light as it’s turned off:
3- In the HA GUI, I have defined the corresponding automation for the same test lamp:
Trigger: when Test Lamp turned off
Conditions: none
Actions: Call a service → rest_command.flag_device_turned_off
Result:
When I turn off the light, the logs do indicate the automation has run.
The server does receive a GET request, however its lamp_id parameter value is empty.
Replacing lamp_id=‘{{ lamp_id }}’ by lamp_id=1234567 in the action definition causes the server to receive the expected query.
Obviously I don’t have a correct view of how to make lamp_id a variable that is set at action time using the corresponding customize.yaml entry I set for the lamp’s device_id.
Post the actual automation configuration. In the automation editor click the 3-dot menu at the top right, select “Edit in YAML”, copy the whole config then paste it here with 3 back ticks ``` on the lines above and below what you pasted.
I doubt the syntax is the issue since the GET request does get sent. Plus this snippet is auto-generated from the GUI.
Somehow the expression {{ lamp_id }} is interpreted as if lamp_id were empty. If it wasn’t interpreted at all the braces would find their way to the query string.
Yes, I realize I had assumed that my entry in customize.yaml amounted to adding a permanent “tag” to the Test Lamp description. It obviously didn’t.
Thanks++ for the lead. I need to understand the fine print of what your proposed change means, though. As such it causes the automation to stop with the following log entry: “Error rendering data template: Result is not a Dictionary”.
You either figured this out or did it accidentally, but for anyone who finds themselves in a similar situation…
It means your customize.yaml file hasn’t been properly loaded since you added the lamp_id configuration. Restarting Home Assistant should reload all your YAML files and add the lamp_id attribute to the entity.