How to create a "light state lock" inside a button card?

Sure thing. I wasn’t at my computer last time, but I am now.

Note, the normal dashboard button doesn’t have scripting, so I am using the excellent custom button card that I got via HACS. If you don’t want to use a custom card you can probably achieve the dynamic icon with another template entity to represent your light. It’s worth the time to learn the custom button card though, as it is quite powerful. I have another topic I created that explains a lot more about how I’m using the custom button card if you are curious. I have a few other related posts too, which you should be able to find if you drill into my profile.

template switch to control the set of automations, defined in configuration.yaml
switch:
- platform: template
  switches:
    garage_lights_automation:
      friendly_name: Garage Lights Automation
      unique_id: template_switch_garage_lights_automation
      value_template: "{{ is_state('automation.garage_light_auto_off_timeout', 'on') }}"
      icon_template: "{{ 'mdi:lightbulb-auto' if is_state('automation.garage_light_auto_off_timeout', 'on') else 'mdi:lightbulb' }}"
      turn_on:
        service: automation.turn_on
        entity_id: 
          - automation.garage_light_auto_on_when_any_doors_open
          - automation.garage_light_auto_off_timeout
          - automation.garage_light_auto_off_warning_flash
      turn_off:
        service: automation.turn_off
        entity_id: 
          - automation.garage_light_auto_on_when_any_doors_open
          - automation.garage_light_auto_off_timeout
          - automation.garage_light_auto_off_warning_flash
custom button card with dynamic icon
type: custom:button-card
entity: switch.garage_lights
name: Groj
icon: '[[[ return states["switch.garage_lights_automation"].state == "on" ? "mdi:lightbulb-auto" : "mdi:lightbulb" ]]]'
double_tap_action:
  action: call-service
  service: homeassistant.toggle
  service_data:
    entity_id: switch.garage_lights_automation
2 Likes