Create JAG/TI WIndChill sensor

HI

Using the windspeed and temperature, im trying to create the WindChill formula in a template.

should be this:

Tgevoel(°C) = 13,12 + 0,6215Tlucht + 0.3965(Tlucht - 28,676)*S10m0,16

valid for:

Tlucht = -46 … +10 °C en S10m = 4,8 … 177 km/h (1.34 … 49 m/s)

with my given sensors this should be something like:

- platform: template
    sensors:
      wind_chill:
        friendly_name: "Wind Chill"
        unit_of_measurement: 'C'
        value_template: "{13.12 +{ 0.6215*{{states.sensor.br_temperature.state}}+ {0.3965*{{states.sensor.br_temperature.state}} - 28.676}*{{states.sensor.br_temperature.state}}*0.16}"

There’s plenty of issues here, but the documentation isnt helping me yet. Please have a look with me?

Thanks,
Marius

Use the “Templates” in the Developer tools to check if you have a syntax error in your template and if you are able to evaluate it.

yes i am:


no error, but no value either yet…
did a mistake, should have used windgust (maybe speed) but thats a detail:

{13.12 +{ 0.6215*{{states.sensor.br_temperature.state}}+ {0.3965*{{states.sensor.br_temperature.state}} - 28.676}*{{states.sensor.br_windgust.state}}*0.16}

Will not work inside a template. You are doing math.

Ok Thanks. But now what?
Python script for something this small?
Or ill have to look for assistance with @olskar who also wrote https://github.com/olskar/home-assistant/blob/2fc65ab1f7c476e9df4530b3bd83718f6710eaf4/homeassistant/components/sensor/mold_indicator.py
Was hoping for some simpler template option tbh.

Cheers,
Marius

Replace it with a ( and the closing one ()) inside the template.

im really sorry, but i don’t fully understand what you say i should change:

(13.12 + 0.6215*{{states.sensor.br_temperature.state}} + 
                   0.3965*({{states.sensor.br_temperature.state}}- 28.676)*{{states.sensor.br_wind_gust.state}}*0.16)

or

(13.12 + 0.6215*states.sensor.br_temperature.state + 
                  0.3965*(states.sensor.br_temperature.state-28.676)*states.sensor.br_wind_gust.state*0.16)

both wont work…
must be missing the crucial point here…

Marius

this should be the correct math, now how to get it calculated:

(13.12 +( 0.6215*{{states.sensor.br_temperature.state}}))+ (0.3965*({{states.sensor.br_temperature.state}} - 28.676))*({{states.sensor.br_temperature.state}}*0.16)

or even this:

13.12 +0.6215*{{states.sensor.br_temperature.state}}+ 0.3965*({{states.sensor.br_temperature.state}} - 28.676)*{{states.sensor.br_temperature.state}}*0.16

Seems to work for me

{% set temperature = 25 %}

The temperature is {{ temperature }}. 
The calculated value is {{ (13.12 + (0.6215 * temperature ) + 
(0.3965 * ( temperature - 28.676 )) * (temperature * 0.16)) | round(2) }}.
1 Like

yes, works here too.

but when i replace {{temperature}} with {{states.sensor.br_temperature.state}} this is displayed:

Error rendering template: TemplateSyntaxError: expected token ':', got '}'

{{ (13.12 + (0.6215 * {{states.sensor.br_temperature.state}} ) + 
(0.3965 * ({{states.sensor.br_temperature.state}} - 28.676 )) * ({{states.sensor.br_temperature.state}} * 0.16)) | round(2) }}

spot the error…

Remove the {{ }} around the variables.

i tried that:

{{ (13.12 + (0.6215 * states.sensor.br_temperature.state ) + 
(0.3965 * (states.sensor.br_temperature.state - 28.676 )) * (states.sensor.br_temperature.state * 0.16)) | round(2) }}

but then nothing at all is displayed in the result window.

If the state is missing (wrong name, not set, etc) then the variables are evaluates blank.

sure, but it is there:

strange, the state is correct, the math is correct (using your temperature statement ), and yet there’s no result combining the two.

I think that it’s not working because we were missing the conversion 13.12 + (0.6125 * float(states.sensor.br_temperature.state)..... Jinja could be more strict than expected.

BIngo!

Now thesis obviously incorrect (freezing 2 degrees celsius at the moment), but the math is passing, thanks you very very much!

while this has become a template sensor formatting thread, please let me ask you another boggling question:
why does:

- platform: rest
  resource: http://192.168.xxx.xxx/api/dmH4lHTTsBu1gzhEuVkbV52AwSQpojSYxaxM9pQq/sensors/2
  value_template: "{{ as_timestamp(value_json.state.lastupdated) | timestamp_custom ('%H:%M') }}"
  name: 'Update Dimmer switch'

show the time in the desired format: 19

and

    hue_dimmer_switch_1_updated:
      friendly_name: 'Dimmer switch1 update'
      value_template: "{{states.sensor.hue_dimmer_switch_1.attributes.last_updated | timestamp_custom ('%H:%M')}}"

show (no matter what i change in the timestamp formatting, or even delete it):

1022

the latter 2 are the same sensors with either states.sensor.hue_dimmer_switch_1.attributes.last_updated or states.sensor.hue_dimmer_switch_1.last_updated

the timestamp doesn’t work in these sensors?

btw this is better:

"{{ (13.12 + 0.6215*float(states.sensor.br_temperature.state) + 0.3965*float(states.sensor.br_temperature.state) - 28.676) * float(states.sensor.br_wind_gust.state)*0.16) | round(2) }}"

yields: 33

which feels more appropriate right now :wink:

Thanks again! Also learned that the starting and ending () are necessary for the | round(2) to work correctly. Magic.

Have a final solution worked out and also created another formula, the Steadman.

29

both sensors for you to use and adapt as you need to localize:

- platform: template
  sensors:
    jagti_windchill:
      value_template: "{{ (13.12 + 0.6215*float(states.sensor.br_temperature.state) + 
                        0.3965*(float(states.sensor.br_temperature.state) - 28.676) *
                  (float(states.sensor.br_wind_speed.state)*3.6)*0.16) | round(2) }}"
      unit_of_measurement: "°C"
      friendly_name: Jag/Ti WindChill

# Tchill(°C) = 13,12 + 0,6215*Tair + 0.3965*(Tair - 28,676)*S10m0,16
# S10m = windspeed (km/h) at anemometer_height = 10 m, Tair in °C

    steadman_windchill:
      value_template: "{{ (1.41 - 1.162*float(states.sensor.br_wind_speed.state) + 
                        0.98*float(states.sensor.br_temperature.state) + 
                        0.124*float(states.sensor.br_wind_speed.state)**2 +
                        0.0185*float(states.sensor.br_wind_speed.state)*
                        float(states.sensor.br_temperature.state)) | round(2) }}"
      unit_of_measurement: "°C"
      friendly_name: Steadman WindChill

# Tchill(°C) = 1.41 - 1.162*S + 0.98*Tair+0.0124*S2 + 0.0185*S*Tair
# Tair in °C en S= in m/s.
1 Like

I guess that we should add those sensors to the documentation.

For the JAG/TI sensor there is a small typo; iT should be **0.16 (double asterisk).
Anyway thanks for this, very helpfull.