I’m using the std Norwegian Weather integration. I want to base an automation on the daily temp forecasted for tomorrow. For simplicity I created a number helper and was just going to update that daily with the forecasted temp. However, despite reading endless posts I can’t make it work. I tried an automation using the get_forecasts service but failed to save it to a helper. I can see the number I want in the ‘weather home’ popup, but can’t see the values when looking at the entity in Dev Tools.
In short I’m not great at HA and at sea! Can anyone help me achieve the goal? Thanks
Did you read this one?
Describe the automation, then we can advise you better which “helper” is best for your situation, or if one is even needed.
There are a few I want to use. But basically within them they’ll use:
IF ‘tomorrow’s forecast temp’ > x THEN …
So if I stored the forecast temp in a number helper I could use this with no problem.
Thanks, Tom. I hadn’t seen that. Sounds good but when I add this to my config I get the following errors re device ID. Any idea why?
It’s a template sensor. So:
template:
- trigger:
- platform: time_pattern
minutes: /5
- platform: homeassistant
event: start
action:
- service: weather.get_forecasts
data:
type: daily
target:
entity_id: weather.openweathermap
response_variable: owm_daily
sensor:
- name: Legacy Forecasts
state: "{{ states('weather.openweathermap') }}"
attributes:
forecast: "{{ owm_daily['weather.openweathermap'].forecast }}"
Thanks Tom. That done the trick. It’s now created a sensor with with coming day’s max temps in it plus lots of other stuff - see pic
. So next question… If I want to use tomorrow’s temp as part of an automation how do I strip it out and maybe save it in it’s own entity so I can use it form there?
You can use the following to get the temperature from tomorrow’s forecast now you have that template sensor set up:
{{state_attr('sensor.legacy_forecasts','forecast')[1].temperature}}
Perfect. Thanks! Appreciate your time. And I can use that as a > or < than within an automation? Or I guess create a helper/entity with it…
Yep you can create a ‘value template’ trigger in an automation and use something like this:
{{ (state_attr('sensor.legacy_forecasts')[1].temperature < 16) }}
In this example, the trigger passes when the forecasted temperature is less than 16. You can do some other comparisons if you want, more info in the docs here.
You might want to consider having this as an automation condition and the trigger being something else, like the time of day. It depends on what the resulting action is as you might keep triggering the automation repeatedly.