Can someone show me how to store the volume of an input number helper to a variable before running a script in an automation and then replace the original volume after the script inside the automation runs

Thank you all in advance for the guidance you give on the below. I feel like I know what I want to do, I just don’t know how to actually do it.

Below is the name of the helper I am using:

input_number.tts_volume

I would just like to store the value of “input_number.tts_volume” before this part happens:

And then after that happens, I would set the volume back to what it was before this portion ran.

      - service: script.jarvis_alert
        data_template:
          message: Turning on Dog Mode.

Below is the automation I have.

- id: dog_mode_activated
  alias: Dog Mode Activated
  description: If done via motion annouce in kitchen. If manually just text.
  trigger:
  - platform: state
    entity_id: binary_sensor.gym_motion_sensor
    to: 'on'
  - platform: state
    entity_id: input_boolean.dog_mode
    to: 'on'
  action:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ trigger.to_state.attributes.friendly_name == "Dog Mode"
          }}'
      sequence:
      - service: script.text_notify
        data:
          who: parents
          title: Dog Mode
          message: Dog Mode has been enabled manually
          data:
          group: modes
          tag:
      - service: script.dog_mode_lighting_on
      - delay:
          minutes: 20
      - service: input_boolean.turn_off
        entity_id: input_boolean.dog_mode
    - conditions:
      - condition: or
        conditions:
        - condition: state
          entity_id: alarm_control_panel.alarmo
          state: armed_night
      - condition: state
        entity_id: group.family
        state: home
      sequence:
      - service: input_boolean.turn_on
        entity_id: input_boolean.dog_mode
      - service: script.jarvis_alert
        data_template:
          message: Turning on Dog Mode.
      - service: script.dog_mode_lighting_on
mode:single
variables:
  original_volume: "{{ states('input_number.tts_volume')|int(0) }}"

then later

- service: input_number.set_value
  value: "{{ original_volume }}"
  entity_id: input_number.tts_volume
1 Like

Thank you so much for showing me this!!

1 Like