Change yr weather units of measure

I am just getting started with HA. I have units of measure set to Imperial in configuration.yaml and the Yr temperature is showing as degrees F which is good.

However, wind speed, barometric pressure, and precipitation show in metric units.

I see that there are options in Configuration|Customization for unit_of_measurement, but I can’t figure out what the allowable values are.

For instance, if I change unit_of_measurement for Weather Pressure (sensor) to inHg, and restart HA, the label on the home page changes to InHg, but the value displayed is still hPa. Likewise if I change wind speed to mph, the label changes to mph but the value displayed is still m/s.

My customize.yml is being updated.

sensor.weather_wind_speed:
unit_of_measurement: mph
sensor.weather_pressure:
unit_of_measurement: inHg

I have looked at the source code at …/homeassistant/components/sensor/yr.py, but saw nothing there that helped. I have Googled and have not found an answer.

How can I fix this?

Thanks!

The customization will only change the label displayed, but will NOT convert the value. To change the value you can use a template sensor to convert.

But perhaps changing the unit_system will do.

I already have

unit_system: imperial

set in configuration.yaml, so that is not sufficient.

I’ll look into Template Sensor, thanks…

The darksky sensor supports different metrical systems, perhaps it’s more convenient to switch?

This looks good, I’ll give it a try. Thanks for the tip!

If you want to stick with YR, you could do something like this:

# Weather convert wind speed
  - platform: template
    sensors:
      wind_speed_mph:
        unit_of_measurement: "mph"
        value_template: "{{states('sensor.pws_wind_kph')|float|round / 1.609 }}"

Change sensor.pws_wind_kph to the one YR uses.

1 Like

Here is the code from my configuration.yaml. I have tried quite a few variations but I can’t figure out the syntax of the value_template. Can you please explain? The only thing that displays is wind_speed_mph with a dash in the icon. All the other values are not displayed. The default unit of measurement is meters/sec, I want to convert to mph and display it.

Weather prediction

sensor:

  • platform: yr
    name: Weather
    forecast: 24
    monitored_conditions:
    • temperature
    • symbol
    • precipitation
    • windSpeed
    • pressure
    • windDirection
    • humidity

sensor:

  • platform: template
    sensors:
    wind_speed_mph:
    unit_of_measurement: “mph”
    value_template: “{{states(sensor.yr_windSpeed_ms)|float|round * 2.23694 }}”

Thanks!

Have you tried the template value in the template editor?

You can trial and error there. Start with part of your value and expand from there.

{{ states(sensor.yr_windSpeed_ms) }}
{{ states(sensor.yr_windSpeed_ms) | float }}

Etc.

To start with I think the sensor name needs to be quoted.

{{ states('sensor.yr_windSpeed_ms') }}

Well, I finally got it working. The tip about the template editor was a good one.

This code is working:

Weather prediction

sensor:

  • platform: yr
    name: Weather
    forecast: 24
    monitored_conditions:

    • temperature
    • symbol
    • precipitation
    • windSpeed
    • pressure
    • windDirection
    • humidity
  • platform: template
    sensors:
    weather_wind_speed_mph:
    friendly_name: “Weather Wind Speed”
    unit_of_measurement: “mph”
    value_template: “{{states(‘sensor.weather_wind_speed’)|float * 2.23694 | round(0) }}”

It displays Weather Wind Speed in mph to one decimal point.

I have to say, to do what would appear to be a simple change of units was pretty painful.

There were several gotcha’s along the way. I found that the - platform template section had to be in the sensor section with yr. If it was in a separate sensor section, none of the yr sensors showed up. The wind speed in yr needed to be monitored, I needed to define a new sensor name wind_speed_mph, and finally hide the yr wind_speed. Finding the correct state name for the yr variable was not obvious.

Thanks to all of you who responded to my question; without your help it would have taken a lot longer to figure out. I have searched the HA docs and googled the problem for several hours. I could find nothing that helped.

If there is a cleaner way to accomplish this, please let me know!

Thanks again…

Try this:

# Weather convert wind speed
  - platform: template
    sensors:
      wind_speed_mph:
        unit_of_measurement: "mph"
        value_template: "{{(states('sensor.weather_wind_speed')| float * 2.23694) | round(1) }}"

You’ll still need to have windSpeed in your YR config. But you can hide it with the customizing function.

Yes, thanks for your reply! This is essentially what I got working above. Since then I have added conversions for pressure and precipitation. These are formatted as floats. I had to change the quotes around the format string to single quotes from an example I found on the net. With double quotes around the format string HA would not start at all. Also, I found that I had to invert the conversion factors for pressure and precipitation and divide rather than multiply by a small decimal number. When multiplying by a number less than one, the result was zero. I hope these clues will help others.

Here is just the template section:

  • platform: template
    sensors:
    weather_wind_speed_mph:
    friendly_name: “Weather Wind Speed”
    unit_of_measurement: “mph”
    value_template: “{{states(‘sensor.weather_wind_speed’)|float * 2.23694 | round(0) }}”
    weather_pressure_inhg:
    friendly_name: “Weather Pressure”
    unit_of_measurement: “inHg”
    value_template: “{{’{0:.2f}’.format(states(‘sensor.weather_pressure’)|float / 33.76895 )}}”
    weather_precipitation_in:
    friendly_name: “Weather Precipitation”
    unit_of_measurement: “in”
    value_template: “{{’{0:.1f}’.format(states(‘sensor.weather_precipitation’)|float / 25.4 )}}”

As you note, the YR sensors need to be hidden.

Thanks again…

1 Like

Ah sorry :slight_smile:

I didn’t read your last post completely.
Have to blame it on my headache :face_with_head_bandage:

I am also trying to change the YR wind speed units from m/s to km/h. The conversion factor is 3.6. I have searched in many threads to get this done with templates, however everything I have tried so far displays either a dash (-) in the new ‘bubble’ (in the frontend), or 0.0. I can’t get this to work. Can anybody help? Here’s my configuration.yaml code:

- platform: template
sensors:
  new_windspeed:
    friendly_name: 'Vent'
    value_template: "{{ states('sensor.yr_windspeed.state') | float * 3.6 | round (1) }}"
    unit_of_measurement: 'km/h'   

Capture

Sure helped me. Big thanks.