I think I have a rather specific problem with repeat until logic.
My automation looks as follows:
alias: Fenster offen!
description: ''
variables:
time: -5
timedelay: 5
trigger:
- platform: state
entity_id:
- binary_sensor.req0542232_state
- binary_sensor.req0542255_state
- binary_sensor.req0542235_state
- binary_sensor.req0542213_state
- binary_sensor.req0542146_state
- binary_sensor.peq0569322_state
from: off
to: on
condition: []
action:
- repeat:
sequence:
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- variables:
time: '{{ time + timedelay }}'
- service: input_text.set_value
data_template:
entity_id: input_text.message_title
value: Fensterwarnung
- service: input_text.set_value
data_template:
entity_id: input_text.message_text
value: >-
{{ trigger.from_state.attributes.friendly_name }} ist seit {{ time
}} Sekunden offen.
- service: script.send_message
until:
- condition: state
entity_id: "{{ trigger.entity_id }}"
state: off
mode: restart
max: 20
… as you can see, I am trying to accomplish a window open warning, which can be triggered by either of my windows opening.
I would like to repeat this message (ideally displaying the correct time for how long it is already open) with the stop condition being the closing of said window. However, when I am trying to save the code above, I get the error message that the entity_id is invalid: “Message malformed: Entity {{ trigger.entity_id }} is neither a valid entity ID nor a valid UUID for dictionary value @ data[‘action’][0][‘repeat’][‘until’][0][‘entity_id’]”.
However what I don’t get is why the friendly name of the trigger can be evaluated, but the entity_id cannot.
Could anybody help me please? I also searched this forum, but I couldn’t find a solution. I think my problem is that I have mulitple triggers…
The State Condition’sentity_id option wants a valid entity_id described as a string but got this {{ trigger.entity_id }} which is a template. Not all options support templates.
Thanks a lot for this input, this works like a charm!
The only thing missing now is the accurate tracking of time.
Still I have the problem that every message it resets the variable “time”. Is there any way to avoid the resetting of the variable, when being inside the repeat until?
Thanks a lot for the support This is what I have been missing with other home automatisation softwares
The automation is triggered when one of the six binary_sensors changes from off to on and stays on for at least 5 seconds. The automation’s action uses a repeat - while to report the window is open every 5 seconds. It computes the elapsed time by simply multiplying repeat.index (a variable that is automatically incremented for each loop) by 5. The repeat - while iterates as long as the binary_sensor’s state remains on and ceases when it changes back to off.
Thanks a lot for the support.
I will try this solution this evening, but the code itself looks as it might work!
I did not know that I can access the repeat.index - this is of course much better than my solution!
I think this topic can be closed - again thanks for the support
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.
Sorry to open up this topic again.
Your solution works very fine, has, however a fundamental flaw - or maybe this is a general flaw of my overall approach: If two consecutive windows have been opened, i.e. the automation has been triggered once by one entity, and another enitity triggers the automation, the first automation will be overwritten, i.e. I will not receive any more message about the first opened window…
Is there any way to avoid it?
I noticed that when I revised your automation but I left the mode as restart because I thought that’s the way you wanted it to work (the notification for one binary_sensor is superseded by the next binary_sensor). If you want all notifications to occur concurrently then, yes, you must change the mode to parallel.