Automation debounce by trigger entity_id

I’d like to debounce my automation based on a condition that it’s been 1 second since the last run:

{{ as_timestamp(now()) -
   as_timestamp(state_attr('automation.color_correct_lifx_a21', 'last_triggered')) | default(0) > 1 }}

But the problem is, I want to check when the 'last_triggered' occurred for a given entity id. I have 7 entities that could cause this to trigger, and I want each one to have a separate timer they’re checking against for 'last_triggered'.

Is that possible or do I have to create 7 copy-pasted automations?

Post the automation’s YAML so we can see all of its triggers and the 7 entities you mentioned.

1 Like


This is the YAML:

alias: Color-correct LIFX A21
description: >-
  Correct Color Temperature in LIFX A21 bulbs. They appear to be 500 Kelvin
  lower than the value you set in Home Assistant or the LIFX app. Bumping up
  only these lights allows using existing automations.
  - platform: state
      - light.living_room_lamp_2
      - light.dining_room_1_2
      - light.dining_room_2_2
      - light.dining_room_3_2
      - light.guest_bedroom_bedside_lamp_2
      - light.lifx_a21_color_1600
    attribute: color_temp_kelvin
  - condition: template
    value_template: |
      {{ as_timestamp(now()) -
         as_timestamp(state_attr('automation.color_correct_lifx_a21', 'last_triggered')) | default(0) > 1 }}
  - service: lifx.set_state
      entity_id: >-
        {{ area_entities(device_attr(trigger.entity_id, 'area_id')) |
        select('is_device_attr','model','LIFX A21 1600lm US') | list }}
      color_temp_kelvin: >
        {% set current_kelvin = state_attr(trigger.entity_id,
        "color_temp_kelvin") | default(3500) %} {{ current_kelvin + 500 }}
mode: parallel
max: 20
  running_entities: []

What is the time value for each one?

What do you mean by “time value”? last_triggered is something part of Home Assistant. I don’t know how to console.log or print that somewhere. I got the code originally from ChatGPT.

You said:

If you have 7 entities and you want each one to “have a a separate timer” then what is the time value of each timer? Or is the time value the same for all of them? In your example, it’s 1 second.

Then it’s 1 second for all of them :+1:.