WTH doesn't Home Assistant stop data glitches at startup or reboot

Every time I reboot Home Assistant or restart it all my sensors show glitches in the data either a very high or low value. If HA would stop all recording to the database until everything is running I think that would help. I could do a template for each sensor but it seems there should be a way to do this globally or just have it done automatically.

All entities are set to unknown on start up, then they are either restored or receive an update from their integration. If you have template sensors that use the int() or float() functions or filters and specify a default of 0 then this is what is causing your glitches when the sate is unknown. You can use the availability template option to avoid this issue. There is an example here.

Other types of sensors should not have this issue, mine certainly don’t. Do you have an example?

3 Likes

Thanks for the reply and info on the availability template. I use a helper to take the data from three template sensors shown below and use the minimum value to make a “humidity setpoint” sensor. This sets the humidity in the house depending on outdoor temperature so that condensation does not collect on the windows .

template:
  - sensor:
      - name: "Current Humidity Setpoint"
        unique_id: "sensor.current_humidity_setpoint"
        state: "{{ states('sensor.openweathermap_temperature') | int /2 +30 }}"
      - name: "Forcast Humidity Setpoint"
        unique_id: "sensor.forcast_humidity_setpoint"
        state: "{{ states('sensor.home_realfeel_temperature_min_day_1') | int /2 +30 }}"
      - name: "Maximum Allowed Humidity"
        unique_id: "sensor.maximum_allowed_humidity"
        state: "{{ 50.0 | float(1) }}"

I tried adding the availability template to the first two of these sensors and that did not take care of the problem with the humidity setpoint sensor glitches unless I applied the template incorrectly?
Here is my new code:

template:
  - sensor:
      - name: "Current Humidity Setpoint"
        unique_id: "sensor.current_humidity_setpoint"
        state: "{{ states('sensor.openweathermap_temperature') | int /2 +30 }}"
        availability: "{{ has_value('sensor.openweathermap_temperature') }}"
      - name: "Forcast Humidity Setpoint"
        unique_id: "sensor.forcast_humidity_setpoint"
        state: "{{ states('sensor.home_realfeel_temperature_min_day_1') | int /2 +30 }}"
        availability: "{{ has_value('sensor.home_realfeel_temperature_min_day_1') }}"
      - name: "Maximum Allowed Humidity"
        unique_id: "sensor.maximum_allowed_humidity"
        state: "{{ 50.0 | float(1) }}"

Here is a screen shot of a plot with that sensor showing the restart of HA
HumiditySetpoint

I also am seeing glitches in data from 6 VOC sensors that are averaged in a helper. These are setup in ESPhome YAML code. The sensors are an ens160 connected to an ESP 8266 board. These are setup in the ESPhome YAML code shown below.

i2c:
  scan: True

sensor:
  - platform: bme280_i2c
    temperature:
      name: "Familyroom temperature"
      id: frtemp
    pressure:
      name: "Familyroom Pressure"
    humidity:
      name: "Familyroom humidity"
      id: frhumi
    address: 0x77
    update_interval: 60s
  - platform: bh1750
    name: "Familyroom Illuminance"
    address: 0x23
    update_interval: 60s
  - platform: ens160_i2c
    eco2:
      name: "Familyroom CO2"
    tvoc:
      name: "Familyroom VOC"
    aqi:
      name: :Familyroom AQI"
    address: 0x53
    update_interval: 60s
    compensation:
      temperature: frtemp
      humidity: frhumi

Here is a plot of one of the sensors and the helper average of all 6 sensors with the glitches where HA was restarted.
VOC

I don’t know how to stop these from reporting erroneous data after an HA reboot or ESP firmware update.

Where is the average VOC sensor configuration?

That is the one that needs the availability template.

It is in a helper. It uses 7 VOC sensor inputs and does an arithmetic mean.



The Humidity Setpoint is now fixed. I deleted the sensors I made in YAML and recreated them in the UI. Now they are working correctly.

You can see the Humidity setpoint just has a spot where the data is missing but the Average VOC still has a glitch when I restart HA.