Should bang bang component work offline?

I have an esp32 with a Dallas temperature probe and a relay for controlling an aquarium heater. I’ve setup the bang bang component to manage this like a thermostat. It works well when connected to home assistant but if the Wi-Fi drops out bang bang doesn’t seem to change the relay when the probe reaches the set temperature until it connects to Wi-Fi again. Should this work offline? I’m surprised it doesn’t given how simple it should be but I’m not sure if it’s something wrong with my configuration or my expectations.

I’ve set reboot_timeout: 0s to let it keep running when the Wi-Fi drops

Yes, being connected to home assistant 100% of the time would be lovely but I’d like this to be resilient to outages.

For anyone to figure out what is going on, they will need logs and the configuration that you are using.

If I was debugging this, I would set up local serial logging (probably verbose) to see what happens when Wi-Fi goes away. That would confirm (or deny) what you think is happening and also likely give you a clue as to why.

I typically use a laptop (see to never sleep with a power cord) with a terminal emulator (Terra term or putty are common choices) set to log to a file. I can then review the (timestamped) file at my leisure.

Is there a reason you are using bang-bang instead of the standard Thermostat? I don’t think that would change the results, but the definition of bang-bang seems a little weird. I chose thermostat for my heating only tasks and it has been working fine (but my Wi-Fi never goes out, at least before the power does completely).

But a thermostats binary output is “bang-bang” as I see it.
As opposed to a pwm that could modulate the heating.

Getting logs while it is disconnected from Wi-Fi is awkward so I haven’t done that yet. My first question was just should it work offline? I assumed it should but maybe someone can say that it wasn’t actually designed to do that.

In my experience, yes it does. The original gas-bulb thermostatic switch on my fridge died nearly 4 years ago and a replacement wasn’t available. So, I replaced it with a sonoff basic with a temp sensor using the bang-bang thermostat component.

I would also echo Neel’s comment that you may get a more helpful answer to your overall situation if you share your config. Unless it’s really bare-bones (like my fridge switch was) there may be some other component that will require a stable or continuous connection.

here’s my config:

esphome:
  name: elf

esp32:
  board: esp32dev
  framework:
    type: esp-idf
    advanced:
      minimum_chip_revision: "3.0"

logger:

api:
  reboot_timeout: 0s

ota:
 - platform: esphome
   password:

external_components:
  - source: github://myhomeiot/esphome-components

esp32_ble_tracker:
  scan_parameters:
    active: False

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.200
    gateway: 192.168.1.1
    subnet: 255.255.255.0
    dns1: 192.168.1.1

ble_gateway:
  devices:
    - mac_address: !secret some mac address here
  on_ble_advertise:
    then:
      homeassistant.service:
        service: ble_monitor.parse_data
        data:
          packet: !lambda return packet;
          gateway_id: elf
          
switch:
  - platform: template
    name: "Aquarium Light"
    id: aquarium_light_logic
    optimistic: true
    turn_on_action:
      - switch.turn_on: aquarium_light_relay
    turn_off_action:
      - switch.turn_off: aquarium_light_relay
  - platform: gpio
    id: aquarium_light_relay
    pin: 23
    inverted: true
    restore_mode: ALWAYS_OFF
  - platform: gpio
    name: "Aquarium heater"
    id: aquarium_heater
    inverted: True
    pin: 22
  - platform: gpio
    name: "Aquarium air"
    id: aquarium_air
    inverted: True
    pin: 19

time:
  - platform: sntp
    id: sntp_time
    servers:
      - 192.168.1.100
    on_time_sync:
      then:
        - script.execute: evaluate_light_schedule
    on_time:
      # 8:00am and 4:00pm every day
      - seconds: 0
        minutes: 0
        hours: 8,16
        then:
          - switch.turn_on: aquarium_light_relay
      # 12:00pm and 8:00pm every day
      - seconds: 0
        minutes: 00
        hours: 12,20
        then:
          - switch.turn_off: aquarium_light_relay

script:
  - id: evaluate_light_schedule
    then:
      - lambda: |-
          auto now = id(sntp_time).now();
          if (!now.is_valid()) return;

          int hour = now.hour;

          bool should_be_on =
            (hour >= 8 && hour < 12) ||
            (hour >= 16 && hour < 20);

          if (should_be_on) {
            id(aquarium_light_logic).turn_on();
          } else {
            id(aquarium_light_logic).turn_off();
          }

one_wire:
  - platform: gpio
    pin: 21

sensor:
  - platform: dallas_temp
    address: 0xe34641d4437d7a28
    name: "Aquarium Temperature"
    id: aquarium_thermometer
    update_interval: 30s

climate:
  - platform: bang_bang
    name: "Aquarium Thermostat"
    sensor: aquarium_thermometer
    default_target_temperature_low: 18
    default_target_temperature_high: 19

    heat_action:
      - switch.turn_on: aquarium_heater
      - switch.turn_on: aquarium_air
    idle_action:
      - switch.turn_off: aquarium_heater
      - switch.turn_off: aquarium_air

You’ve done so for the API, but not the WiFi. Although this shouldn’t keep the thermostat from functioning, especially since bang-bang doesn’t seem to have minimum cycle times. But it still means the whole thing is rebooting every 15 minutes.

Your config is not a minimal configuration. You do have components that need connectivity. It is possible/likely that they are part of the problem you are seeing.

You can remove them and see if that solves your problem.

When I first read the bang-bang controller page it didn’t make much sense to me. It still doesn’t. It does have some warnings about using it both heating and cooling (which you aren’t). The regular thermostat says it is just two bang-bang controllers. But, I find it much easier to understand. I set the set point and I can set the upper and lower dead bands and/or set minimum run and/or idle times. All of those things make sense to me.

You get the same behavior in bang-bang (for heating) but you have to change both set points when you want to change the target. If you always want the same temperature it doesn’t matter. I change the set point based on activity and time so only having to change one thing is an advantage to me. This really isn’t the cause of the issue you are seeing.

If you don’t want to get logs, just remove everything else and see if the problem goes away. I find the time it takes to set up logging more than pays in the time it takes to solve problems once you have the logs.

Thanks for the help everyone. It seems like I misdiagnosed the issue and it wasn’t the Wi-Fi dropping, just the Dallas temperature sensor being flaky due to loose connections. Glad to hear esphome would be able to keep running offline as this gives me confidence to build more on it in the future.

Less they have connections, more reliable they are. I have esphome devices running mainly offline for years, reliably like “train toilet”.