(Solved) Automation: notify for turn on coffee machine

Hi All,
I do a automation to send a notification on my iPhone to ask to turn on my coffee machine.
It was working on HA 2021.6 but since I upgrade to 2021.7 don’t get back the answer of the actionable notification.
Here is the code


alias: Coffee Machine Notification to iPhone (v2)
description: ''
trigger:
  - platform: time
    at: '12:10:00'
  - platform: time
    at: '15:20:00'
  - platform: time
    at: '18:30:00'
condition:
  - condition: zone
    entity_id: person.me
    zone: zone.home
  - condition: device
    type: is_off
    device_id: 5989f3d038c76ee1054569eb4cabaxxx
    entity_id: switch.smart_plug_2
    domain: switch
action:
  - service: notify.mobile_app_me_iphone
    data:
      message: Turn on ?
      title: Coffee machine
      data:
        actions:
          - action: COFFEE_ON
            title: 'Yes'
          - action: COFFEE_STAY_OFF
            title: 'No'
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: COFFEE_ON
        context:
          user_id:
            - 8f8c9dae2c704f709408b1ae3fed3xxx
    continue_on_timeout: false
    timeout: '00:00:30'
  - type: turn_on
    device_id: 5989f3d038c76ee1054569eb4cabaxxx
    entity_id: switch.smart_plug_2
    domain: switch
mode: single

Any idea why it doesn’t work anymore ?

Had the same problem 'til I discovered that the actions pop up by long-pressing the message. Don’t know why.

Thanks, my problem is not the same. The notification pop up but don’t do anything when I chose a action.

Is it working without the conditions?

Yes, if I force to run the automation (so skip conditions), I get the notification on the iPhone but the action button don’t do anything.

Think it’s the timeout. I copied the script part and tried with and without timeout (or rather with timeout, but continue_on_timeout: true )

With that option the coffee machine turn on after 30 seconds whatever I chose on the notification options

I can’t see an off part.

Have you tried to outsource the “wait for trigger part” into a second automation?

The first automation can send the notification, HA receives the log on which the second automation reacts and starts you coffee machine.

alias: tebra wants coffee
description: ''
mode: single
trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data: COFFEE_ON
    context:
      user_id:
        - 8f8c9dae2c704f709408b1ae3fed3xxx
condition: []
action:
  - type: turn_on
    device_id: 5989f3d038c76ee1054569eb4cabaxxx
    entity_id: switch.smart_plug_2
    domain: switch

Yes, that would produce a second automations and not everything is in one place but at least you don’t to react that fast to the message.

Thanks all for your replays and suggestions.
I had modified my automation and now it works.
As said here, the trick, was to don’t declare a static entity but declare a variable.
Here is my new automation

alias: Coffee Machine Notification to iPhone (v3)
description: ''
trigger:
  - platform: time
    at: '12:10:00'
  - platform: time
    at: '15:20:00'
  - platform: time
    at: '18:30:00'
condition:
  - condition: zone
    entity_id: person.me
    zone: zone.home
  - condition: device
    type: is_off
    device_id: 5989f3d038c76ee1054569eb4cabaxxx
    entity_id: switch.smart_plug_2
    domain: switch
action:
  - alias: Set up variables for the actions
    variables:
      action_oui: '{{ ''OUI_'' ~ context.id }}'
      action_non: '{{ ''NON_'' ~ context.id }}'
  - alias: Ask to turn on coffee machine
    service: notify.mobile_app_me_iphone
    data:
      message: Turn on Coffee machine ?
      data:
        actions:
          - action: '{{ action_oui }}'
            title: 'Yes'
          - action: '{{ action_non }}'
            title: 'No'
  - alias: Wait for a response
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: '{{ action_oui }}'
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: '{{ action_non }}'
    continue_on_timeout: false
    timeout: '00:00:30'
  - alias: Perform the action
    choose:
      - conditions:
          - condition: template
            value_template: '{{ wait.trigger.event.data.action == action_oui }}'
        sequence:
          - type: turn_on
            device_id: 5989f3d038c76ee1054569eb4cabaxxx
            entity_id: switch.smart_plug_2
            domain: switch
mode: single

1 Like

Hello tobra,

I’m very happy to know my script help you but… the trick for my case was to address multiple mobile devices that is not your issue…

Enjoy your coffee :wink: