Create "sensor" from two existing ones

Hi all

I’m new to this forum (and home assistant) so I hope I’m asking I’m using the yr.no set of sensors, and it works well, but I doesn’t show wind chill (which is a contributing factor in Norway at the moment, with temperatures dropping below -40 some places). As far as I can see, the yr data doesn’t include wind chill, but it’s detailed here http://om.yr.no/symbol/effektiv-temperatur/ (article in Norwegian) among other places. Pyrhon3 code for converting this matches the wind chill reported on yr.no.

Any idea how to do this most easily?

roy

#!/usr/bin/env python3

T=-11 # Celsius
V=4 # m/s
Vkmh = V*3.6 # in kmh, since the formula wants that

W = 13.12 + 0.6215T - 11.37Vkmh0.16 + 0.3965TVkmh0.16

print("At " + str(T) + "°C with " + str(V) + "m/s wind, effective temperature is " + str(round(W,1)) + “°C”)

You’re probably needing a

Take in the T and V / Vkmh values, and use them to create a sensor that gives you W.

I’m not clear on how that W equation works, is it like this?

W = (13.12 + 0.6215*T) - (11.37*Vkmh*0.16 + 0.3965*T*Vkmh*0.16)

W is the windchill, that is, what the temperature feels like.

  • platform: template
    sensors:
    windchill:
    unit_of_measurement: ‘°C’

W = 13.12 + 0.6215T - 11.37(V3.6)**0.16 + 0.3965T*(V*3.6)**0.16

   value_template: >-
     "{{ (13.12 + 0.6215*states('sensor.yr.temperature')) - (11.37*states('sensor.yr.windSpeed')*3.6)**0.16 + (0.3965*states('sensor.yr.temperature')**0.16)|float }}"

The formula should be right, but it’s probably something I’m doing wrong in the syntax, since it fails. Any ideas?

tail: /home/homeassistant/.homeassistant/home-assistant.log: file truncated
2018-02-28 19:44:58 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.windchill fails
Traceback (most recent call last):
File “/home/homeassistant/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 204, in async_update_ha_state
yield from self.async_device_update()
File “/home/homeassistant/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 325, in async_device_update
yield from self.async_update()
File “/usr/lib/python3.5/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/home/homeassistant/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/template.py”, line 162, in async_update
self._state = self._template.async_render()
File “/home/homeassistant/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/template.py”, line 131, in async_render
return self._compiled.render(kwargs).strip()
File “/home/homeassistant/homeassistant/lib/python3.5/site-packages/jinja2/environment.py”, line 1008, in render
return self.environment.handle_exception(exc_info, True)
File “/home/homeassistant/homeassistant/lib/python3.5/site-packages/jinja2/environment.py”, line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File “/home/homeassistant/homeassistant/lib/python3.5/site-packages/jinja2/_compat.py”, line 37, in reraise
raise value.with_traceback(tb)
File “”, line 1, in top-level template code
TypeError: can’t multiply sequence by non-int of type ‘float’

Yeah, the needed syntax is states.your_sensor.state - something like the following should work:

{{ (13.12 + (0.6215 * states.sensor.yr.temperature.state)) - (11.37 * (states.sensor.yr.windSpeed.state * 3.6) * 0.16 + (0.3965 * states.sensor.yr.temperature.state) * 0.16) | float }}

Though I would have expected the sensor naming convention to look more like this:

sensor.yr_temperature

sensor.yr_windSpeed

Are you sure those sensors are named that way?

I guess, perhaps

{{ (13.12 + (0.6215 * states.sensor.yr.temperature.state)) - (11.37 * (states.sensor.yr.windSpeed.state * 3.6) ** 0.16 + (0.3965 * states.sensor.yr.temperature.state) ** 0.16) | float }}

It’s not “times” 0.16, it’s “to the power of 0.16”

Now, boiled down to this, it still doesn’t want to play. Log just tells me

2018-02-28 20:21:51 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template windchill, the state is unknown.

See config below. Thanks for any help, btw.

  • platform: template
    sensors:
    windchill:
    value_template: >-
    “{{ (13.12 + (0.6215 * states.sensor.yr.temperature.state)) - (11.37 * (states.sensor.yr.windSpeed.state * 3.6) ** 0.16 + (0.3965 * states.sensor.yr.temperature.state) ** 0.16) | float }}”

Have you tried the value template in the template editor in the HA UI?

Not really - what difference does it make to editing the config file?

Perhaps someone can help me find out what’s wrong wit this? It seems states.sensor.yr.temperature.state is invalid, somehow.

Have you checked if the darksky component figures in windchill? It has a “feels like” temperature that figures in the humidity, very important when you live in the tropics. It might factor in windchill also for colder temps, wouldn’t know though as wind chill isn’t really something that happens here :wink:

I haven’t no, and I’d like to use the data from Yr, since they are really accurate here (in Norway/Sweden), and as far as I know, the calculations of windchill and heat differ largely in that at lower temperatures, the humidity can be take out of the equation, whereas in high tempertures, it plays an importat role (note: I’m no meteorologist, I’ve just read up a bit about things)

You do not need to restant HA for every try.

Did you solve this sensor and if so could you share the code?

I guess so and that’s why the hin using the template editor of HA UI is valid.I don’t use the yr component, but usually per entity there is (domain).(entity) and then either “state” or “attributes.(attribute name)”

Use the dev’s templates tool (http://hostname/dev-template) to check, what is working:

{{ states.sensor.yr.state }} 
{{ states.sensor.yr.attributes }} 
{{ states.sensor.yr.attributes.temperature }} 
{{ states.sensor.yr.attributes.temperature.state }}

I think it should be sensor.weather_temperature and sensor.weather_wind_speed

Oh yes, your are right, it’s the same with Wunderground. Go to the /dev-state path of your HA installation to identify the available sensors.

Im really curious if @rkarlsba made it work since i want the chill effect as well :slight_smile:
Now im using an sensor from Wunderground but it would be nice to avoid relying on other services when i hav my own sensors :slight_smile:

I must be doing something wrong…

{{ states.sensor.yr.precipitation.state }}

Error rendering template: UndefinedError: ‘None’ has no attribute ‘precipitation’

For loop example:
{% for state in states.sensor -%}
{%- if loop.first %}The {% elif loop.last %} and the {% else %}, the {% endif -%}
{{ state.name | lower }} is {{state.state_with_unit}}
{%- endfor %}.

For loop example:
The cpu temperature is 46.54 °C, the hygrometer på pi is 23.8 %, the termometer på pi is 29.4 °C, the windchill is unknown, the yr humidity is 80.0 %, the yr precipitation is 0.0 mm, the yr pressure is 1009.2 hPa, the yr symbol is 2, the yr temperature is -2.2 °C and the yr wind speed is 0.7 m/s.

Just like @m0wlheld mentioned, you should address an attribute. This should be

{{ states.sensor.yr.attributes.precipitation }}

if precipitation is an attribute to the yr sensor or

{{ states.sensor.yr_precipitation.state }}

if it is a sensor by itself

But I was wrong … the Wunderground weather hub (and yr probably too) create a series of sensors. You need to find them and get their state.