Template switch won't work as expected on picture-elements card

I’ve created a template switch that controls 3 lamps and it works fine on an entities card:

  - platform: template
    switches:
      livingroomswitch:
        value_template: "{{ is_state('switch.lamp_four', 'on') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: 
              - switch.lamp_one
              - switch.lamp_two
              - switch.lamp_three
        turn_off:
          service: switch.turn_off
          data:
            entity_id: 
              - switch.lamp_one
              - switch.lamp_two
              - switch.lamp_three

However, when I place it on a picture-elements card it doesn’t turn the three lamps on and off:

    elements:
      - type: icon
        icon: mdi:lightbulb
        entity: switch.livingroomswitch
        tap_action: toggle
        style:
          top: 82%
          left: 19%

When I click the icon nothing happens. I want one icon that will turn off all lamps and when I click it again, it turns all lamps back on. I can do it with two icons with the code below, but I want only one icon to “toggle” between off and on. How do I do that?

      - type: state-icon
        entity: switch.livingroomswitch
        tap_action:
          action: call-service
          service: switch.turn_on
          service_data:
            entity_id: switch.livingroomswitch
        style:
          top: 85%
          left: 19%
      - type: state-icon
        entity: switch.livingroomswitch
        tap_action:
          action: call-service
          service: switch.turn_off
          service_data:
            entity_id: switch.livingroomswitch
        style:
          top: 85%
          left: 22%

After struggling for 24 hours, finally figured out it should be:

      - type: state-icon
        icon: 'mdi:ceiling-light'
        entity: switch.livingroomswitch
        tap_action:
          action: toggle
        style:
          top: 82%
          left: 19%
1 Like

wow thank you. I was struggling with the tap_action until I found your post.

1 Like