BatteryHeater with Relay and Dallas Temp Sensors

Hello everyone,

I am currently trying to build a battery heater with two Dallas Temp Sensors and a Relay Shield.

I would like the relay to be switched on if the TemperatureBattery sensor falls below a certain value.
However, if the second sensor TemperatureHZG1 exceeds a value, the relay should be switched off. If TemperatureHZG1 is now again below a level again, the relay should be switched on again, but only if the TemperatureBattery sensor is also below its target temperature. In other words, a type of overheating protection should be measured directly on the heating loop.

I have already tried this with a bang-bang config, this works so half if the TemperatureHZG1 has once caused the switch off the relay is no longer switched on because the TemperatureBattery sensor is still below its level.

climate:
  - platform: bang_bang
    id: batteryheatingcontroller
    name: "Battery Heating Controller"
    sensor: TemperatureBattery
    default_target_temperature_high: 25
    default_target_temperature_low:  23

    visual:
      max_temperature:  60
      min_temperature:  0
      temperature_step: 01

    heat_action:
      - switch.turn_on: batteryheater
    idle_action:
      - switch.turn_off: batteryheater

  - platform: bang_bang
    id: batteryoverheatingcontroller
    name: "Battery OverHeating ControllerOne"
    sensor: TemperatureHZG1
    default_target_temperature_high: 30
    default_target_temperature_low:  25

    visual:
      max_temperature:  60
      min_temperature:  0
      temperature_step: 01

    cool_action:
      - climate.control:
          id: batteryheatingcontroller
          mode: "OFF"
    idle_action:
      - climate.control:
          id: batteryheatingcontroller
          mode: "HEAT"

At the moment I am trying this with on_value_range: here the behavior is also similar.

sensor:
  - platform: dallas_temp
    address: 0xa602159246f99c28
    name: "TemperatureHZG1"
    id: TemperatureHZG1
    unit_of_measurement: "°C"
    icon: "mdi:thermometer-plus"
    device_class: "temperature"
    state_class: "measurement"
    accuracy_decimals: 1
    update_interval: 10s
    on_value_range:
    - above: 35.0
      then:
        - switch.turn_off: batteryheater
  - platform: dallas_temp
    address: 0xd102159246ca6628
    name: "TemperatureBattery"
    id: TemperatureBattery
    unit_of_measurement: "°C"
    icon: "mdi:thermometer-plus"
    device_class: "temperature"
    state_class: "measurement"
    accuracy_decimals: 1
    update_interval: 10s
    on_value_range:
      - below: 20.0
        then:
          - switch.turn_on: batteryheater
      - above: 35.0
        then:
          - switch.turn_off: batteryheater

Does anyone have an idea how I can solve this problem?

Thank You

i seem to have found a solution
works so far
:smile: was actually quite simple

    on_value_range:
      - below: 30.0
        then:
          - if:
              condition:
                lambda: |-
                  return id(TemperatureBattery).state < 20;
              then:
                - switch.turn_on: batteryheater
      - above: 40.0
        then:
          - switch.turn_off: batteryheater