2025年1月19日星期日 上午10:36:46

How to wait for multiple different triggers and continue with different sequences bases wait for trigger

1 周 前
#59980 引用
https://www.home-assistant.io/docs/scripts/#wait


How to wait for multiple different triggers and continue with different sequences bases wait for trigger


https://community.home-assistant.io/t/how-to-wait-for-multiple-different-triggers-and-continue-with-different-sequences-bases-on-the-fullfilled-trigger/232567
0
1 周 前
#59981 引用
it’s doing exactly what you told it to do

- wait_for_trigger:
          - platform: time
            at: "10:30:00"
          - platform: event
            event_type: mobile_app_notification_action
            event_data:
              action: roborock_autoclean_now
          - platform: event
            event_type: mobile_app_notification_action
            event_data:
              action: roborock_autoclean_abort
- choose:
    - conditions:
        - condition: template
          value_template: '{{ wait.trigger.event.data.action == "roborock_autoclean_now" }}'
      sequence:
        - service: XXX
    - conditions:
        - condition: template
          value_template: '{{ wait.trigger.event.data.action == "roborock_autoclean_abort" }}'
      sequence:
        - service: XXX
0
1 周 前
#59982 引用
you can get the state object for the wait_for_trigger from wait.trigger
0
6 天 前
#60015 引用
alias: wait for study study
description: ""
triggers: []
conditions: []
actions:
  - wait_template: "{{ is_state('binary_sensor.contact_sensor', 'off') }}"
    continue_on_timeout: true
mode: single



This action evaluates the template, and if true, the script will continue. If not, then it will wait until it is true.
0
6 天 前
#60016 引用
Multiple wait_for_triggers
0
6 天 前
#60017 引用
trace timeline

wait.completed being true means that the trigger happened. If wait_for_trigger had reached the timeout, then wait.completed would’ve been false (also wait.remaining would’ve been 0 of course).




automation:
  alias: The mf_social solution
  trigger:
    platform: state
    entity_id: binary_sensor.1
    to: 'on'
  action:
    - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.2
        to: 'on'
      timeout:
        seconds: 30
    - condition: template
      value_template: "{{ not wait.completed }}"
    - service: notify.you
      data:
        message: "It happened"
0
5 天 前
#60018 引用
- id: '1596277325558'
  alias: xTest
  description: Test only.....
  trigger:
  - platform: state
    entity_id: binary_sensor.movimiento0105_occupancy
    to: 'on'
  action:
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.xxxx #<- put the second binary sensor here
      to: 'on'
      timeout: '00:00:30'
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.xxxx #<- put the second binary sensor here
        state: 'off'
      sequence:
        - servie: blalbla #<- put the action you want to take if the binary sensor didn't change
    default: []

This triggers when the the first binary_sensor changes to on, it then waits for 30 seconds and if the second binary sensor doesn’t change to on in these 30 seconds, it executes the action, otherwise nothing happens.
0
5 天 前
#60019 引用
wait.completed

https://www.home-assistant.io/docs/scripts/#wait-variable

wait.completed  true if the condition was met, false otherwise
0
5 天 前
#60020 引用
Template variable  Data
trigger.id  The id of the trigger.
trigger.idx  Index of the trigger. (The first trigger idx is 0.)

https://www.home-assistant.io/docs/automation/templating/#available-trigger-data
0
3 天 前
#60026 引用
Take different actions wait for trigger in home assistant

- wait_for_trigger:
          - platform: time
            at: "10:30:00"
          - platform: event
            event_type: mobile_app_notification_action
            event_data:
              action: roborock_autoclean_now
          - platform: event
            event_type: mobile_app_notification_action
            event_data:
              action: roborock_autoclean_abort
- choose:
    - conditions:
        - condition: template
          value_template: '{{ wait.trigger.event.data.action == "roborock_autoclean_now" }}'
      sequence:
        - service: XXX
    - conditions:
        - condition: template
          value_template: '{{ wait.trigger.event.data.action == "roborock_autoclean_abort" }}'
      sequence:
        - service: XXX
0