Esp32 Hot tub controller

Hér er kóði fyrir esp32 og 4 channel realy til að stýra úti sturtu og heitum potti.


esphome:
  name: pottastyring
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: ""
  password: ""
  domain: .lan
  manual_ip:
    static_ip: 192.168.x.x
    gateway: 192.168.x.x
    subnet: 255.255.255.0
    dns1: 192.168.x.x

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "hottub"
    password: ""

captive_portal:

web_server:
  port: 80

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

time:
  - platform: sntp
    id: timer
    servers:
      - 0.pool.ntp.org
      - 1.pool.ntp.org
      - 2.pool.ntp.org

dallas:
  - pin: GPIO13


sensor:
  - platform: dallas
    address: 0x67011464EA7EFF28
    name: "Pottur hiti"
    id: pottur_hiti
    
  - platform: dallas
    address: 0x8B0314649975FF28
    name: "Vatn i pott"
    id: vatn_i_hiti
    
  - platform: dallas
    address: 0x110000045976f328
    name: "Hiti Skapur"
    id: Hiti_skapur

  - platform: dallas
    address: 0xe10314645814ff28
    name: "Hiti Uti"
    id: hiti_uti

    
binary_sensor:
  - platform: gpio
    filters:
      - delayed_on: 100ms
    id: fylla
    pin:
      number: GPIO17
      mode: INPUT_PULLUP
      inverted: True
    name: "Pottur fylla takki"
    on_press:
        if:
          condition:
            lambda: 'return id(pottur_hiti).state < 20;'
          then:
          - logger.log: "The sensor value is below 20!"
          - switch.turn_on: relay_1
          - delay: 1min
          - switch.turn_on: relay_4
          - delay: 30min
          - switch.turn_off: relay_1
          - delay: 3min
          - climate.control:
                id: pottur_climate
                mode: "HEAT"
          else:
          - logger.log: "The sensor value is above 20!"

  - platform: gpio
    filters:
      - delayed_on: 500ms
    id: sturta
    pin:
      number: GPIO21
      mode: INPUT_PULLUP
      inverted: True
    name: "Sturta takki"
    on_press:
        if:
          condition:
            lambda: 'return id(pottur_hiti).state > 38;'
          then:
          - logger.log: "The sensor value is above 38!"
          - climate.control:
                id: pottur_climate
                mode: "OFF"
          - delay: 10sec
          - switch.turn_on: relay_3
          - delay: 4min
          - switch.turn_off: relay_3
          else:
          - logger.log: "The sensor value is below 20!"  
          - switch.turn_on: relay_3
          - delay: 4min
          - switch.turn_off: relay_3
          
  - platform: gpio
    filters:
      - delayed_on: 500ms
    id: nidurfall
    pin:
      number: GPIO33
      mode: INPUT_PULLUP
      inverted: True
    name: "taema takki"
    on_press:
      then:
      - switch.turn_off: relay_4
      - climate.control:
            id: pottur_climate
            mode: "off"

switch:
  - platform: gpio
    restore_mode: ALWAYS_OFF
    name: "Pottur fylla relay"
    pin: GPIO25
    id: relay_1
    
  - platform: gpio
    restore_mode: ALWAYS_OFF
    name: "Pottur hita relay"
    pin: GPIO26
    id: relay_2
    
  - platform: gpio
    restore_mode: ALWAYS_OFF
    name: "Sturta relay"
    pin: GPIO27
    id: relay_3
    
  - platform: gpio
    restore_mode: ALWAYS_ON
    name: "Loka nidurfalli"
    pin: GPIO18
    id: relay_4
  
climate:
  - platform: bang_bang
    id: pottur_climate
    visual:
      min_temperature: 38
      max_temperature: 42
      temperature_step: 1.0
    name: "Pottur vatn"
    sensor: pottur_hiti
    default_target_temperature_low: 38 °C
    default_target_temperature_high: 40 °C
 
    heat_action:
      if:
          condition:
            lambda: 'return id(pottur_hiti).state > 32;'
          then:
          - logger.log: "The sensor is above 32! then full"
          - switch.turn_on: relay_1
          - switch.turn_on: relay_2
          else:
          - logger.log: "The sensor value is below 32!"
          - switch.turn_on: relay_1
          - delay: 1min
          - switch.turn_on: relay_4
          - delay: 30min
          - switch.turn_on: relay_2
          
    idle_action:
      - switch.turn_off: relay_2
      - switch.turn_off: relay_1

mqtt:
  broker: 192.168.x.x
  username: xxx
  password: xxx