I want to change the heat curve of my heat pump at different temperatures and I want it to check this every 15min. I have created scripts for each heat curve change and those works indiviudally but my automation doesn’t work. It is my first automation and I feel like I have no idea of what I am doing, most of the code is written with the help of ChatGPT. I hope I have pasted the code correctly.
That is an automation that calls script1. Script1 choose another script from list1 and calls that. That script from list1 calls still another script from list2.
None of the scripts have actual code, and recursively call each other.
In addition to SG’s comments above, it would help us if you would split the different parts instead of pasting them as one block… unless that actually how it is? If that’s the case, that’s the problem.
# This part is formatted as if taken from the Automation editor
alias: Set heat curve every 15min
description: ""
trigger:
- platform: time_pattern
minutes: "/15"
action:
- service: script.check_temperature
# This part, as if it's in configuration.yaml
script:
check_temperature:
sequence:
- variables:
temperature: "{{ states('sensor.pink_palace_outdoor_temperature') | float }}"
- choose:
- conditions: "{{ temperature > 12 }}"
sequence:
- service: script.heating_curve_0_50
- conditions: "{{ 12 >= temperature > 5 }}"
sequence:
- service: script.heating_curve_0_55
- conditions: "{{ 5 >= temperature > 0 }}"
sequence:
- service: script.heating_curve_0_60
- conditions: "{{ 0 >= temperature > -3 }}"
sequence:
- service: script.heating_curve_0_65
- conditions: "{{ -3 >= temperature > -5 }}"
sequence:
- service: script.heating_curve_0_7
- conditions: "{{ temperature <= -5 }}"
sequence:
- service: script.heating_curve_0_75
#Everything past here is either an improperly indented addition to the above
# or properly indented if it's in scripts.yaml...
# And why are they here...? They aren't being used by anything shown anywhere else...
heating_curve_above_12:
sequence:
- service: script.heating_curve_0_50
heating_curve_12_5:
sequence:
- service: script.heating_curve_0_55
heating_curve_5_0:
sequence:
- service: script.heating_curve_0_60
heating_curve_0_neg3:
sequence:
- service: script.heating_curve_0_65
heating_curve_-3_-5:
sequence:
- service: script.heating_curve_0_7
heating_curve_below_-5:
sequence:
- service: script.heating_curve_0_75
What ChatGPT produced appears to be needlessly verbose.
It would be preferable to focus on your requirements and develop something more concise.
This can be done when the outdoor temperature actually changes as opposed to a fixed schedule of every 15 minutes. Would that be acceptable? Or is there a requirement to only check every 15 minutes?
Post the code for those scripts because what is shown above is an automation that calls scripts that call more scripts (but there’s no script code shown).
Doing it based on outdoor temp changes would be ideal, but I have tried to get my head around this every now and then for a year now, and I just don’t get it with the scripts automations etc. This at least I could get to trigger one script based on the timer, but when doing the logic with intervals, everything broke down.
Ths is an automation that works but it obviously only changes the heat curve once, based on the temp and without anything changing it to something else, it just changes the heat curve to the same (0.50) every time the temp is above 12C.
alias: Set heat curve every 15min above 12C to 0.50
description: ""
triggers:
- trigger: time_pattern
minutes: "15"
conditions:
- condition: numeric_state
entity_id: sensor.pink_palace_outdoor_temperature
above: 12
actions:
- action: script.heating_curve_0_50
metadata: {}
data: {}
mode: single
Currently, the first ChatGPT automation isn’t saved in HA because I get an error when saving it (no surprise, as it sounds like it is complete gibberish).
What more do I need to do to enable you guys to point me in the right direction?
This is one of the scripts. I’m completely new to this, so I’m sorry if I’m using the wrong terminology.
So, what this automation does, is that it runs every 15 minutes. It then ecks if the temperature is above 12, and if it is, it runs this script. All the script does is that it sends a value. Instead of having a number of scripts, I would simply have the action as a part of the automation. And you can trigger the automation on a change of the outside temperature, so it doesn’t have to run every 15 minutes. A neat thing about triggers, is that the thing that is triggered on is stored in a variable that you can tempuse. So if you use a numeric state trigger, this will trigger every time the temperature changes. The current temperature is then available in your automation as {{trigger.to_state}} and the previous temperature as ‘{{trigger.from_state}}’. You can then use a choose block to select which value to send.
Does that make sense to you?
Actually, you don’t even need to use trigger variables. I’ve made an example for you, using a temperature sensor in my house and a light so I could test it. If you replace the action and everything below it with the thing you had in your script, and adjust the sensor name, it should work. You can add more conditions if you wish of course.
We need a little more information about the bigger picture of this automation idea…
Are all the “heating curve” scripts the same except for the value being set in the action?
Do you see a need to be able to execute these specific actions from other automations, scripts, or from the dashboard?
If the answer to 1 is “yes” and 2 is “no”, then you probably only need a single automation without additional scripts. Otherwise, please describe the other differences and the other ways you plan to use the scripts.
The following automation example (or something similar) may meet your requirements.
Whenever the outdoor temperature changes, and maintains the new value unchanged for at least 15 seconds, the automation is triggered.
It confirms the new temperature value is a number (and not unknown or unavailable).
It sets the value of number.your_number (you will need to change that to match your actual number entity) based on values in a dictionary (think of it as a cross-reference table of temperatures and offset values).
alias: Set heat curve when temperature changes
description: ""
triggers:
- trigger: state
entity_id: sensor.pink_palace_outdoor_temperature
for:
seconds: 15
conditions:
- condition: template
value_template: "{{ trigger.to_state.state | is_number }}"
actions:
- action: number.set_value
target:
entity_id: number.your_number
data:
value: >
{% set t = trigger.to_state.state | float(13) %}
{% set offsets = {
t > 12: 0.5,
12 >= t > 5: 0.55,
5 >= t > 0: 0.6,
0 >= t > -3: 0.65,
-3 >= t > -5: 0.7 } %}
{{ offsets.get(true, 0.75) }}
If you prefer to have the automation trigger according to a fixed schedule, as opposed to whenever the outdoor temperature actually changes, this version is designed to do that.
alias: Set heat curve every 15 minutes
description: ""
triggers:
- trigger: time_pattern
minutes: "/15"
conditions: []
actions:
- action: number.set_value
target:
entity_id: number.your_number
data:
value: >
{% set t = states('sensor.pink_palace_outdoor_temperature') | float(13) %}
{% set offsets = {
t > 12: 0.5,
12 >= t > 5: 0.55,
5 >= t > 0: 0.6,
0 >= t > -3: 0.65,
-3 >= t > -5: 0.7 } %}
{{ offsets.get(true, 0.75) }}
As you can see from both examples, only a single automation is needed to achieve the goal of adjusting the number entity’s value by a specific amount based on outdoor temperature.