Hi, I need some help with the new way of dealing with weather forecast entities.
I am trying to configure a custom weather entity, combining forecast from an online source with my own sensors.
I read that we have have to use a trigger template, calling weather.get_forecasts
service.
Here is my code (which seems to work)
- trigger:
- platform: state
entity_id:
- weather.casa
- sensor.th_esterno_temperature
- sensor.th_esterno_humidity
- sensor.meteonetwork
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.casa
response_variable: daily_forecast
weather:
- name: Forecast Casa
unique_id: forecast_casa
condition_template: "{{ states('weather.casa') }}"
temperature_template: "{{ states('sensor.th_esterno_temperature')|float(0) }}"
temperature_unit: "°C"
humidity_template: "{{ states('sensor.th_esterno_humidity')|float(0) }}"
pressure_template: "{{ state_attr('sensor.meteonetwork', 'smlp')|float(0) }}"
wind_bearing_template: "{{ state_attr('weather.casa', 'wind_bearing')|float(0) }}"
wind_speed_template: "{{ state_attr('weather.casa', 'wind_speed')|float(0) }}"
forecast_daily_template: "{{ daily_forecast['weather.casa'].forecast }}"
I want to trigger updates when any of the sources state changes, as opposed to fixed time pattern, but here is the problem: the code looks inefficient to me, as it calls weather.get_forecasts
unnecessarily, in case of any change of my local sensors.
How can I update each part of the weather entity only when needed? Maybe using trigger IDs ?
Thanks in advance
Marco