I’m not sure if what I’m trying to do is possible or if I just have the syntax wrong. I have a floorplan dashboard with icons and badges for my various sensors around the house. I would like to have my front door lock or unlock, based on current state, after a long press on the icon. I’m assuming the way I need to accomplish this is through the use of templating but I can’t seem to get it quite right and I’m not sure where errors might be logged.
Failed to call service {% if is_state('lock/front_door_lock', 'locked') %} service: lock. Service not found.
I needed to remove the braces after the data field, that also kicked up an error. And the forward slash inside the is_state call isn’t a typo. It looks like it’s not parsing this as a template.
My home assistant is under maintenance, I can’t validate what I’m writing.
You should always test your templates in the developer tools.
Not sure that you can put a tempate there but can’t test now, the other solution is to call a script that will do the template.
That got things working! Created a script with a simple if statement to toggle based on lock state. Changed the hold_action to call the script and I’m in business. Thank you for the clarifications @Olivier1974 and @Didgeridrew!!
For future reference:
- type: state-icon
entity: lock.front_door_lock
tap_action: []
hold_action:
action: call-service
confirmation:
text: This will TOGGLE the front door lock. Are you sure?
service: script.toggle_door_lock
By using Didgeridrew’s suggestion but marking your own post with the Solution tag, you have misunderstood how that tag is used in this community forum.
Refer to guideline 21 in the FAQ. The Solution tag’s purpose is to mark the first post that explains how to solve the problem. Without Didgeridrew’s suggestion, you wouldn’t know how to solve the problem so obviously you didn’t solve it and Didgeridrew did. Therefore please consider marking Didgeridrew’s post with the Solution tag.