Variable "for" in wait_for_trigger doesn't render

The docs also explicitly states you can use templates:

Yeah my man I’m stumped. seconds_before_dimmed obviously contains the correct value.

Hopefully someone smarter than me comes along to help ya out. I’m out of ideas :man_shrugging:

1 Like

Based on your results, it appears that script variables are not passed into a wait_for_trigger. You can confirm that by performing one more experiment: replace the Template Trigger with a State Trigger.

  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.studiekamer_occupancy
        for:
          seconds: '{{ seconds_before_dimmed }}'
  • If it fails then it supports the theory that script variables are not passed into the wait_for_trigger.
  • If it succeeds then the problem is a bit more nuanced and depends on what kind of trigger is used in the wait_for_trigger.

Either way, I feel it’s a bug because the expectation is that a script variable should be able to work within the wait_for_trigger. Report it as an Issue in the Core repository on GitHub.


EDIT

Looks like you already posted it (about 3 hours ago):

Yeah I figured after the extensive troubleshooting with @jazzyisj it felt more like a bug.

I changed the wait_for_trigger to your example and… looks like it’s more nuanced because setting it to state DOES render the “for: seconds:” template. While interesting, sadly no solution because (as far as I know) the state trigger doesn’t accept a variable for entity_id

I’m encountering the same problem, and after hours of searching and testing, I fallback to use a choose with big chunks of code repeated just because I cannot put a variable in the for in the wait for trigger: template thing.

Anybody found something else on this subject? Why this thing isn’t solved yet? Am I missing something?

Because nobody in the Core Development team responded to Issue 63886 and, after one month, the Issue was automatically marked as stale and was closed.

This outcome isn’t the norm but it can happen (and, yes, it can be frustrating); it’s happened to a few Issues I have reported.

If you look at the backlog of open Issues and assume only half of them are legitimate bugs, that still leaves far more problems to investigate and fix than resources available to handle them.


NOTE

I haven’t recently tested a wait_for_trigger with a templated for in a Template Trigger, so I will assume that based on your experience it’s still not fixed. I only mention it because sometimes a bug will be fixed as a result of some other change and the Issue that had reported the bug is never formally closed (and just goes stale and self-closes). This has also happened to one of my reported Issues. I kept it open for over two years then allowed it to self-close. Months later, I discovered the reported bug was fixed.

1 Like

It probably doesn’t make any difference but I wonder if:

for: "{{ my_variable|int(10) }}"

Makes any difference? If the variable was seconds anyway, then you could try using that in the for directly without having to add the hours, minutes, seconds mapping.

No template is accepted in this field. That’s the problem.

…Yes, yes it is - that has already been tested - it will accept a template per the docs, of say the numerical state of something like an input_number helper. What is not working is template variables. I simply wondered if it was entire for entry that was not rendering the variable or if it was only the mapping below the for key.

I saw it was tagged as “stale”, but I don’t quite know how those are handled.
The problem is not solved yet, I confirm. That’s really unfortunate because that’s the only way I can do what I want to do which is:

  1. check if a template is true (with an “if template condition”)
  2. if not then wait for the template to be true for a certain time, time that will vary depending on the circumstances of the calling script.
  3. some actions.

Actually the docs mention that the template trigger for can be templated in the Automation Trigger page, but in the scripts page for wait for trigger it’s not mentioned, but let us assume it is.

I just retested, just to make sure, and something like for: "{{ my_variable|int(10) }}" doesn’t work either unfortunately. For the wait for trigger- template, there is no choice then putting an actual value, no template whatsoever.

1 Like

Maybe I’m misunderstanding something here, but this works just fine.

test_wait_trigger:
  alias: Test Wait Trigger
  sequence:
  - wait_for_trigger:
    - platform: template
      value_template: "{{ is_state('input_boolean.charlie_home_alone', 'on') }}"
      for: "{{ states('input_number.charlie_mealtime_notification_interval') }}"

  - service: fan.turn_on
    target:
      entity_id: fan.living_room_fan
  mode: single

Yup, that works, what doesn’t is:

variables:
  my_wait_time: 10

sequence:
  - wait_for_trigger:
      - platform: template
        value_template: "{{ is_state('person.andrew','home') }}"
        for: "{{ my_wait_time }}"

or

for:
  seconds: "{{ my_wait_time }}"

In short, variables either passed to the script, or set in the script / automation - don’t seem to make it to the wait_for_trigger.

Ah. Gotcha. Yup, looks like something is amiss there. When the for: parameter is templated none of the trigger attributes appear to be passed.

And there are errors in the log.

2024-01-13 19:52:39.385 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'wait_time' is undefined when rendering '{{ wait_time }}'
2024-01-13 19:52:39.387 ERROR (MainThread) [homeassistant.components.template.trigger] Error rendering 'Test Wait Trigger' for template: offset  should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F'
1 Like

Just wanted to say that I’m having the same issue, and find it very interesting that the thread was dormant for 2 years and then picked up again less than a week before I ran into it!

Is there any way we can re-open the bug?

Ha! When I replied to the most recent comment I didn’t go back and read the whole thread. I had forgotten all about looking into this before. At least I came to the same conclusion much faster this time. :rofl: Damn, getting old sucks…lol.

You’ll probably just have to open a new issue in core. Provide a link back to the closed issue in your comments.