I have been unable to get a parameter passed from ESPHome to a HA script to work. I am only having a problem with scripts. I have number of cases where passing a parameter to a service and those work just fine. I have looked at the documentation on scripts and a number of forum entries/examples and still have not been able to get the script to work. There is no error generated in the log file so am at a loss as to what could be wrong. I know the ESPHome code and the script works if I hard code the entity_id in the script. Once i replace the entity_id with ‘{{ entity_id }}’ it no longer works. The code for each is below.
---- ESPHome yaml code -------------------------
## Backdoor lock button
- platform: nextion
id: backdoor_lock
name: $device_name Toggle Backdoor Lock
page_id: 2
component_id: 5
on_click:
- homeassistant.service:
service: script.lock_toggle_backdoor
data:
entity_id: lock.schlage_touchscreen_deadbolt
------ script yaml with parameter entity_id --------------------
lock_toggle_backdoor:
alias: Toggle Backdoor Lock
fields:
entity_id:
description: Lock Entity ID
example: lock.front_door
required: true
selector:
entity:
domain: lock
sequence:
- service: >
{% if states( "'{{ entity_id }}'" ) == "locked" %}
lock.unlock
{% else %}
lock.lock
{% endif %}
data:
entity_id: '{{ entity_id }}'
mode: single
icon: mdi:lock
--------------- script with hard coded entity that works --------------
lock_toggle_backdoor:
alias: Toggle Backdoor Lock
fields:
entity_id:
description: Lock Entity ID
example: lock.front_door
required: true
selector:
entity:
domain: lock
sequence:
- service: >
{% if states( "lock.schlage_touchscreen_deadbolt" ) == "locked" %}
lock.unlock
{% else %}
lock.lock
{% endif %}
data:
entity_id: lock.schlage_touchscreen_deadbolt
mode: single
icon: mdi:lock
Can someone identify what I am doing wrong?