New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add template support for remaining attributes of weather entity #47736
Add template support for remaining attributes of weather entity #47736
Conversation
Hi @csoltenborn, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
Documentation for this [PR](home-assistant/core#47736)
Thanks for the fast review! Now that I have your attention, two questions which came into my mind:
|
|
I was talking about Shall I than expose that attribute, too?
Not to nitpick, but the documentation you referred to suggests different kinds of units (e.g. The current air pressure in hPa or inHg). I'm not even sure how HA handles this - how does it know whether the number is in hPa or inHg? And if it doesn't know, but relies on fixed units in this context, than these units should probably be documented... |
|
Sorry that I'm not getting it - I'm rather new to the HA world...
What do you mean with "extract the unit"? From
I didn't want to change anything - it's just that when I implemented a weather template, I had to figure out myself what the parameters' units are because the docs don't say so. In particular, my sensor would provide wind speed in m/s, and I only noticed on the GUI that I have to compute km/h in |
I was thinking that if you have the temperature entity (from the template) you could check it's attributes to know the unit. But I came to realise this might not be available in all cases. So lets go with
OK, that can be updated in documentation repository through a new PR |
My bad - I'm facing issues adding the |
I believe all sensors with a unit of measurement set to a valid temperature unit will be automatically converted to core/homeassistant/helpers/entity.py Lines 399 to 409 in 1fc8e32
This is also true for weather entitie's temperature attribute. In my understanding, the only case that can fail is a sensor that does not have a unit of measurement. But this can be fixed by providing a unit of measurement for the sensor in question, or by making a template sensor with a unit of measurement, or by making the conversion in the template for temperature itself. There is also the complexity that I believe that the I would vote to keep it simple by not including the template for the temperature unit. |
Let me start by saying that I agree with the current PR as is (no need to add anymore features) I also agree with @MatthewFlamm, but that is only true if the template has an entity. But you can write in any number in the template... |
Good point @dgomes. I forgot about that possibility. In this case, the user should also be able to write in the number in the correct units. This is probably better in the documentation (in a different PR, which I also agree). |
Thanks - I've learned something here. However, there seems to be a problem with some of the other properties. For instance, I have a sensor as follows: - platform: command_line
command: python3 -c "import re; import requests; print(re.search(r'Wind speed:<br><b> .*<br> ([\d\.]*) km\/h', requests.get('http://foo/bar.html').text).group(1))"
name: Foo Weather Station - Wind speed
unit_of_measurement: 'km/h'
scan_interval: 900 I use that sensor in my weather template: weather:
- platform: template
name: Foo
wind_speed_template: "{{ (states('sensor.foo_weather_station_wind_speed') | float) | round(1) }}" The problem is that the weather's wind speed will always have unit km/h, but its value is displayed as mph in Imperial mode. However, there's no way I'm aware of (which doesn't mean much, though :-) ) to check within I would then propose the following changes (in a different PR):
This would be in the line of @property
def wind_speed(self):
"""Return the wind speed."""
return self.hass.config.units.length(self._wind_speed, LENGTH_KILOMETERS)
@property
def visibility(self):
"""Return the visibility."""
return self.hass.config.units.length(self._visibility, LENGTH_KILOMETERS) I think that this change will make it possible to write weather templates which work both in Metric and Imperial mode. Shall I open that PR? |
Ok, I will do so as soon as this PR has been merged! |
One final note: Let's try to get this and the upcoming PR into the next version! The reason is that the "fix units" change is a breaking one - it will break weather templates of people using Imperial mode (the weather templates of which would not work correctly in Metric mode). Since the weather template has only been released lately, the sooner that fix is in, the less people will be affected, I guess... |
These new attributes are a great addition to this template. My weather station (WeatherRack2) also reports the following data, so I'd also like to suggest additional attributes for:
Thank you. |
I'm rather new to Home Assistant, but afaik, there is no HA support for these attributes yet, so even if there would be templates for them, there's nothing to map the computed values to... So my guess is that you should open a feature request against HA Core. |
Is this ready to be merged? |
Proposed change
The new weather template is great, but does not support all attributes of the weather entity. This PR adds support for these attributes.
Type of change
Example entry for
configuration.yaml
:Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: