Disable logging zero values

Hi All,

My Xiaomi climate sensor reports pressure values in hPa, while in my country atmospheric pressure is typically measured in mmHg. This is not a problem since these values can be linearly recalculated:

- platform: template
  sensors:
    pressure_mmhg:
      friendly_name: "Atmospheric pressure"
      entity_id: sensor.balcony_climate_sensor_pressure
      value_template: "{{ (states('sensor.balcony_climate_sensor_pressure') | float * 0.750062) | round(2) }}"
      unit_of_measurement: 'mmHg'

This approach has one drawback: when home assistant starts it logs a zero value, as result the graph gets totally unusable

Is there a way to disable logging zero values? Or set an undefined value (hope grafana will skip these values).

Alternatively, is there a way to make an InfluxDB query that would skip zero values, so that I can build the proper graph?

Nevermind, I found availability_template option

- platform: template
  sensors:
    pressure_mmhg:
      friendly_name: "Atmospheric pressure"
      entity_id: sensor.balcony_climate_sensor_pressure
      value_template: "{{ (states('sensor.balcony_climate_sensor_pressure') | float * 0.750062) | round(2) }}"
      availability_template: "{{ not is_state('sensor.balcony_climate_sensor_pressure', 'unknown') }}"
      unit_of_measurement: 'mmHg'
1 Like

Hmmm, I have to get back to this topic. Unfortunately the code above still generates zero values from time to time. I tried to suppress this with adding an additional rule in availability_template

      availability_template: "{{ not is_state('sensor.balcony_climate_sensor_pressure', 'unknown') and
                                     states('sensor.balcony_climate_sensor_pressure') | int != 0}}"
 

Unfortunately this filtered out all values, not just zero ones. I checked this expression in HA template debugger. It evaluates to true (as expected), but no value is stored.

Does someone has any ideas what is wrong?

Inconvenience - yes, cosmetically poor - perhaps, unclean - maybe, “totally unusable” - no.
I note you found the fix anyway,

Well, typical values of the atmospheric pressure are 730-750 mmHg. Grafana automatically adjusts bounds so that graph takes full vertical scale, and I find this suitable and handy
image

When zero values get added to the list, the bounds are adjusted to 0-750, and the graph becomes almost a straight line at the top with spikes to zero. Pressure changes get no longer noticeable. That is what I mean totally unusable (sorry, I do not have a picture right now, as I went to influxdb and manually deleted all zeros).

Well, I can definitely go to grafana settings and explicitely set graph bounds to 730-750, so zero values will just go outside the graph. But I would prefer to fix the source of the problem, rather than mask it.