Keep button card icon on state change until button is pressed

Hi,

I have a button card on which the icon is changed when the state of a door sensor changes. The sensor state can be on or off.

mailbox_one_template:
        value_template: "{{ is_state('binary_sensor.neo_door_sensor_mailbox_sensor','on') }}"
        icon_template: "mdi:garage{{ '-open' if is_state('binary_sensor.neo_door_sensor_mailbox_sensor','on') else '' }}"

But I want the icon to stay when the state goes to ‘on’ as long as i don’t press the button. When i press the button the state has to go to off.

What is the best approach for this?

Hi,

Eventually I used MQTT to set the state once of a mailbox sensor entity to ‘On’ and use that entity in a custom button card. In the custom button card I used the state value off the entity do determine the color of the icon so I can see if the mailbox was opened. On button press I set the state to off so I know I already checked the mail until new mal arrives. Maybe not best practice but is does the job for me.

type: 'custom:button-card'
tap_action:
  action: call-service
  service: mqtt.publish
  service_data:
    topic: home/mailbox
    payload: 'Off'
icon: 'mdi:mailbox'
name: Mailbox
show_state: false
show_name: false
size: 10%
entity: sensor.mailbox
hold_action:
  action: none
state:
  - value: 'On'
    styles:
      icon:
        - color: red
  - value: 'Off'
    styles:
      icon:
        - color: green