Trigger automation based on weather report

I have an air to water heatpump that heats both my indoor air and tap water. Higher outdoor temps means better effficieny and I’m thinking about how I could optimize this with Home Assistent which I have integrated with the pump. Normally, the heatpump simply triggers the hot water cycle when the temperature in the tax goes from max 53 degrees celcius to 47 degrees celcisus. Were I live the day temp during summer can be 25 degrees and 10-15 during night! However, if the temp is above 20 degrees the pump will overheat and start using the immersion heater which is bad. So ideally, the hot water should be made at outdoor temps at 20 degrees.

My idea is the following but I’m not sure its possible to do with HA.

  • Every morning at 09:00 an script/automation should run that checks todays weather forecast. It should look at the average temperature for each hour.
  • If the max temp is equal or below 20 degrees celcius, then it should somehow start a timer or schedule a hot water run at that time.
  • If the max temp is above 20 degrees, then the time when its 20 degrees should be selected, the hot water should be triggered. For example if the temp is 20 at 12:00 and 22 at 13:00, then the hot water should be triggered at 12:00.

This leaves me with a couple of questions:

  1. How can I schedule an automation with another automation?
  2. Is there a simple way get this forecast data?
  3. How can I write this logic? Maybe multiple automations?

You would generally write a script to do actual tasks in this case, and run automation(s) that fire the scripts. Having an automation generating a trigger that fires another automation is very iffy and not suggested in any scenario. Scripts which are actually automnations that run on call as opposed to having their own start trigger were made for that.
You will have to find your data, I’m sure what you want is available.
The logic I would suggest drawing a flow chart what you want to happen when,then just write some scripts and automations.

I see, shouldnt be to difficult to write the scripts. I think the biggest difficulty will be how to trigger the automation based on a dynamic value.

I guess the script could start a timer and then when the timer finishes the automation that starts the, hot water cycle would run.

It’s being overthought.
The simple solution is to have the automation that selects the time to have the hot water scheduled, simply sets the value of a date time helper.

An automation can then be used with a time trigger, that uses the helper as the time to trigger, that can then handle actually turning the water on.

As for the whole forecast part, that’s reasonably easy - Weather - Home Assistant it’s weather.get_forecasts set to hourly, and then you can work through the array, say the entity id is weather.home then something like:

{%- set t = now() -%}
{%- for i in range(0,12) -%}
  {%- set h = forecast['weather.home']['forecast'][i] -%}
  {%- if (h['temperature'] < 20) -%}
    {%- set t = h['datetime'] -%}
  {%- else -%}
    {%- break -%}
  {%- endif -%}
{%- endfor -%}
{{ t }}

Not tested - but something along those lines.
That will take the forecast response variable (forecast) from the get weather forecasts service call. And then start looking at the average temperature up to 13 hours into the future ((temp + templow)/2) and if it is below an average of 20, then setting the value t to the timestamp of that forecast hour. The loop will step forwards through the 13 hours setting the value of t to the timestamp each time the average temperature is below 20, until the average temperature goes above 20, at which point the loop exits - leaving you with the timestamp of the forecast hour before it goes above 20. If this was in the value template of the service call to set the datetime helper, it should work fine.

Note you mention both an automation on a max temperature and an average temperature, I went with average here, but it can be easily changed to work with just max temperature.

I hope this gave some idea of how to proceed.

EDIT:
Edited because the hourly forecast doesn’t have templow - that must be only daily forecasts.

Ah, I am actually experimenting with this right now as chatgpt suggested this type of approach :smiley: Gonna post the final solution when I have it figured out.

1 Like

Strongly recommend not getting it to write the code.

So, why ask here if chatgpt is giving you advice? Seems like you prefer chatgpt than somebody experienced here at the forum who is trying to help…

Didn’t think about it until after my post lol. I don’t trust it but it is useful for some things.

Why are you using the forecast to try to schedule it, rather than running when the outside temperature is 20°C?

Yes that is one option of course. The problem is that then it will not run at all if temp does not reach 20.

I see. First step, as linked in Andrew’s post above, is to get a local weather integration set up and a trigger-based sensor using the get_forecast service to pull the forecast into an attribute.

Once you have that, paste the attribute data here showing the structure of your forecast and we can start trying to work out what you want.

If you can explain it in logical steps, HA can certainly do it.