Templates to convert pressure

I am getting the differential drop across my air handler filter with some new hardware I built. The sensor returns the value in Pascals.

My ultimate goal is to have the pressure drop, in inches of water, with a rolling 5 minutes average on a dashboard. I’ve been failing to make any progress using statistics or filter.

This is the sensor that esphome is exposing:

image

This has been working

- sensor:
  - name: "Pressure Differential in Inches of Water"
    unique_id: pressure_differential_inches_of_water
    unit_of_measurement: 'inH2O'
    state: "{{ (states('sensor.press_diff_pressure') | float / 248.84) | round(2) }}" # Conversion factor from pascals to inches of water

Neither of these seem to work:

  - platform: statistics
    name: "Pressure Differential 5-Min Avg inH2O"
    entity_id: sensor.pressure_differential_inches_of_water
    max_age:
      minutes: 5
  - platform: filter
    name: "Pressure Differential 5-Min Avg inH2O"
    entity_id: sensor.pressure_differential_inches_of_water
    filters:
      - filter: time_simple_moving_average
        window_size: 2
        precision: 2

For statistics filter you forgot to specify what type of statistics you wanted. For the filter sensor, the docs state that time_simple_moving_average requires a time window.

- platform: statistics
    name: "Pressure Differential 5-Min Avg inH2O"
    entity_id: sensor.pressure_differential_inches_of_water
    state_characteristic: mean
    max_age:
      minutes: 5
  - platform: filter
    name: "Pressure Differential 5-Min Avg inH2O"
    entity_id: sensor.pressure_differential_inches_of_water
    filters:
      - filter: time_simple_moving_average
        window_size: "05:00"
        precision: 2

Thanks for the help! I’ve updated it, but I don’t think it’s changed much

image

I’m not sure which sensor isn’t working now. You should also add a unique_id to both of your sensors (and also make them differently). Without the unique_id every time you reload the yaml config HA will create a new sensor instead of modifying the existing one. So you might be looking at the wrong sensor.

The problem is your template sensor. Your template sensor has an inline comment which means your state is a string.

Do this instead.

- sensor:
  - name: "Pressure Differential in Inches of Water"
    unique_id: pressure_differential_inches_of_water
    unit_of_measurement: 'inH2O'
    # Conversion factor from pascals to inches of water
    state: "{{ (states('sensor.press_diff_pressure') | float / 248.84) | round(2) }}" 

Also, that unit of measurement is just… not correct. It should be some unit of measurement that represents a volume. But this isn’t causing your problem, the inline comment is.

FYI here’s a valid list of volumes that HA understands
image

Your other 2 sensors that feed off your template are correct, they are not the problem.

Thanks for the help, I definitely would not have figured out the comment issue. Here is what I have now

template:
- sensor:
  - name: "Pressure Differential in Inches of Water"
    unique_id: pressure_differential_inw
    #unit_of_measurement: 'inH2O'
     # Conversion factor from pascals to inches of water
    state: "{{ (states('sensor.press_diff_pressure') | float / 248.84) | round(2) }}"

sensor:
  - platform: filter
    name: "Pressure Differential Avg"
    unique_id: pressure_differential_avg
    entity_id: sensor.pressure_differential_inw
    filters:
      - filter: time_simple_moving_average
        window_size: "01:00"
        precision: 2

However, the value is still Unknown

image