Checking the attribute in the condition

I need a condition check for if-that the attribute has not changed values for some time.
If the volume level has not changed in the last 5 seconds, then perform the action
Does a State element with an empty value perform the check I need? Or it is possible to check through templates?

If I were working with specific values, I would use a binary template sensor with delay_on. Or a similar template value. But in this case, the options are unclear to me.

Show us what the entity you’re working with that holds the volume looks like: screenshot from Developer Tools / States, showing entity, state and attributes columns.

Standard MediaPlayer entity
image

However, the question is of a general nature. Applies to any attribute of any entity.

I’m just checking you genuinely meant attribute and weren’t confused with state, which would have an easier solution via last_updated.

I’d do this with a trigger-based template sensor that updates to the current time whenever the volume changes, then create an automation with a template trigger checking if that sensor is more than five seconds away from the current time.

Yes, this is probably the only option.
Without the trigger part, the system will not start tracking any attribute changes.

According to the docs, this should work — have you tried it?

trigger:
  - platform: state
    entity_id: media_player.NAME
    attribute: volume_level
    for: "00:00:05"

This construction works in a trigger. But I need a condition check in the action block.
Any trigger is a subscription to the HAssistant’s event stream to catch the right one and pull the trigger.
Creating additional automation to track volume changes and then calculate the time stamp difference is the only solution. You said it right.

1 Like