Toggle switch in glace chart

Dear HA enthusiasts,

I have very a basic question which drives me nuts:

I’m setting up a “glance” card where I have included several switches, e.g., “- switch.xyz”. How can I add a toggle action to these switches? In case of a “standard entity” I usually add “toogle” as “tap_action” which works fine. But how can I add a toogle action to a “- switch.xyz” as mentioned above?

Thanks in advance and kind regards,
Roman.

have you tried something along the lines

tap_action:
  action: call-service
  service: switch.toggle
  service_data:
    entity_id: switch.xyz
1 Like

Hello lolouk44,

thank you very much for your response. With your help, I got it up and running. If someone else stumbles over the same problem, I will post below my working solution:

        entities:
          - entity: switch.xyz
            tap_action:
             action: call-service
             service: switch.toggle
             service_data:
               entity_id: switch.xyz

Thanks again and kind regards from Roman.

1 Like

Good afternoon,

I have tried the solution above with “lock.starnuki” of my smart lock in order to toggle the lock and unlock state by replacing “switch.xyz” by “lock.starnuki” in the snippet above. However, this doesn’t seem to work as nothing happens when I click in the icon. Any idea which this doesn’t work?

Thanks in advance and kind regards,
Roman.

On some of my devices I’ve had to create custom switches, my lock included. Here’s a snip from my switches.yaml:

- platform: template
  switches:
   driveway_door_lock:
     friendly_name: "Driveway Door Lock"
     value_template: "{{ is_state('lock.driveway_door_lock', 'unlocked') }}"
     turn_on:
       service: lock.unlock
       data:
         entity_id: lock.driveway_door_lock
     turn_off:
       service: lock.lock
       data:
         entity_id: lock.driveway_door_lock
1 Like

Dear Markus99,

thanks for the tip which seems to work fine! :slight_smile:

Just one minor thing that doesn’t currently work as expected: I have implemented the switch in a glance card, where the status “OFF” is shown when the door lock is locked. Do you have any idea how to display the status “Locked” instead. Evidently, it would be nice to display “Unlocked” for an unlocked status.

Kind regards,
Roman.

Guess it depends on how / where you’re trying to use / display it. You can certainly then setup custom sensor(s), this thread explains this further: Changing the States displayed on the frontend of a entity

Personally, I simply display that switch based on a condition and only when it’s ‘on’ - so I never really see the ‘on’ / ‘off’ state - only the result of it via the UI:

image

I use this in ui-lovelace.yaml to display it:

      - type: conditional
        conditions:
          - entity: binary_sensor.front_gate_contact
            state_not: "off"
        card:
          type: entities
          entities:
            - entity: switch.front_drive_gate
              name: Front Gate
              tap_action:
                action: toggle

So it’s only shown when it’s NOT OFF (aka Open)

1 Like

One last thing, if you want to display these in a GLANCE card, then you can also customize the icon/image (by using a custom image [which you can create / download from MDI (https://materialdesignicons.com/) and upload to your /config/www directory (where mine are referenced). Note the entity_picture_template section (which I omitted for brevity in my post above).

- platform: template
  switches:
   front_drive_gate:
     friendly_name: "Front Driveway Gate"
     value_template: "{{ is_state('binary_sensor.front_gate_contact', 'on') }}"
     turn_on:
       service: switch.toggle
       data:
         entity_id: switch.front_gate
     turn_off:
       service: switch.toggle
       data:
         entity_id: switch.front_gate
     entity_picture_template: >-
       {% if is_state('binary_sensor.front_gate_contact', 'on') %}
         /local/gate-open.png?v=5
       {% else %}
         /local/gate-closed.png?v=5
       {% endif %}

Here’s how it then looks in a glance card:
image

I did the same for my garage doors, fwiw. Anyhow, cheers!

1 Like

Dear Markus99,

your link was gold and very interesting to read. I’ve set a bookmark because I am sure that I will need this info in the near future. :grinning: Thanks!

What I currently have at my GLANCE card looks like this image:

nuki

Two things are currently wrong with this image. First, the current status of the lock is “unlocked” and the icon is highlighted in yellow. IMHO, a yellow icon would be more appropriate for the “locked” status. Second, the label states “On” for the “unlocked” lock. It would be nice to show “locked” for a locked state and “unlocked” for an unlocked state instead of “Off” and “On” in the GLACE card, respectively.

I will play around with the settings later today.

Kind regards,
Roman.

Glad I could ‘help’ somebody! I haven’t been doing this for too long myself, and there’s a ton of people here who know a TON more than I, but tinkering enough I’ve figured a bit out.

Personally, I use BLUE icons for closed / off and YELLOW for open / on. Your personal preference is allowed to be whatever you’d like :slight_smile: Here’s my open gate and closed garage at present:
image
So for the garage I made a blue closed icon (one on left) and then a yellow open (one on right)
image
materialdesignicons.com also has a few unlocked icons (though I’ve found not all of these work by default in HA, if you’re making them custom, doesn’t matter…)

  • lock-open-outline
  • lock-open-variant-outline

The two above are the outline ones below
image
I think w/out using something other than a typical glance card, the only other way to do change the ‘state’ is to create a custom sensor which reports ‘open’ or ‘locked’ or ‘unlocked’ and then have two rows ‘stacked’ - something like this thread (Display both state and last_changed in glance?)

Something like this:

    gate_friendly_status:
      friendly_name: "Friendly Gate Status"
      value_template: >-
       {% if is_state('switch.front_drive_gate', 'on') %}
         open
       {% else %}
         closed
       {% endif %}

Again, there might be a custom card someone’s design out there, but I’ve decided on my glance cards that having them show a different color when they’re open/on/unlocked is enough for me to quickly tell - w/out having to show their exact state - so I personally haven’t gone this extra-sensor route.

1 Like

Dear Markus99,

I thought about the color choice for locked and unlocked states and you’re right. Yellow indicating an unlocked state is much better because in this way I am visually notified if I forgot to lock the door.

I will play around with the custom icon settings and will try to implement the “LOCK” and “UNLOCKED” label in my GLANCE card.

Btw, right now, my overview panel looks like this:

Looks great!

I will say to be careful with revealing your HA URL in screenshots. Always better safe than sorry!

Hi!

*.starnet is my local network, i.e., 192.168.whatever is operated from my local DNS server and thus only accessible from my LAN. I don’t use HA access from the internet.

Kind regards,
Roman.