#Save states of entity to reapply it in a later automation step

1 messages · Page 1 of 1 (latest)

rugged cove
#

I want to create an automation which lowers the volume of a given mediaplayer and in the last step it should be reset the volume to the value before starting the automation.

My try so far:

alias: Pause Audio while listening
description: Schalten Audio stumm, solange Home Assistant Voice aktiv ist
triggers:
  - trigger: state
    entity_id:
      - assist_satellite.ha_voice_office_assist_satellit
    to: listening
conditions: []
actions:
  - action: input_number.set_value
    data:
      value: "{{(state_attr('media_player.office','volume_level')|float)}}"
    target:
      entity_id: input_number.mm_volume
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.05
    target:
      device_id: <id>
    enabled: true
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - assist_satellite.ha_voice_office_assist_satellit
        to: idle
  - action: media_player.volume_set
    metadata: {}
    data:
      volume_level: "{{states('input_number.mm_volume')|float}}"
    target:
      device_id: <id>
    enabled: true
mode: single

But obviously the former state is either not saved to variable or not applied back.

#

Ok, I have to create the helper input_number.mm_volume first. Is there a way to create variables (scoped to automation) and not having to create a helper each time?

drifting shadow
#

yes, you can create varibles which are usable in the scope of the automatin