Local check for sensor failure

I’m building my own sauna controller and one of the safeties I want to add is to shut off the oven if my main temperature sensor fails. But how can I check if the sensor gave a recent reading? Can I check for unavailability? Can I check for last updated value?

When I google or search on this community I get a lot of stuff about unavailability of the device not a singel sensor, or i find solutions that involve home assistant, but for safety I need this to be fully local on the device.

The best thing I could think of till now is to have an on_value part in the dallas sensor that updates a global variable with a timestamp and then a time sensor that triggers every minute and me checking the global variable. But this seems ugly to me. Any elegant solutions you could steer me towards?

Thanks!

No reactions, too bad… For anyone ending up here. This is my resolution:

For the temperature sensor I did this:

globals:
  - id: global_main_temp_sensor_updated_min_ago
    type: int
    restore_value: no
    initial_value: '0'

sensor:
  - platform: dallas
    address: 0x5b00000f0f1eb328 # temp_sensor_6
    # address: 0x3600000f12ebcc28 # original
    name: "Onboard Temperature"
    id: onboard_temp
    on_value:
      then:
        - lambda: |-
            if (!isnan(id(onboard_temp).state))
            id(global_main_temp_sensor_updated_min_ago)=0;

and then I already had a logic that checked all kinds of stuff every minute so there I have:

time:
  - platform: homeassistant
    id: homeassistant_synced_time
    timezone: Europe/Amsterdam
    on_time:
      # Every minute
      - seconds: 0
        minutes: /1
        then:
          - lambda: |-
              if (id(climate_pid).mode==climate::CLIMATE_MODE_OFF) {
                // something not relevant for this post was here
              }else{
                id(global_main_temp_sensor_updated_min_ago)++;
                // If no temperature is read for 1 minutes then turn of heater
                if (id(global_main_temp_sensor_updated_min_ago)>=2){
                    auto call = id(climate_pid).make_call();
                    call.set_mode("OFF");
                    call.perform();
                    ESP_LOGE("temp_sensor_update_check", "Turning heater off, because temperature sensor had no new value for more than 1 minute.");
                  }
              }

Hope this helps someone some day!

2 Likes