Skip to content

How does wait_for_trigger syntax works in pyscript? Struggling with Actionable Notification #760

@warheat1990

Description

@warheat1990

I've used pyscript (no YAML) for all my automation/scripts/trigger/etc and it rocks. However I'm struggling with how to do Actionable Notification. Consider this syntax that I've come across in this website https://www.devwithimagination.com/2023/04/16/using-actionable-notifications-in-home-assistant/

alias: Notify - Kids lights left on
description: ""
trigger:
  - platform: time
    at: "08:00:00"
condition:
  - condition: and
    conditions:
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
        alias: Is it a weekday?
      - condition: or
        conditions:
          - condition: state
            entity_id: light.childone_room_cloud_light
            state: "on"
          - condition: state
            entity_id: light.childone_room_bulb
            state: "on"
          - condition: state
            entity_id: light.childtwo_bedroom_main_bulb
            state: "on"
        alias: Are any of the boys lights on?
action:
  - alias: Set up variables for the actions
    variables:
      action_no: "{{ 'NO_' ~ context.id }}"
      action_turnoff: "{{ 'TURNOFF_' ~ context.id }}"
  - alias: Notify Mobile
    service: notify.mobile_app_twelve
    data:
      message: Boys lights are still on. Turn off?
      data:
        actions:
          - action: "{{ action_turnoff }}"
            title: Turn off lights
          - action: "{{ action_no }}"
            title: Leave On
  - alias: Wait for a response
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_no }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_turnoff }}"
  - alias: Perform the action
    choose:
      - conditions: "{{ wait.trigger.event.data.action == action_no }}"
        sequence: []
      - conditions: "{{ wait.trigger.event.data.action == action_turnoff }}"
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.childone_room_bulb
                - light.childtwo_bedroom_main_bulb
                - light.childone_room_cloud_light
mode: single


Seems straightforward except I'm struggling with this wait_for_trigger part of the YAML syntax

    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_no }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_turnoff }}"
  - alias: Perform the action
    choose:
      - conditions: "{{ wait.trigger.event.data.action == action_no }}"
        sequence: []
      - conditions: "{{ wait.trigger.event.data.action == action_turnoff }}"
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.childone_room_bulb
                - light.childtwo_bedroom_main_bulb
                - light.childone_room_cloud_light

How do I write this in pyscript?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions