crankshaft
(crankshaft)
December 14, 2023, 7:55pm
1
I have just created an automation that determines the order in which the radiators heat up but it’s not triggering.
Any idea what the problem might be ?
alias: Wiser Order
trigger: []
action:
- wait_template: |-
{%- for item in result.trvs -%}
{%- if state_attr(item[0], 'temperature')|float >= (item[1]|float+degrees) -%}
{%- set r2.done = r2.done + 1 -%}
{%- set result.trvs = result.trvs[:r2.done] + [(item[0], item[1], (now() - r2.start).total_seconds()|int)] + result.trvs[r2.done+1:] -%}
{%- endif -%}
{%- endfor -%}
{%- if r2.done >= r2.count -%}
true
{%- endif -%}
- service: persistent_notification.create
data:
message: "{{ sensors }}"
variables:
degrees: 0.1
start: "{{ now() }}"
sensors: |-
{% set result = namespace(trvs=[],start=now()) %}
{% for trv in states.sensor %}
{% if 'trv_' in trv.entity_id and '_signal' in trv.entity_id %}
{% set result.trvs = result.trvs + [(trv.entity_id, trv.attributes.temperature,0)] %}
{% endif %}
{% endfor %}
{%- set r2 = namespace(start=now(),done=0, count=result.trvs|length) -%}
{{ result.trvs }}
mode: single
petro
(Petro)
December 14, 2023, 7:59pm
2
You don’t have any triggers.
crankshaft
(crankshaft)
December 14, 2023, 8:00pm
3
Sorry, should have explained I trigger this manually.
petro
(Petro)
December 14, 2023, 8:01pm
4
There’s also a lot of issues with the templates. You’re making an assumption that variables are shared through the templates, which they are not.
crankshaft
(crankshaft)
December 14, 2023, 8:08pm
5
Thanks for helping, appreciate that, been trying this on and off all day.
Are you referring to this:
{%- set r2 = namespace(start=now(),done=0, count=result.trvs|length) -%}
I have now moved it to to top of the wait_template
petro
(Petro)
December 14, 2023, 8:09pm
6
Yes, but there’s a lot more you need to fix. You’re using result.trvs in the wait template, namespaces cannot be passed between templates.
crankshaft
(crankshaft)
December 14, 2023, 8:11pm
7
Oh yes, I did not notice that, I should be using the sensors variable.
petro
(Petro)
December 14, 2023, 8:13pm
8
I also think you have a miss-conception on how the template will work. It’s going to roll up immediately. It’s not going to spend time executing the template over and over again.
EDIT: Well, nevermind, it will. Sorry, disregard.
petro
(Petro)
December 14, 2023, 8:16pm
9
alias: Wiser Order
trigger: []
variables:
degrees: 0.1
start: "{{ now() }}"
sensors: |-
{% set result = namespace(trvs=[]) %}
{% for trv in states.sensor %}
{% if 'trv_' in trv.entity_id and '_signal' in trv.entity_id %}
{% set result.trvs = result.trvs + [(trv.entity_id, trv.attributes.temperature)] %}
{% endif %}
{% endfor %}
{{ result.trvs }}
action:
- wait_template: |-
{%- set result = namespace(done=[]) -%}
{%- for entity_id, temperature in sensors -%}
{%- if state_attr(entity_id, 'temperature') >= (temperature + degrees) -%}
{%- set result.done = result.done + [(entity_id, temperature, (now() - start).total_seconds()|int)] -%}
{%- endif -%}
{%- endfor -%}
{{ result.done | length == sensor | length }}
- service: persistent_notification.create
data:
message: All trvs complete
mode: single
Pretty sure this is what you’re looking for. Unfortunately, because you’re using a wait template, you can’t get the done results out.
crankshaft
(crankshaft)
December 14, 2023, 8:22pm
10
Thanks very much, but that’s exactly what I need, I need to know the order in which each radiator heats up by x degrees so that I can then balance them by adjusting the lockshield valves on each radiator, starting with the one that heats up first (closeset to the boiler)
I dont really care how much time they took, all I need is the order
petro
(Petro)
December 14, 2023, 8:25pm
11
I’ll have to think this over for a bit.
tom_l
December 14, 2023, 8:52pm
13
It you have no triggers and you run this manually you should be using a script, not an automation. All the same actions are available. Automations are just triggered scripts.
crankshaft
(crankshaft)
December 16, 2023, 6:51am
14
Thanks, but how would a script work and prompt the order when it ends where the automation would not ?
crankshaft
(crankshaft)
December 16, 2023, 6:57am
15
@petro - I just tried your last code, unfortunately it does not appear to wait for each temp to reach and completes immediately.
tom_l
December 16, 2023, 7:05am
16
Like this:
script:
wiser_order:
sequence:
- variables:
degrees: 0.1
start: "{{ now() }}"
sensors: |-
{% set result = namespace(trvs=[]) %}
{% for trv in states.sensor %}
{% if 'trv_' in trv.entity_id and '_signal' in trv.entity_id %}
{% set result.trvs = result.trvs + [(trv.entity_id, trv.attributes.temperature)] %}
{% endif %}
{% endfor %}
{{ result.trvs }}
- wait_template: |-
{%- set result = namespace(done=[]) -%}
{%- for entity_id, temperature in sensors -%}
{%- if state_attr(entity_id, 'temperature') >= (temperature + degrees) -%}
{%- set result.done = result.done + [(entity_id, temperature, (now() - start).total_seconds()|int)] -%}
{%- endif -%}
{%- endfor -%}
{{ result.done | length == sensor | length }}
- service: persistent_notification.create
data:
message: All trvs complete
Scripts are services so you can call it from a button tap action in your dashboard.
show_name: true
show_icon: true
type: button
tap_action:
action: call-service
service: script.wiser_order
icon: mdi:valve
EDIT: if petro’s automation has issues so will that script. It is the same.
crankshaft
(crankshaft)
December 16, 2023, 7:15am
17
Thanks for that, but the problem is I dont just need to know when all TRVs have reached their temperature, but I need to know the order in which they reach temperature so that I can determine what the sequence is in order to adjust the lockshield valves and balance the system.
The limitation with Petro’s script is that it cannot report out the data and only a text message saying “All trvs complete”.