Turn off esp8266 heater if it losts connection

Hello Guys,

I have an esp8266 (d1 mini) which controls the gas heater with a relay works as a wifi termostat, it has an onboard temp sensor(ds18b20 connected to it), and also receives a temperature from another esp8266 via Home assistant.
Some times I lost connection with this device, it can be reached via Esphome, but unreachable via Homeassistant UI.

Could you suggest me a way to disable heating / or use onboard temp sensor(ds18b20 connected to it), if its lost connection to Homeassistant/ to the other esp8266 which serves as a temp sensor to it?

Currently I have a code which checks if the value from the other esp8266 is not null, but obviously its just using old data, so the heating remaining on…

Here is the current code of the device:

dallas:
  - pin: D3
    update_interval: 60s 

sensor:
  - platform: homeassistant
    entity_id: sensor.norbiek_temp
    id: room_temp
    
  - platform: dallas
    address: 0x0B0416540EE3FF28
    name: "Kazan homerseklet"  
    id: onboard_temp

  #This one used in heating logic
  - platform: template
    name: "Active Temp sensor"
    id: active_temp
    lambda: |-
      if (isnan(id(room_temp).state)){
        return id(onboard_temp).state;
      } else {
        return id(room_temp).state;
      }
    update_interval: 60s    

text_sensor:    
  #This one used to display in HA
  - platform: template
    id: active_temp_sensor
    name: "Active Temp Sensor"
    lambda: |-
      if (isnan(id(room_temp).state)){
        return {"Kazan homero"};
      } else {
        return {"Szoba homero"};
      }    

switch:
  - platform: gpio
    name: "Relay"
    pin: D5
    id: example_heater
    on_turn_on:
    - lambda: |-
        id(gas_thermostat).publish_state();
        
    on_turn_off:
    - lambda: |-    
        id(gas_thermostat).publish_state();    

binary_sensor:
  - platform: template
    id: heater_relay
    name: "Heater Relay"
    lambda: |-
      return id(example_heater).state;

    
# Example single-point configuration entry (for heating only)
climate:
  - platform: thermostat
    name: "Thermostat Climate Controller"
    sensor: active_temp
    id: gas_thermostat
    default_target_temperature_low: 20 °C
    min_heating_off_time: 30s
    min_heating_run_time: 30s
    min_idle_time: 3s
    heat_action:
      - switch.turn_on: example_heater
    idle_action:
      - switch.turn_off: example_heater

Thank you very much for your help in advance!

Have a look at


sensor:
  - platform: wifi_signal

It’ll tell you if it’s lost WiFi.

Thank you for your answer, didn’t know that, but it didn’t lose WiFi, so I can reach it in HomeAssistant under EspHome, but can’t reach it in the HomeAssistant UI. So HA doesn’t forward it the value from the other esp8266…thus it continue heating.

platform status

hmm that seems good, so I can check in my esp8266’s code that if its connected to HA via the API. Could you please provide a code sample for it? Do you know what are the possible return values of this sensor?

on_state:
  if:
    condition:
      # Same syntax for is_off
      binary_sensor.is_on: my_binary_sensor
   then:
      - switch.turn_off: your switch I'd

more precisely here You can view. and also read the operators if, or, and.