Help with code for control of Truma Ultraheat (caravan/motorhome heater)

I am working on an ESP32 project. I am replacing Truma’s ultraheat control and replacing it with an ESP 32 and an SSM1306 Display. I’m happy to share blueprints/hardware if anyone else is interested.

I would need help with 2 things. I dont think it’s that hard, but i’m stuck.

( relay 1-3 is pulled by differences in temperature.)

First:
(conditions below Dallas)
I would like the conditions for 1000w to only run if also GPIO16 (id= activate1kw) is true.
The condition for 2000W only if also the condition for 2000W GPIO23 (id= activate2kw) and GPIO16 (id= activate1kw) is true

next thing:
(Binary sensor)
If GPIO 25 id= turnoff is false, i wont all three relays to turn off, and i want them off untill GPIO25 is true

Plz help me :slight_smile:

captive_portal:

web_server:
  port: 80
  auth:
    username: admin
    password: '123456'  

button:
  - platform: restart
    name: "Omstart"  
    icon: "mdi:emoticon-outline"

dallas:
  - pin: 13
    id: hub_1
    #update_interval: 120s
  
sensor:
  - platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 60s
    entity_category: "diagnostic"

  - platform: copy # Reports the WiFi signal strength in %
    source_id: wifi_signal_db
    name: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    entity_category: "diagnostic"
    device_class: ""

  - platform: uptime # Uptime
    name: "Uptime Sensor"

  - platform: dallas
    dallas_id: hub_1
    address: 0x5474ddbf0a646128
    name: "Temperatur"
    id: temp
    on_value_range:

        # Turn Off Heaters
      - above: !lambda "return id(set_temp).state + 0.5;"
        then:

          - switch.turn_off: relay_1
          - switch.turn_off: relay_2
          - switch.turn_off: relay_3

        # This combination gives 500W of power
      - below: !lambda "return id(set_temp).state - 0.5;"
        then:
          - switch.turn_off: relay_1
          - switch.turn_on: relay_2
          - switch.turn_on: relay_3

        # This combination gives 1000W of power
      - below: !lambda "return id(set_temp).state - 1.5;"
        then:
          - switch.turn_on: relay_2
          - switch.turn_on: relay_2
          - switch.turn_on: relay_3
          
        # This combination gives 2000W of power
      - below:  !lambda "return id(set_temp).state - 2.5;"
        then:
          - switch.turn_on: relay_1
          - switch.turn_off: relay_2
          - switch.turn_off: relay_3


binary_sensor:
    # increase temp 0,5
  - platform: gpio
    pin:
      number: 4
      inverted: false
      mode:
        input: true
        pullup: true
    name: "increase temperature"
    id: in1
    on_press:
      then:
       - number.operation:
          id: set_temp
          operation: !lambda "return NUMBER_OP_INCREMENT;"
          cycle: !lambda "return true;"

    # Decrease temp 0,5
  - platform: gpio
    pin:
      number: 17
      inverted: false
      mode:
        input: true
        pullup: true
    name: "reduce temperature"
    id: in2
    on_press:
      then:
       - number.operation:
          id: set_temp
          operation: !lambda "return NUMBER_OP_DECREMENT;"
          cycle: !lambda "return true;"

    # Ok to start relays for 1000W
  - platform: gpio
    pin:
      number: 16
      inverted: false
      mode:
        input: true
        pullup: true
    name: "Activate 1Kw"
    id: activate1kw

    # Ok to start relays for 2000W
  - platform: gpio
    pin:
      number: 23
      inverted: false
      mode:
        input: true
        pullup: true
    name: "Activate 2Kw"
    id: activate2kw


    # Turn relay 1-3 off and keep them off
  - platform: gpio
    pin:
      number: 25
      inverted: false
      mode:
        input: true
        pullup: true
    name: "turnoff"
    id: turnoff

switch:
  
  - platform: gpio
    pin:
      number: 18
      mode:
        output: true
    name: "Relay 1"
    device_class: Switch
    id: relay_1
#    restore_mode: restore_default_off

  - platform: gpio
    pin:
      number: 19
      mode:
        output: true
    name: "Relay 2"
    device_class: Switch
    id: relay_2
#    restore_mode: restore_default_off

  - platform: gpio
    pin:
      number: 20
      mode:
        output: true
    name: "Relay 3"
    device_class: Switch
    id: relay_3
#    restore_mode: restore_default_off


number:
  - platform: template
    name: "Vald temperatur"
    device_class: temperature
    optimistic: true
    restore_value: true
    min_value: 0
    max_value: 100
    step: 0.5
    initial_value: 21.0
    id: set_temp


i2c:
  sda: 21
  scl: 22
  scan: True
  frequency: 400kHz

font:
  - file: 'slkscr.ttf'
    id: font1
    size: 8

  - file: 'bebas-neue-regular.ttf'
    id: font2
    size: 48

  - file: 'arial.ttf'
    id: font3
    size: 14

  - file: 'bebas-neue-regular.ttf'
    id: font4
    size: 32



display:
  - platform: ssd1306_i2c
    model: "SH1106 128x64"
    id: "my_display"
    reset_pin: 0
    address: 0x3C
    #update_interval: 2s
    lambda: |-
      // Print "Truma Heat"
      it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Tolycke 6");

      // Temp:"
      it.printf(10, 23, id(font3), TextAlign::TOP_LEFT, "Temp:");

      // Print inside temperature (from homeassistant sensor)
      if (id(temp).has_state()) {
        it.printf(127, 23, id(font3), TextAlign::TOP_RIGHT , "%.1f°", id(temp).state);
      }


      // Temp Setp:"
      it.printf(10, 60, id(font3), TextAlign::BASELINE_LEFT, "Temp Setp:");


      // Print outside temperature (from homeassistant sensor)
      if (id(set_temp).has_state()) {
        it.printf(127, 60, id(font3), TextAlign::BASELINE_RIGHT , "%.1f°", id(set_temp).state);
      }