Calculating wind chill factor value inside a weather forecast value template?

Hi.

I have used an integration to get weather forecast data from Finnish Meteorology Institute (FMI). I have the following value template in my configuration.yaml, which combines data for four following forecasts into a text sensor, which is then read by ESPHome, split apart and presented on a ePaper display. It is working ok.


# FMI, forecast data
  - platform: template
    sensors:
      fmi_forecast:
        friendly_name: FMI forecast for four items
        # entity_id: sensor.fmi_forecast
        value_template: >-
          {%- for i in [ 0, 1, 2, 3] -%}
            {{- state_attr('weather.hakametsa', 'forecast')[i].datetime.hour -}};
            {{- state_attr('weather.hakametsa', 'forecast')[i].temperature -}};
            {{- state_attr('weather.hakametsa', 'forecast')[i].condition -}};
            {{- state_attr('weather.hakametsa', 'forecast')[i].precipitation -}};
          {%- endfor %}

But, FMI weather data does not contain wind chill factor values, which would be a very nice plus.

I’ve found a thread, where a formula for calculating wind chill factor is presented, but don’t understand how to include it to value template I have.


windchill:
        value_template: >
          {% if states('sensor.out_temp') | float < 10 and states('sensor.yr_wind_speed') | float > 1.34 %}
            {{(13.12 + (0.6215 * (states('sensor.out_temp') | float)) - (11.37 * (states('sensor.yr_wind_speed') | float * 3.6)**0.16)
            + (0.3965 * (states('sensor.out_temp') | float) * (states('sensor.yr_wind_speed') | float *3.6)**0.16)) | round(1) }}
          {% else %}
            N/A
          {% endif %}
        unit_of_measurement: '°C'
        friendly_name: Wind chill

Anyone willing to help on this?

What I seem to read is that you look are 4 values (3 ahead), not sure if date or hour but that should not matter. So for each you need the windchil as well and thus for each i you need to use the hakametsa values into the windchill calc.
Something like

 ...
   {{- state_attr('weather.hakametsa', 'forecast')[i].precipitation -}}; 
   {% if state_attr('weather.hakametsa', 'forecast')[i].temperature | float < 10 and {{- 
    state_attr('weather.hakametsa', 'forecast')[i].wind -}}; | float > 1.34 %}
  {{(13.12 .......
   ...
  {% endif %}

As your current template does not show the wind, I guessed it is there as a attrib…as suggested above
Tip (if not already known), test it out in Developer>Templates

1 Like

Thank you very mucu for your hint & tip, @vingerha!

It seems to work now - after couple of iterations :slight_smile:

  # FMI, neljä seuraavaa forecastia, w/ wind_speed and wind chill
  - platform: template
    sensors:
      fmi_forecast_new:
        friendly_name: FMI forecast for four items, w/ wind speed and wind chill
        # entity_id: sensor.fmi_forecast_new
        value_template: >-
          {%- for i in [ 0, 1, 2, 3 ] -%}
            {{- state_attr('weather.hakametsa', 'forecast')[i].datetime.hour -}};
            {{- state_attr('weather.hakametsa', 'forecast')[i].temperature -}} ;
            {{- state_attr('weather.hakametsa', 'forecast')[i].condition -}};
            {{- state_attr('weather.hakametsa', 'forecast')[i].precipitation -}};
            {{- state_attr('weather.hakametsa', 'forecast')[i].wind_speed -}};
            {%- if state_attr('weather.hakametsa', 'forecast')[i].temperature | float < 10 and state_attr('weather.hakametsa', 'forecast')[i].wind_speed | float > 1.34 -%}
              {{ (13.12 + (0.6215 * (state_attr('weather.hakametsa', 'forecast')[i].temperature | float)) - (11.37 * (state_attr('weather.hakametsa', 'forecast')[i].wind_speed | float * 3.6)**0.16) + (0.3965 * (state_attr('weather.hakametsa', 'forecast')[i].temperature | float) * (state_attr('weather.hakametsa', 'forecast')[i].wind_speed | float * 3.6)**0.16)) | round(1) }};
            {%- else -%}
              N/A
            {%- endif %}
          {%- endfor %}