I have 2 Zwave locks that I use the custom:button-card to show the lock status and change colour based on lock’s status. That is all working well.
The issue is when I click the lock, it opens the entity’s history of locked/unlocked. I would rather tap action either lock or unlock depending on it’s current state. Here’s what my code looks like:
- entity: lock.front_door
type: 'custom:button-card'
icon: mdi:lock
size: 50px
state:
- value: "locked"
color: green
icon: mdi:lock
tap_action:
action: call-service
service: lock.unlock
service_data:
entity_id: lock.front_door
- value: "unlocked"
color: red
icon: mdi:lock-open-variant
tap_action:
action: call-service
service: lock.lock
service_data:
entity_id: lock.front_door
The above config is not generating any errors, but tapping the icon still opens the history rather than calling the associated service.
Thanks for any help.
petro
(Petro)
April 28, 2020, 11:22am
2
tap action indentation is wrong
- entity: lock.front_door
type: 'custom:button-card'
icon: mdi:lock
size: 50px
state:
- value: "locked"
color: green
icon: mdi:lock
tap_action:
action: call-service
service: lock.unlock
service_data:
entity_id: lock.front_door
- value: "unlocked"
color: red
icon: mdi:lock-open-variant
tap_action:
action: call-service
service: lock.lock
service_data:
entity_id: lock.front_door
I also notice that you’re using odd intendation all over the place. Pick a value and stick with it. Makes for easier reading.
Looks like it formatted wrong when I pasted compared to what’s in the yaml. Second tap action is on the same level of the first set. Neither works.
- entity: lock.front_door
type: 'custom:button-card'
icon: mdi:lock
size: 50px
state:
- value: "locked"
color: green
icon: mdi:lock
tap_action:
action: call-service
service: lock.unlock
service_data:
entity_id: lock.front_door
- value: "unlocked"
color: red
icon: mdi:lock-open-variant
tap_action:
action: call-service
service: lock.lock
service_data:
entity_id: lock.front_door
petro
(Petro)
April 28, 2020, 11:32am
4
Your tap action is indented on value, it’s flat out wrong.
I want separate tap actions based on the lock’s current value. If locked, tap action unlocks. If unlocked. tap action locks.
petro
(Petro)
April 28, 2020, 11:35am
6
Then you have to template it. Look at the state level, it does not have tap_action as a valid option for state. I.E. wrong… like i’ve said twice now.
Oh templating, a whole new beast.
Appreciate the guidance, thanks!
petro
(Petro)
April 28, 2020, 11:39am
8
- entity: lock.front_door
type: 'custom:button-card'
icon: mdi:lock
size: 50px
state:
- value: "locked"
color: green
icon: mdi:lock
- value: "unlocked"
color: red
icon: mdi:lock-open-variant
tap_action:
action: call-service
service: |
[[[
return (entity.state === 'locked') ? 'lock.unlock' : 'lock.lock';
]]]
service_data:
entity_id: lock.front_door
4 Likes
Wow. Again, many thanks. I was just trying to write the code myself, but this is much cleaner.
Thank you!!
Klagio
(Klagio)
December 25, 2020, 6:38pm
10
Hi I am trying to do the same and a search brought me here. I change the code as below but I get an error while tapping the lock
I get a popup Failed to call service [[[
- type: 'custom:button-card'
entity: lock.front_door
type: 'custom:button-card'
icon: mdi:lock
size: 50px
state:
- value: "locked"
color: green
icon: mdi:lock
- value: "unlocked"
color: red
icon: mdi:lock-open-variant
tap_action:
action: call-service
service: |
[[[
return (entity.state === 'locked') ? 'lock.unlock' : 'lock.lock';
]]]
service_data:
entity_id: lock.car_door_lock
``
esenterre
(Éric Senterre)
February 16, 2021, 9:15pm
11
I don’t know if you fixed your problem yet. But I see a problem in your code.
Second line you tell entity: lock.front_door
and on the last line lock.car_door_lock
. I suppose you have a problem there.
BUT, I also tried that code from @petro and get the same error message as you (but use the same entity name in my case).
j3tang
(J Tang)
August 25, 2021, 3:33pm
12
I seem to get the same error, does this no longer work?
catchdave
(CatchDave)
August 6, 2022, 6:32pm
13
I found that simply using toggle
worked without using service
. This is what works for me:
tap_action:
action: toggle
1 Like
That works for me too. Thank you!