Sensor template help... please

I am recording barometric pressure here in inches of mercury. The conversion template was straight forward but I have an issue with it’s recording of zero upon restart of HA or sensor going offline.
Here’s the template:

- platform: template
  sensors:
    outdoor_barometer:
      friendly_name: Barometric Pressure
      unit_of_measurement: "inHg"
      value_template: "{{ (states('sensor.outdoor_multi_sensor_pressure')|float * 0.0295301)|round(2) }}"
      entity_id: sensor.outdoor_multi_sensor_pressure

Now how to I insure that when it wants to record a value of less than 26 inches, it records 26 inches. My charts get all worthless-y when a zero is stuck in it.

Please try this config

- platform: template
  sensors:
    outdoor_barometer:
      friendly_name: Barometric Pressure
      unit_of_measurement: "inHg"
      value_template: >
          {% if (states('sensor.outdoor_multi_sensor_pressure')|float * 0.0295301)|round(2) <= 26.0 %}
            26.0
          {% else %}
            {{ (states('sensor.outdoor_multi_sensor_pressure')|float * 0.0295301)|round(2) }}
          {% endif %}
2 Likes

Test if the value is below 26 and set to 26 else set current value
You may also need to check that the value is available
When I get to a workstation I’ll dig out some examples

1 Like

Yep. It was that simple. Thanks guys!!
Now I suppose I’ll have to put in the compensations for altitude and temperature. :slight_smile:

Just FYI there’s a simpler way to do this:

value_template: "{{ (states('sensor.outdoor_multi_sensor_pressure')|float(26) * 0.0295301)|round(2) }}"

This will substitute 26 for unavailable states.