home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.51k stars 30.34k forks source link

Value_Templates not not work with Repeat Until/While in Scripts #128393

Open GSVil opened 1 hour ago

GSVil commented 1 hour ago

The problem

Using templates with Repeat Until/While does not work when trying to validate against the state of an entity. It does not appear to pick up state changes. Using the Script Builder (GUI) works, but I'm using value_template's so it will not work for me.

I'm trying to check when the state of a media-player changes to IDLE. It only sees the initial state (for example playing), even if the state changes during the script execution.

I have tested with both is_state () and states (), both fail to retrieve the state changes of an entity.

What version of Home Assistant Core has the issue?

core-2024.10.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Scripts

Link to integration documentation on our website

https://www.home-assistant.io/integrations/script/

Diagnostics information

No response

Example YAML snippet

Tested both the following, they fail to validate correctly when the state of an entity changes.
**TEST 1**
repeat:
  until:
    - condition: template
      value_template: "{{ is_state('media_player.bar_voice_assistant_speaker', 'idle') }}"
  sequence:
    - delay:
        milliseconds: 500 
    enabled: 

**TEST 2**
repeat:
  until:
    - condition: template
      value_template: "{{ states('media_player.bar_voice_assistant_speaker') == 'idle' }}"
  sequence:
    - delay:
        milliseconds: 500 
    enabled: 

**TEST 3** - Works, but it does not use value_template, which is what I'm trying to use.
 repeat:
  until:
    - condition: state
      entity_id: media_player.bar_voice_assistant_speaker
      state: idle
  sequence:
    - delay:
        milliseconds: 500

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 hour ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (script) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `script` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign script` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


script documentation script source (message by IssueLinks)