Actionable Push Notification when TV turned on after set time to change entity status?

Hello all,

First post, and noob for HA. I’ve finally taken the chance to amalgamate all my smart kit into one place. I’m pretty happy with where I’m at, I’ve used HACS to add additional devices using API’s etc.

I’m now looking to build some automation between devices now they’re all in one place.

We’ve got a 2 year old that goes to bed around 19:00, so figured it would be cool to prompt on our phones that when the TV is turned on, do we want to enable ‘night mode’ on our sonos Beam.

I’ve read up on a few threads/tutorials, and have built the following using the UI rather than editing configuration.yaml directly. But what I’m not sure on is why I can’t trigger the entity ‘switch.sonos_lounge_night_sound’ to on when pressing the actionable push notification?

Script below:

- id: '1651129291824'
  alias: Sonos Night Mode Push Notification
  description: ''
  trigger:
  - platform: device
    device_id: 849e6b384a1f992c69e179841d38c5ca
    domain: media_player
    entity_id: media_player.lounge_tv
    type: turned_on
  condition:
  - condition: time
    after: '19:00:00'
  action:
  - service: notify.notify
    data:
      title: Sonos Night Mode
      message: Do you want to enable Night Mode, Oliver may be in bed?
      data:
        actions:
        - action: switch.sonos_lounge_night_sound
          title: Enable
  - wait_for_trigger:
    - platform: event
      event_type: ios.notification_action_fired
      event_data:
        actionName: switch.sonos_lounge_night_sound
    timeout: '10'
  - condition: state
    entity_id: switch.sonos_lounge_night_sound
    state: 'On'
  mode: single

That last bit is a condition, not an action.
Replace it with:

    - service: switch.turn_on
      data:
        entity_id: switch.sonos_lounge_night_sound

Also bear in mind that data is case sensitive. state: 'On' would not work and should be state: 'on'

Thanks @lolouk44 thats done the trick.

Maybe you can help educate me further, I’ve seen a few examples of push notifications where by it automatically presents you were options to action or decline, the way my script is currently set up is I have to long press on the notification to present the button to trigger the action? Any ideas how to change this? I appreciate it may by OS specific, in my case both myself and my wife use IOS.

is this on phone? I have the same, however on my Apple watch it presents all relevant options, I think it’s by design, though happy to be proven wrong :wink:

Yes, this is on phone. I could of swore I’ve received other notifications where it presents an option to accept/decline.

I’ll do a little digging!

Any ideas how I could also include an ‘ignore’ or ‘decline’ option too? I’ve included a timeout of 10 seconds, but it would just be nice for completeness.