How to create template sensor for forecasted precipitation (Openweathermap or Met.no)?
I’ve seen more than a couple of topics about it and all of them say to use attributes, what makes sense but I can’t find them in my integrations.
Met.no:
temperature: 10.8
dew_point: -1.2
temperature_unit: °C
humidity: 43
cloud_coverage: 19.1
uv_index: 2.2
pressure: 1022
pressure_unit: hPa
wind_bearing: 356.3
wind_gust_speed: 41.8
wind_speed: 19.4
wind_speed_unit: km/h
visibility_unit: km
precipitation_unit: mm
attribution: >-
Weather forecast from met.no, delivered by the Norwegian Meteorological
Institute.
friendly_name: met.no
supported_features: 3
and Openweathermap:
temperature: 8.5
apparent_temperature: 5.8
dew_point: 2.3
temperature_unit: °C
humidity: 65
cloud_coverage: 34
pressure: 1022
pressure_unit: hPa
wind_bearing: 16
wind_gust_speed: 18.54
wind_speed: 17.1
wind_speed_unit: km/h
visibility_unit: km
precipitation_unit: mm
attribution: Data provided by OpenWeatherMap
friendly_name: OpenWeatherMap
supported_features: 3
I would like to create sensor for forecasted daily precipitation and use it in my irrigation automation… How to do it?
To be clear, the only template in what you posted is:
and in that circumstance, hourly does not exist because actions did not execute.
The only way to test that template in the template editor would be to run the weather.get_forecasts in developer tools → actions tab. Then copy the response data and set it inside the template. e.g.
The code you posted above goes inside your configuration.yaml file.
Testing it in the template editor is possible but not straight forward because you need data from a service call. The template editor does not run service calls, which is why it doesn’t see the variable and why it’s producing an error.
Thanks, I’ve got better understanding now.
The only thing which is strange that’s I created template entity with its unique id, I removed it later (completely) and that id is still visible in the system. Even more strange is that afterwards I created new template id with slightly different id and its state is visible/assigned to that deleted id…
How to sort it out?
Like I said, yaml is removed and in ui, delete option is greyed out…
I changed in ui old id to new id but this action duplicated in ui sensor belonging this time to sensor integration.
So, now I have 2 sensors with the same id (supposed to be impossible?), old one belonging to template integration, new (duplicated) to sensor integration… and both have the same value/state and can’t be removed.
You have to wait for HA to realize the yaml is no longer present. It’s not a simple process because HA doesn’t know when yaml exists or not.
I have no idea if you’re referring to the entity_id or unique_id. It’s not possible to have 2 of either. The template entities under the hood append additional information to the unique_id, which means what you put in will not be what HA stores. So if you’re referring to unique_id, you will have 2 config entries at the end of the day. Unique_id’s are only unique within the integration. Separate integrations have separate information appended to each unique_id. This is done so things can remain unique in the system if the user accidentally uses the same unique_id inside 2 different integrations.
Entity_id’s will append _2 or 3 or 4 etc if the system detects the same entity_id being used.
Removed that yaml template and sensor with that id “A” remains in gui and can’t be deleted (even with recorder’s purge).
I created second template sensor with unique_id “B”. That id is not visible in gui; instead sensor “A” shows state of sensor with unique_id “B”.
That’s why I’m a bit lost…
The unique_id creates a unique config entry. Entity_id is what you as a user uses to target the entity in question.
If you create 2 config entries (which are generated from the unique_ids in yaml) that use the same entity_id, one will have the entity_id you want, the second will have the entity_id you want with an _2. This is what’s happening for you.
Go to developer tools → states page and you’ll see both entities or just one if the other doesn’t exist anymore.
EDIT: Your entity_id is derived from the name in your configuration. e.g. your entity_ids should be:
For future reference, you shouldn’t change your unique_id ever. Always just fix the sensor without touching the unique_id. This will retain your original entity_id and config entry without the headache you’ve created for yourself. If you can remember the original unique_id, I’d swap back and ignore the B configuration. Then in a couple of days when HA realizes B is no longer in the yaml, delete the b entity via the UI.
You don’t need to use a unique_id, but if you omit it, you can’t use the entity in the UI. That means you won’t be able to assign it to areas, change precision, update the icon, etc.