#Wait for trigger does not work if the condition is already met

1 messages · Page 1 of 1 (latest)

swift stag
#

I want to use wait_for_trigger to make sure a device (my tv) is ready to receive a command. But I always find myself having to guard for the fact that the TV might already be ready to receive the command

  - if:
    - condition: state
      entity_id: switch.aramathinewall_power_button
      state:
      - 'off'
    then:
    - wait_for_trigger:
      - trigger: state
        entity_id:
        - switch.aramathinewall_power_button
        from:
        to:
        - 'on'
      timeout:
        hours: 0
        minutes: 5
        seconds: 0
        milliseconds: 0
      continue_on_timeout: false
    alias: wait for tv to turn on

this gets quite repetitive. Am I missing something? This is also a race condition which is bad

jaunty gull
#

you can just use a wait_template

#

and you can encapsulate that logic in a script that you can call to ensure that the device is on, or even combine it with sending the command in the same script using a parameter that you pass in

swift stag
#

won't it have the same issue?

jaunty gull
#

no, because it will either go straight through if the condition is already met or wait until it is

#

wait_for_trigger requires a state change, which is what's complicating your logic

swift stag
#

yeah I just checked, it does work

#

that's good enough for me!

#

but I kinda wish this didn't require templates

limpid trenchBOT
#

If you have a feature request for Home Assistant you can open one here. Feature requests for custom cards, integrations, etc. should be made to the developer of that custom card/component.

jaunty gull
#

you could request a wait_for_condition or something like that if there isn't one already

#

you wouldn't be the first

#

a non-instanenous condition, in other words

chilly crow
#

I think when I ran into this a while ago I made a script that contained the logic from your original post and then just waited for that in the main automation

swift stag
#

wait for template doesn't work after all 🤔

swift stag
chilly crow
#

i just passed it the entity and the state, maybe the timeout

#

the logic was "if entity not in state, wait for entity to be in state"

jaunty gull
#

You need to use is_state()

chilly crow
#

is_state

swift stag
#

ah

#

silly me

#

that's right

honest panther
swift stag