Temperature / Humidity Sensor change units

Bought this a while back: https://www.amazon.com/gp/product/B07D37FKGY/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

Is there any way to change the pressure from milibars into inHg? In the US we use 29.92 as the standard for atmospheric pressure…

You could use a template sensor to calculate pressure inHg from the supplied value.

sensors:
  - platform: template
    sensors:
      atmospheric_pressure_inhg:
        friendly_name: "Atmospheric Pressure inHg"
        unit_of_measurement: inHg
        value_template: "{{ states('sensor.weather_station_pressure')|float / 33.864  }}"
        icon_template: mdi:gauge

Or something similar. I haven’t tested this so I don’t know if it will work as stated, but read the link below and that should get you started.

I just jerked this out of my sensors.yaml file. It converts my local sensor to inHg. BTW, I use the same sensors you mentioned. Note; the if <= 25.8 line is there so when you have to reboot, the value will NOT report 0 which will really screw up the granularity of your chart and the +.34 is an altitude adjustor (I’m at 6oo’ above sea level):

- 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) <= 25.8 %}
            30.0
          {% else %}
            {{((states('sensor.outdoor_multi_sensor_pressure')|float * 0.0295301)+0.34)|round(2)}}
          {% endif %}

I’m pretty new to templates, can you walk me through what all this means?

Templates are simply expressions that result in a value, that may be used to create a new sensor (in this case) or be used as a comparison for a condition in an automation, among other things.

Templates are defined using Jinja - the link is below.

Basically what this:

{{((states('sensor.outdoor_multi_sensor_pressure')|float * 0.0295301)+0.34)|round(2)}}

does is as follows:

  • {{ starts a template that is going to return a value. There are other forms like {% which is a statement and {# for comments.
  • states('sensor.outdoor_multi_sensor_pressure') refers to the value of the sensor you want to calculate on - in this case pressure in hPa from your sensor. The name of that sensor may be different. You can find all your sensor names using developer tools (the small hammer icon)
  • | float converts the sensor value (which is typically a string) to a number.
  • * 0.0295301 multiplies that number by the factor to convert to inHg
  • + 0.34 then adds a fudge factor to the result to convert the pressure to Mean Sea Level (MSL). MSL pressures are what the weather man quotes and are the local air pressure compensated for your altitude, to a figure that represents that air pressure at sea level. As stated this is for 600 feet, you should also take the current temperature into account for an accurate value.
  • | round(2) takes the result of that calculation and rounds it to 2 decimal places
  • }} finishes the template.

The returned value will be the value of the sensor you are defining - friendly_name: Barometric Pressure

The rest of that code is simply some logical tests to prevent your template sensor returning a zero value. If you are not familiar with programming I suggest you do some reading of the examples in the links I have provided - you should be able to get the gist of it.

With templates - start simple like my example then work up to more complex code as you start to understand.

https://jinja.palletsprojects.com/en/latest/templates/

Thanks for the insight

Would this go in my template yaml, automations yaml or config yaml? I assume templates, but then I would somehow have to call that template into action?

Looks like the value is correct, now how would I go about adding that to my dashboard?

image

That one is in an included file in my configuration.yaml:

sensor: !include sensors.yaml

If you don’t have one, you can just put the code in your configuration.yaml like this:

sensor:
  - 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) <= 25.8 %}
              30.0
            {% else %}
              {{((states('sensor.outdoor_multi_sensor_pressure')|float * 0.0295301)+0.34)|round(2)}}
            {% endif %}

Notice the only difference is the template is embedded 2 spaces after the line sensor: in the configuration.yaml

Depending on the type of card you are using (entities, entity or a custom-card) arrange these items:

          - type: state-label
            title: Barometer
            prefix: 'Barometer: '
            entity: sensor.outdoor_barometer

Where does this part of it go? Configuration or somewhere else?

That would go in your ui-lovelace.yaml file if you are writing your own, which is quite an adventure but extremely customizable. I can’t help much on just a dashboard, I’m an old school coder and haven’t played with that one.

Sounds good, I’ll see if I can figure it out.

Did we end up making a sensor entity anywhere along the way?

The sensor entity we created with that template is:

sensor.outdoor_barometer

If you don’t like that name, you can change it in the template. (third line in the template)

I guess I’m tired this morning, but I don’t see where that is in the config yaml…

sensor:
  - platform: template
    sensors:
      temperature_pressure:
        friendly_name: Barometric Pressure
        unit_of_measurement: "inHg"
        value_template: >
            {% if (states('sensor.temperature_pressure')|float * 0.0295301)|round(2) <= 25.8 %}
              30.0
            {% else %}
              {{((states('sensor.temperature_pressure')|float * 0.0295301)+0.0)|round(2)}}
            {% endif %}

You already changed it. :slight_smile:

sensor.temperature_pressure

OK, but I’m not seeing that as an entitty, the sensor.temperature_pressure_hpa is the hpa setting, I was hoping to get the inHg

Had to reboot HA! Doh!

1 Like