Beaufort Wind Scale

Hi, can someone please advise me how I can create a card that takes the reading from my garden weather station and converts the wind speed in mph to the corresponding number on the beaufort wind scale.

I imagine it must be some sort of code, but i am a green novice and bit lost.
I have searched HACS and the various forums but cannot find a solution.

Any advice would be very gratefully received.

1 Like

see this post DIY Zigbee weather station - Share your Projects! - Home Assistant Community (home-assistant.io)
The windforce is indicated in Dutch but I guess you can translate that yourselves

sensors:
      windforce:
        friendly_name: Wind force
        icon_template: " mdi:weather-windy"
        value_template: "{% set wind = states('sensor.windspeed')|float %}
        {% set wind_round = wind|round(1) %}
        {% if wind <= 1 %}Bft: 0, Wind stil, {{wind_round}} m/s
        {% elif wind <= 5 %}Bft: 1
        , Zwak: flauwe wind, {{wind_round}} m/s
        {% elif wind <= 11 %}Bft: 2, Zwak, {{wind_round}} m/s
        {% elif wind <= 20 %}Bft: 3, Matig: lichte bries, {{wind_round}} m/s
        {% elif wind <= 28 %}Bft: 4, Matig: flauwe bries, {{wind_round}} m/s
        {% elif wind <= 39 %}Bft: 5, Vrij krachtig, {{wind_round}} m/s
        {% elif wind <= 50 %}Bft: 6, Krachtig, {{wind_round}} m/s
        {% elif wind <= 62 %}Bft: 7, Hard, {{wind_round}} m/s
        {% elif wind <= 75 %}Bft: 8, Stormachting, {{wind_round}} m/s
        {% elif wind <= 89 %}Bft: 9, Storm, {{wind_round}} m/s
        {% elif wind <= 103 %}Bft: 10, Zware storm, {{wind_round}} m/s
        {% elif wind <= 117 %}Bft: 11, Zeer zware storm, {{wind_round}} m/s
        {% else %} > 117 %}Bft: 12, Orkaan, {{wind_round}} m/s
        {%- endif %}"

The code above assumes the wind speed sensor is in m/s. The OPs is in mph, so the sensor value will need to be multiplied by a correction factor before being usable (0.44704 to be precise).

Thanks for this, but what am i looking at? where would I apply this code? perhaps a card? or template?
Thanks

So you add this as a sensor of-your-own, either directly in configuration.yaml or (what I prefer) in a separate sensor.yaml being ‘included’ from the configuration.yaml.
Config example:

sensor:
   - platform: template
     sensors:
         windforce: (copy rest from above)

Toptip; Before having a cycle of adding/restarting/fixing/restart/etc…make sure the whole thing works via Developer > Templates

Since you know Dutch it would have been easier for you to translate for this English language forum. :wink:

I just copy/pasted it from the link … am rather lazy then tired :slight_smile:
But added it now to my own setup as well…so…the english version …still based on m/s

windforce:
        friendly_name: Wind force
        icon_template: " mdi:weather-windy"
        value_template: "{% set wind = state_attr('weather.home', 'wind_speed')|float %}
        {% set wind_round = wind|round(1) %}
        {% if wind <= 1 %}Bft: 0, Calm, {{wind_round}} m/s
        {% elif wind <= 5 %}Bft: 1, Light air, {{wind_round}} m/s
        {% elif wind <= 11 %}Bft: 2, Light breeze, {{wind_round}} m/s
        {% elif wind <= 20 %}Bft: 3, Gentle breeze, {{wind_round}} m/s
        {% elif wind <= 28 %}Bft: 4, Moderate breeze, {{wind_round}} m/s
        {% elif wind <= 39 %}Bft: 5, Fresh breeze, {{wind_round}} m/s
        {% elif wind <= 50 %}Bft: 6, Strong breeze, {{wind_round}} m/s
        {% elif wind <= 62 %}Bft: 7, Near gale, {{wind_round}} m/s
        {% elif wind <= 75 %}Bft: 8, Gale, {{wind_round}} m/s
        {% elif wind <= 89 %}Bft: 9, Severe gale, {{wind_round}} m/s
        {% elif wind <= 103 %}Bft: 10, Storm, {{wind_round}} m/s
        {% elif wind <= 117 %}Bft: 11, Violent storm, {{wind_round}} m/s
        {% else %} > 117 %}Bft: 12, Hurricane, {{wind_round}} m/s
        {%- endif %}"
3 Likes

Thanks all, I tried the following based on your advice but clearly missing something.

I really am a novice, I understand integrations, cards and lovelace but this is more complicated.

I am trying to pull a Beaufort number from my garden Weather station that returns wind speed in MPH.

I created a sensors.yaml in the config folder and pasted the below into it

sensor:
   - platform: template
     sensors:
        windforce:
        friendly_name: Wind force
        icon_template: " mdi:weather-windy"
        value_template: "{% set wind = state_attr('sensor.wind_speed', 'wind_speed')|float %}
        {% set wind_round = wind|round(1) %}
        {% if wind <= 1 %}Bft: 0, Calm, {{wind_round}} m/s
        {% elif wind <= 5 %}Bft: 1, Light air, {{wind_round}} m/s
        {% elif wind <= 11 %}Bft: 2, Light breeze, {{wind_round}} m/s
        {% elif wind <= 20 %}Bft: 3, Gentle breeze, {{wind_round}} m/s
        {% elif wind <= 28 %}Bft: 4, Moderate breeze, {{wind_round}} m/s
        {% elif wind <= 39 %}Bft: 5, Fresh breeze, {{wind_round}} m/s
        {% elif wind <= 50 %}Bft: 6, Strong breeze, {{wind_round}} m/s
        {% elif wind <= 62 %}Bft: 7, Near gale, {{wind_round}} m/s
        {% elif wind <= 75 %}Bft: 8, Gale, {{wind_round}} m/s
        {% elif wind <= 89 %}Bft: 9, Severe gale, {{wind_round}} m/s
        {% elif wind <= 103 %}Bft: 10, Storm, {{wind_round}} m/s
        {% elif wind <= 117 %}Bft: 11, Violent storm, {{wind_round}} m/s
        {% else %} > 117 %}Bft: 12, Hurricane, {{wind_round}} m/s
        {%- endif %}"

I called the sensors.yaml file from the configuration.yaml using

sensor: !include sensors.yaml

When i verify or try and restart HA i get the following error.

Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 11).

If i paste try the code in the template editor it seems to work, although it is not very windy today so hard to tell.

My configuration.yaml looks like this.

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
1 Like

The sensors.yaml should not (!) have “sensor:” as header
image
And for the template, pls check what you have as unit in your wind sensor…you may need to correct it then as per earlier mentioned comment above

I have removed the sensor: as header.
If I include the - Platform like your example, it reads:

end of the stream or a document separator is expected at line 2, column 1:
sensors:

If i remove the ‘-’ it will save but then returns this message when i try and restart.

Failed to call service homeassistant/restart. argument of type ‘NoneType’ is not iterable

Rather lost…

Please look at my screen-shot
Start with - platform , incl. the hyphen, you may have other sensors later on based on another platform
indent the line next, etc.

  - platform: template
       sensors:
           [name of sensor 1] 
              ......
              .......
           [name of sensor 2]

And something else I just noticed, is your sensor called wind_speed? then it may not have an attribute wind speed but it would be the state tiself…pls send screenshot of your entity if unsure (using menu-Developer Tools > tab-States )
And with a bit more info…
I use the ‘weather’ sensor to get to the data and not sure where you get yours from. Usually one setsup an integration with a weather platform, e.g. openweathermap, accuweather, etc. (see integrations). That integration should then kick back attributes of which one would be ‘wind_speed’ (or so).
Then you can use the state_attr to extract the value of that attribute

Hi Vingerha,

I copied your YAML, double checking the indentations and it was accepted - thank you!

I have included my windspeed entity, it seems it should be simple enough to use the MPH to set a corresponding Beaufort scale, but it’s beyond me.

You have chosen a nice ‘easy’ challenge to start off your HA experience … as ‘templates’ are not easy at all and I am learning since a long time.
Since the value is not in the attribute (as I have, using state_attr) … but in the state of the sensor, change the line to show below, with correction to mph:

{% set wind = states('sensor.wind_speed') | float * 0.44704 %}

And again… I recommend to try out the whole value_template in Developer Tools > Templates…so that you can see if it kicks back the value expected

1 Like

And whenever you find more time…
Templating - Home Assistant (home-assistant.io)

Thank you so much for your patience and direction, that change

{% set wind = states(‘sensor.wind_speed’) | float * 0.44704 %}

worked immediately and I was able to finally complete my project and create this dial based off of live data fed in from my weather station in the garden.

Great…!!
HA has its pro’s and con’s …the (many) pro’s being that almost amything is possible without cost…the con’s …not always that easy :slight_smile:

And now it is my turn to ask … where you got your card…

I picked up the card from this Github page and the author GlennHA was helpful in enabling me to understand how to set it up.
https://github.com/GlennGoddard/CanvasGaugeBackgrounds

The work was inspired from this original post/project from Ali_Kiaie.
https://community.home-assistant.io/t/cool-uv-index-gauge-for-my-swimming-pool-area/116223

Thx…closing my activity to this topic…good luck :slight_smile:

I hope everyone realizes that the Beaufort values in this template are in km/h and the author is wrongly feeding m/sec as input.

Otherwise 117 m/sec (Hurricane) would be 421 km/h winds…

Reference:

2 Likes