Add emergency shutdown in automation for boiler overheating

Hi folks,
had a bigger problem last week as my water heater for the tub in the garden made itself and turned on at 0:00 with no external trigger. The problem was that not only did the sun not shine at night and therefore it was not really heated with the remaining solar power, but also that I had no temperature control in it that switched off the shelly as soon as one of the two sensors was over 80 degrees C. The boiler withstood the 120 degrees … not the garden hoses! :wink:
So yesterday I had a large steam boiler in the garden, which wasn’t planned :laughing:

I would like to expand my automation to the point, or create a second one, that ensures that the Shellys only switch when

sun.sun

is activated and
sensor.hotwater_temperature_tank_middle or
sensor.hotwater_temperature_tank_out

does not measure over 80 degrees C.

Unfortunately I can’t do it alone. Just too many loops and conditions… Thanks for your help.
Here is the previous automation:

alias: Steuerung PV WarmWasser
description: Nutzen der PV-Überschussleistung durch selektives Schalten von Verbrauchern
trigger:
  - platform: state
    entity_id:
      - binary_sensor.solar_uberschuss_stufe_0
    attribute: position
    from: above
    to: below
    for:
      hours: 0
      minutes: 0
      seconds: 10
    id: "0"
  - platform: state
    entity_id:
      - binary_sensor.solar_uberschuss_stufe_1
    attribute: position
    to: in_range
    for:
      hours: 0
      minutes: 0
      seconds: 5
    id: "1"
  - platform: state
    entity_id:
      - binary_sensor.solar_uberschuss_stufe_2
    attribute: position
    from: below
    for:
      hours: 0
      minutes: 0
      seconds: 5
    id: "2"
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: "0"
        sequence:
          - service: switch.turn_off
            data: {}
            target:
              entity_id:
                - switch.warmwasser_solar_garten_switch_0
                - switch.warmwasser_solar_garten_switch_1
      - conditions:
          - condition: trigger
            id: "1"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.warmwasser_solar_garten_switch_0
          - service: switch.turn_off
            data: {}
            target:
              entity_id:
                - switch.warmwasser_solar_garten_switch_1
      - conditions:
          - condition: trigger
            id: "2"
        sequence:
          - service: switch.turn_on
            data: {}
            target:
              entity_id:
                - switch.warmwasser_solar_garten_switch_1
          - service: switch.turn_off
            data: {}
            target:
              entity_id:
                - switch.warmwasser_solar_garten_switch_0
mode: single

thx for help !
meanwhile I use a old analog Timerscoket to disable the shelly at night … what a shame … :grinning: