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

Like most, I have a bunch of automations for my lights. For instance, the kitchen lights are motion activated, and turn off if there has been no motion for three minutes. I move like a sloth though, thus the lights keep on turning off while I’m eating breakfast. Oppositely, my wife likes to eat in the dark, so she keeps swearing at the damn light turning on all the time.

So I wanted a “light state lock” but couldn’t find one, so I tried it myself and had some success using conditional cards, custom-fields and card-mod, but its extremely messy and doesn’t work all that well, and it looks terrible in the companion app.

There must be a simpler/better way of doing it (with scripts and templates?)!

Here are the scenarios, I might have forgotten one, but I think its clear how it should work. what I want to happen…

Someone must have already made this functionality, right? Or else, I would appreciate any helpful tip on how to make this work well, logically, and responsively at the same time.

I made a template switch that turns the related set of automations on and off, then in my dashboard button I use double_tap to toggle that template switch. My button conditionally shows the lightbulb icon when the template switch is off, and the lightbulb with a small A next to it when it’s on. The light itself toggles with normal press of the button and changes the button background color appropriately.

Cool Keith! I’ve not yet begun to learn about templates, could you perhaps share what it looks like?

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
- platform: template
      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' }}"
        service: automation.turn_on
          - automation.garage_light_auto_on_when_any_doors_open
          - automation.garage_light_auto_off_timeout
          - automation.garage_light_auto_off_warning_flash
        service: automation.turn_off
          - 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" ]]]'
  action: call-service
  service: homeassistant.toggle
    entity_id: switch.garage_lights_automation

Thanks Keith, I think I understand how this works!