SOLVED: Trying to make a card for my lock

So my idea is ‘simple’.
I want an image to show the state of the lock, and pressing it changes the state.
So far I’ve gotten an image to show the state by using a picture glance.

type: picture-glance
show_state: false
show_name: false
entities:
  - lock.poly_control_danalock_v3_btze_locked
state_image:
  locked: /local/locked.png
  unlocked: /local/unlocked.png
entity: lock.poly_control_danalock_v3_btze_locked

Now this shows the state, unfortunately I see a few problems, the image gets very large, as it fills out the width


It also shows they grey bar, despit I’ve set show_state: false

So how do I scale the image down, and get rid of the bottom grey bar?

But I guess the really tricky part is the actions, with a lock I don’t have a ‘toggle’ action, only a ‘lock’ and ‘unlock’.
So how do I call the right service based on the state of the lock?

Ok, so I think I figured out that I need to do a template for the ‘state sensitive’ service that is to be placed as a ‘tap_action’.
I’ve placed this in the ‘templates.yaml’:

service_template: >
  {% lock.poly_control_danalock_v3_btze_locked = "locked" %}
    lock.unlock
      {
        "entity_id": "lock.poly_control_danalock_v3_btze_locked"
      }
  {% else %}
    lock.lock
      {
        "entity_id": "lock.poly_control_danalock_v3_btze_locked"
      }
  {% endif %}
entity_id: lock.toggle  

I thought that would create a service called lock.toggle, but I don’t see anything in the services list.
What have I misunderstood?

Ok, so after seeing some errors in the way I did it, I’ve changed it to this, but I’m still not sure if I’m doing it right, as I don’t see anything:

service_template: >
  {% if is_state('lock.poly_control_danalock_v3_btze_locked', 'locked' %}
    lock.unlock
      {
        "entity_id": "lock.poly_control_danalock_v3_btze_locked"
      }
  {% else %}
    lock.lock
      {
        "entity_id": "lock.poly_control_danalock_v3_btze_locked"
      }
  {% endif %}
entity_id: something.lock.toggle

I just added the lock to the appdaemon dashboard, and there it does exactly what I want it to, clearly shows if the lock is locked, and if I press it, it will toggle the lock.

GOT IT SOLVED. WEEHEE.

So, picked up a custom button card:

Then this is the config for the lock, and it looks perfect!
2019-05-17_1820
I placed the button above the picture, as the picture takes a second or two to show, and then you end up clicking on the image when it appears.

The button is configured as below, not that the actions are moved to under the state, so that each state has it’s own action, very very nice!

type: horizontal-stack
cards:
  - type: 'custom:button-card'
    color_type: blank-card
  - type: 'custom:button-card'
    color_type: blank-card
  - type: 'custom:button-card'
    entity: lock.poly_control_danalock_v3_btze_locked
    name: Fordør
    show_state: true
    state:
      - value: locked
        icon: 'mdi:lock'
        color: green
        tap_action:
          action: call-service
          service: lock.unlock
          service_data:
            entity_id: lock.poly_control_danalock_v3_btze_locked
      - value: unlocked
        icon: 'mdi:lock-open'
        color: red
        tap_action:
          action: call-service
          service: lock.lock
          service_data:
            entity_id: lock.poly_control_danalock_v3_btze_locked
  - type: 'custom:button-card'
    color_type: blank-card
  - type: 'custom:button-card'
    color_type: blank-card
1 Like

This doesn’t seem to work anymore. I’m guessing the custom:button-card was updated and it broke the state-based actions? I copied/pasted your code above for the lock card, and whenever I tap, it pulls up the info on the lock, with the options to Lock or Unlock.

Could you tell me what version of the custom:button-card you’re running? I would be willing to downgrade to get this simple functionality.

Thanks - Jonesie

1 Like

Yes, it was updated on 0.108 as far as I remember.
I’ve moved it to a vertical stack, as I’ve added the videodoorbell video below the lock button, but that can be removed if you wish:

cards:
  - cards:
      - color_type: blank-card
        type: 'custom:button-card'
      - entity: lock.poly_control_danalock_v3_btze_locked
        name: Hoveddør
        show_entity_picture: true
        state:
          - entity_picture: /local/images/lock-locked.png
            value: locked
          - entity_picture: /local/images/lock-unlocked.png
            value: unlocked
        style: |
          ha-card{background:transparent;box-shadow: none;}
        tap_action:
          action: call-service
          service: >-
            [[[ return entity.state === "locked" ? "lock.unlock" : "lock.lock"
            ]]]
          service_data:
            entity_id: entity
        type: 'custom:button-card'
      - color_type: blank-card
        type: 'custom:button-card'
    type: horizontal-stack
type: vertical-stack
3 Likes

I will give this a try this week! Thank you, sir!

Jonesie

Hi,

Any success? I didn’t quite get this one to work :confused:

Yes, my working config (as of 0.114.4) for my doorlock button looks like this:

entity: lock.poly_control_danalock_v3_btze_locked
name: Hoveddør
show_entity_picture: true
state:
  - entity_picture: /local/images/lock-locked.png
    value: locked
  - entity_picture: /local/images/lock-unlocked.png
    value: unlocked
style: |
  ha-card{background:transparent;box-shadow: none;}
tap_action:
  action: call-service
  service: '[[[ return entity.state === "locked" ? "lock.unlock" : "lock.lock" ]]]'
  service_data:
    entity_id: entity
type: 'custom:button-card'

So I have two pictures that I use to display if it’s locked or not.
And depending on the state of the lock, I call an ‘unlock’ or ‘lock’ command.
So it just has one ‘tap action’ and the service call is magically changed upon the the state of the lock.

2 Likes

Just wondering if this last sample bit of code still works?
I am essentially trying to achieve the same thing but when I “tap” on the icon, i get an error that indicates that the lock.service is not found.

A variation of my situation from what’s shown above is that I’m using it on a binary_sensor entity for a door, and then i’m tapping on it to lock/unlock the door lock that’s associated with that door.

              - type: 'custom:multiple-entity-row'
                entity: binary_sensor.garage_entry
                entities:
                  - entity: lock.garage_entry_lock
                    name: Door is
                    tap_action:
                      action: call-service
                      service: |
                        [[[ 
                          return (entity.state === "locked") ? "lock.unlock" : "lock.lock"; 
                        ]]]
                      service_data:
                        entity_id: entity

i’m assuming it’s because the “entity_id: entity” on the last line is what’s probably causing the issue because the main entity is a door and i’m calling for an action for a lock. I’ve tried replacing “entity” with the actual lock’s entity, “lock.garage_entry_lock” without success. I think the syntax of mine is still wrong … (duh) … can anyone help?

Hej J Tang

Not sure what you try to accomplish, it seems the config snippet is not complete.
I would suggest you build the config for the locking button ‘outside’ of the multiple-entity-row, make it work there, and then move it to the multiple-entity-row afterwards.

I have a danalock v3 btze, connected to aeotec. I use zigbee, but this lock is much older than the HA setup, so it was z-wave.

The lock gives me these entities:

  • lock.frontdoor_lock_mode
  • sensor.frontdoor_lock_battery_level
  • binary_sensor.frontdoor_lock_low_battery_level
  • binary_sensor.frontdoor_lock_jammed
  • binary_sensor.frontdoor_lock_current_state
  • sensor.z_wave_controlled_door_lock_with_bluetooth_smart_access_control_lock_state
  • sensor.z_wave_controlled_door_lock_with_bluetooth_smart_alarmlevel
  • sensor.z_wave_controlled_door_lock_with_bluetooth_smart_alarmtype

So the one to manipulate is the lock.frontdoor_lock_mode (as it has the lock.*)

The button I have for this is:

entity: lock.frontdoor_lock_mode
name: Hoveddør
show_entity_picture: true
state:
  - entity_picture: /local/images/lock-locked.png
    value: locked
  - entity_picture: /local/images/lock-unlocked.png
    value: unlocked
tap_action:
  action: call-service
  service: '[[[ return entity.state === "locked" ? "lock.unlock" : "lock.lock" ]]]'
  service_data:
    entity_id: entity
type: 'custom:button-card'

So first part of my config is that I show two different pictures if it’s locked or not.
Secondly the tap_action is for when you press the picture shown.
The service to call, depends on whether the entity used in the button-card has a state of locked or not, that is why it refers to ‘entity’ simply, that will take the entity from the button-card.

Apologies for not explaining it very well, but since a picture is worth a thousand words …
lock

This is a custom card (multiple entity row) and the problem I encounter is that the “main” entity associated with it is a binary_sensor (a door), not a lock. What I’m trying to achieve is for the tap_action to (un)lock the locking device for the door. Since there is no “lock” service for the binary_sensor, it is throwing an error indicating that the lock.service is not available.

I need some guidance to redirect the “entity_id: entity” to not be directed to the main entity, but to the secondary entity.

1 Like