How to replicate the functionality of an Inkbird

Preamble:
I have a keezer (kegerator freezer) for my homebrewing. Currently, I have an ESP8266 with a Dallas probe which reads the temp into my HA setup and also controls a circulation fan through Lovelace. Temperature control is via an Inkbird which is repeatedly going screwy and I want to replace it.

It seems that the obvious solution is to use the ESP8266 temp readings from the Dallas to operate a relay switch based on a high/low temp range which I’m happy to set in the code as it doesn’t change. I can get it to do that but I’m getting held by by the additional requirement to have a compressor delay to prevent burnout.

Problem:
I need to add code to the base that I have that will allow me to set a high/low range, lets say 0C/32F is low and 4C/39F high. When the keezer warms to 39F, it will kick in the compressor which will cool to 32F then turn off and STAY OFF for a set number of seconds, even if the keezer warms up beyond 39*F during that period.

Has anyone figured out that kind of solution? I did a search but didn’t turn up anything that made sense. My current code is below:

esphome:
  name: esp8266_bar_controller
  platform: ESP8266
  board: d1_mini

logger:

wifi:
  manual_ip:
    static_ip: 192.168.10.115
    gateway: 192.168.10.1
    subnet: 255.255.255.0
    dns1: 192.168.10.1
    dns2: 0.0.0.0
  ap:
    ssid: "Fallback_BarController"
    password: ""
    ap_timeout: 1min
  domain: .local
  reboot_timeout: 15min
  power_save_mode: NONE
  fast_connect: false
  output_power: 20.0
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
    priority: 0.0
  use_address: 192.168.10.115

captive_portal:

api:
  password: !secret api_password
  port: 6053
  reboot_timeout: 15min
ota:
  password: !secret ota_password
  safe_mode: true
  port: 8266

dallas:
  - pin: D2 #GPIO4

switch:
  - platform: restart
    name: Bar Controller Restart  

  - platform: gpio
    pin:
      number: D5
      inverted: yes
    restore_mode: Restore_Default_Off
    name: "Bar LED"
    id: bar_led
  - platform: gpio  
    pin:
      number: D6
      inverted: yes
    restore_mode: Restore_Default_On
    name: "Keezer Fan"
    id: keezer_fan

sensor:
  - platform: dallas
    address: 0x463C01B5561*****
    name: Keezer Temperature
    filters:
        - filter_out: nan
        - heartbeat: 15s
        - sliding_window_moving_average:
            window_size: 5
            send_every: 5
            send_first_at: 1
    unit_of_measurement: "°C"

  - platform: wifi_signal
    name: "Bar Controller Wifi Signal"
    id: barcontroller_wifi_signal
    update_interval: 15s
    force_update: false
    unit_of_measurement: dB
    icon: mdi:wifi
    accuracy_decimals: 0

binary_sensor:
  - platform: status
    name: "Bar Controller Status"

text_sensor:
  - platform: wifi_info
    mac_address:
      name: Bar Controller Mac Address

I think you want a climate component!

You should be able to use on_value_range to start run a script, wait_until the temp is cool enough and then have a wait for however long you want your debounce to be.

script:
    - id: cooldown
      mode: single
      then:
        - switch.turn_on: keezer_fan
        - wait_until:
                sensor.in_range:
                  id: keezer_temperature
                  below: 4
        - switch.turn_off: keezer_fan
        - wait: 60s

That looks like a simple solution but in my mind, here is how it runs:

** Compressor turns on (keezer_fan in the code example in your post) and starts cooling until the Dallas hits 32*F (you have 4 in your post)

** Compressor turns off and waits set time (60 secs in your code). After set time, the code runs again and if the temp is below the set value, it goes back into another set wait loop.

** Once the temp is above the set temperature, it turns the compressor back on and the whole thing repeats.

In this case, the compressor control (switch on/switch off) becomes time based rather than temperature based; the decision is binary as being either above or below the set temp and the set time controls how often that is checked. I played around with something similar with ‘above’ and ‘below’ temperatures which seemed to work but doesn’t build in the compressor delay. The beauty of your example could lie in the simple ‘wait’ element coupled with the ‘above’ and ‘below’ thresholds.

I’ll try to get time to work on it over the weekend and if I get it running, I may create a blueprint.

@nickrout - I’ll look into the climate component. I hadn’t considered that.

I’m sorry, I didn’t have a full example in here. The part you’re missing is the part that runs the script when it gets above the target temperature. (Also, I put 4 because your sensor is in C, not F so 32 would be way too warm in C)

script:
    - id: cooldown
      mode: single
      then:
        - switch.turn_on: keezer_fan
        - wait_until:
                sensor.in_range:
                  id: keezer_temperature
                  below: 0
        - switch.turn_off: keezer_fan
        - wait: 60s

sensor:
  - platform: dallas
    address: 0x463C01B5561*****
    name: Keezer Temperature
    filters:
        - filter_out: nan
        - heartbeat: 15s
        - sliding_window_moving_average:
            window_size: 5
            send_every: 5
            send_first_at: 1
    unit_of_measurement: "°C"
    on_value_range:
        above: 4
        then:
            - script.execute: cooldown

So in this if the value is above 4C then it’ll execute the script cooldown which will turn on the fan, run until the temp is below 0C, wait 60s and then exit. This will then be fired again if the dallas sensor gets above 4C.

I also corrected the temperature in the script to be your lowest target of 0C.

I got it uploaded. I’ll post back here with the results.

Sidebar question: Is there a way to monitor when the script is triggered? It doesn’t show up as an entity. I’d like to just record when it runs, when it stops etc for debug purposes.

Thanks for your help so far, it got me way further than I had managed alone. I haven’t used scripts in the YAML code before, I just but the automations in the HA automation section. Always love to learn new stuff.

Watch the logs.

It seems that @pcon was on point for simplicity and function. I didn’t try the climate controller function because this solution was simple and easy to implement and I can confirm that it is working as expected.

Many thanks Patrick and Nick for you assistance. I’ll post the working code here for anyone else that needs it. For reference, I’m running this on a Wemos D1 Mini with a 4-relay board connected to D5 (relay #1), D6 (relay #2), D7 (relay #3). The fourth relay will run my line cooler to the taps when I get around to it.

esphome:
  name: esp8266_bar_controller
  platform: ESP8266
  board: d1_mini

logger:

wifi:
  manual_ip:
    static_ip: 192.168.10.115
    gateway: 192.168.10.1
    subnet: 255.255.255.0
    dns1: 192.168.10.1
    dns2: 0.0.0.0
  ap:
    ssid: "Fallback_BarController"
    password: ""
    ap_timeout: 1min
  domain: .local
  reboot_timeout: 15min
  power_save_mode: NONE
  fast_connect: false
  output_power: 20.0
  networks:
  - ssid: !secret wifi_ssid
    password: !secret wifi_password
    priority: 0.0
  use_address: 192.168.10.115

captive_portal:

api:
  password: !secret api_password
  port: 6053
  reboot_timeout: 15min
ota:
  password: !secret ota_password
  safe_mode: true
  port: 8266

dallas:
  - pin: D2 #GPIO4

script:
    - id: keezer_cooldown
      mode: single
      then:
        - switch.turn_on: keezer_compressor
        - wait_until:
                sensor.in_range:
                  id: keezer_temperature
                  below: 1
        - switch.turn_off: keezer_compressor
        - delay: 600s

switch:
  - platform: restart
    name: Bar Controller Restart  

  - platform: gpio
    pin:
      number: D5
      inverted: yes
    restore_mode: Restore_Default_Off
    name: "Bar LED"
    id: bar_led
  - platform: gpio  
    pin:
      number: D6
      inverted: yes
    restore_mode: Restore_Default_On
    name: "Keezer Fan"
    id: keezer_fan
  - platform: gpio
    pin:
      number: D7
      inverted: yes
    restore_mode: Restore_Default_Off
    name: "Keezer Compressor"
    id: keezer_compressor

sensor:
  - platform: dallas
    address: 0x463C01B5561*****
    name: "Keezer Temperature"
    id: keezer_temperature
    filters:
        - filter_out: nan
        - heartbeat: 15s
        - sliding_window_moving_average:
            window_size: 5
            send_every: 5
            send_first_at: 1
    unit_of_measurement: "°C"
    on_value_range:
      above: 4
      then:
          - script.execute: keezer_cooldown
          - script.wait: keezer_cooldown

  - platform: wifi_signal
    name: "Bar Controller Wifi Signal"
    id: barcontroller_wifi_signal
    update_interval: 15s
    force_update: false
    unit_of_measurement: dB
    icon: mdi:wifi
    accuracy_decimals: 0

binary_sensor:
  - platform: status
    name: "Bar Controller Status"

text_sensor:
  - platform: wifi_info
    mac_address:
      name: Bar Controller Mac Address