Two changes in sequence with some delay

Hi All,

Sorry if that question has already been raised - i am not really sure how to do the following:

Add a single button which performs the following:

  1. Set a state (“loading warm water”) to true and set another state (“load water for 2 hours”) to true
  2. Wait until another state (“Warm water tempeature”) reached 50 degree
  3. As soon as the temp. level is reached → set another state (thermal desinfection) on true → stop.
    In case between during 2 and 3 the warm water loading was stopped, ofc the action shouldn’t wait anymore.

Goal: My heatpump is senselessly starting the heating rod at 40 degree water temperature when I am starting the desinfcetion mode here…I want to avoid that by first heating up the water to the maximum “meaningful” temperature using the heatpump, and only than start the heating rod.

For what keyword do I have to search to implement such logical sequences in home assistant?

Thanks a lot for your help!
Timo

Remark to myself… should ask such beginner questions to chatgpt first…I got the following snippet and will try to adjust it to my states. If I get It working i will update the script

automation:
  - alias: "Warm Water Desinfection"
    trigger:
      platform: state
      entity_id: input_boolean.start_warm_water_desinfection
      to: "on"
    action:
      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.loading_warm_water

      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.load_water_for_2_hours

      - wait_template: "{{ states('sensor.warm_water_temperature') | float >= 50 or is_state('input_boolean.loading_warm_water', 'off') }}"

      - condition: state
        entity_id: input_boolean.loading_warm_water
        state: "on"

      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.thermal_desinfection

      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.loading_warm_water
        # Optionally turn off "load_water_for_2_hours" if needed

      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.load_water_for_2_hours