Seeking help with triggering a script w/ input_button

I have created an automation that I want to trigger with a helper button: input_button.office_light_flash

I can run the automation and it works, but when I press the button it does not trigger. What am I missing?

alias: Flash Office Lights
description: Flash Office Lights
triggers:
  - entity_id: input_button.office_light_flash
    from: "off"
    to: pressed
    trigger: state
conditions: []
actions:
  - variables:
      original_brightness: "{{ state_attr('light.floor_lamp', 'brightness') | default(0) }}"
      target_state: |
        {% if original_brightness <= 128 %}
          255
        {% else %}
          64
        {% endif %}
  - repeat:
      count: 3
      sequence:
        - choose:
            - conditions:
                - condition: template
                  value_template: "{{ original_brightness == 0 }}"
              sequence:
                - target:
                    entity_id: light.floor_lamp
                  action: light.turn_off
                  data: {}
            - conditions:
                - condition: template
                  value_template: "{{ original_brightness > 0 }}"
              sequence:
                - target:
                    entity_id: light.floor_lamp
                  data:
                    brightness: "{{ target_state | int }}"
                  action: light.turn_on
        - delay: "00:00:00.5"
        - choose:
            - conditions:
                - condition: template
                  value_template: "{{ original_brightness == 0 }}"
              sequence:
                - target:
                    entity_id: light.floor_lamp
                  action: light.turn_off
                  data: {}
            - conditions:
                - condition: template
                  value_template: "{{ original_brightness > 0 }}"
              sequence:
                - target:
                    entity_id: light.floor_lamp
                  data:
                    brightness: "{{ original_brightness | int }}"
                  action: light.turn_on
        - delay: "00:00:00.5"
  - target:
      entity_id: input_button.sam_office_light_flash
    action: input_button.press
    data: {}
mode: single

input_button does not have an actual state, as explicitely said in the documentation. Its state is the timestamp it was last triggered.

So use

  - entity_id: input_button.office_light_flash
    trigger: state
1 Like

After making the necessary changes Koying has provided you may see additional errors.

I’d suggest | int(0) or | float(0) vs | default(0)

actions:
  - variables:
      original_brightness: "{{ state_attr('light.floor_lamp', 'brightness') | int(0) }}"
      target_state: |
        {% if original_brightness  <= 128 %}
         255
        {% else %}
         64
        {% endif %}

I’d suggest researching Integers vs String

2 Likes