Easier notifications in iOS 2021.5

:100:

Like you said solutions are available. Really no need to have home assitant notifications a apple/google cloud :cloud: feature only.

Just to name two examples: I have signal (using persistent websocket for notification) and telegram (using telegram’s own push service) on my google-free :tm: phone and have :zero: problems with it. Messages are delivered instantly and their is no significant battery drain at all :battery:.

I really hope that one that one day we can get privacy first notifications in home assistant which work without sign contracts with google or apple :rocket:

2 Likes

This is a great update, kudos to the dev team!
A couple of notes:

  1. I love the pattern of concatenating the context id to the event name, but it’s a bit cumbersome, especially since the UI turns to YAML in many places when a template is used. Will be great to somehow make this more streamlined, or perhaps even better, have the event be created with the parent context id set to that of the automation. Since wait_for_trigger can filter based on context, the UI can have a single checkbox with something like “only trigger for events sent as a result of this script/automation”, and behind the scenes it would add the right filter.
  2. Will be great if there was a way to send action_data per action, and not just per notification. This will allow several actions to trigger the same behavior with some variables (a made example - a notification sent to you at dusk letting you turn on the lights in various rooms, and you choose the one you’re in. Currently, you’ll need a lot of code to handle this, but with action_data per action, you can simply pass the received action_data as a parameter to light.turn_on).

Actually, my suggestion for #1 also solves #2, because once the action name doesn’t have the context id, it in itself can be the data you need.

Actually it’s one of worst practices. Don’t understand how one would love it.
However I suppose it might be a limitation of some platform (Android?) being not able to send data back. I’m guessing by the fact that previous iOS methods gives method to return it (category identifier).

I though tag can be used for that but it’s not available in returning message. Still not sure it’s limitation of one of supported platforms or just design decision.

Another “weird” decision is using message to pass operation type (cancel previous message). It deserves dedicated attribute.

Well, I did mention its shortcomings, and how I think they can be addressed, but I wouldn’t go as far as to call it “one of the worst practices”. Given the situation, I think it’s a good first step, that can be improved upon.

Any thoughts on how to do this new format with NR? I’d love to have it all in NR without having to rely on yaml for actionable notifications…

Here is a snippet from my project.
You can find tag and actions as new attributes.
Optionally I’m adding action_data.categories as replacement of actionName attribute which is not found in response any more. It’s not needed always since in most cases you can recognize the event only by action name. However I have at least one case It’s useful. Note sending data back is limited to iOS only.

Code bellow can be put into Service node configuration or added as “data” object to payload feeding this node

    {
        "message": "Washing machine has just finished after %s",
        "title": "Washing Machine",
        "data": {
            "tag": "WASHING_MACHINE",
            "attachment": {
                "url": "https://www.freepnglogos.com/uploads/washing-machine-png/washing-machine-icon-download-png-and-ico-icon-easy-4.png",
                "content-type": "png",
                "hide-thumbnail": false
            },
            "action_data": {
                "category": "WASHING_MACHINE"
            },
            "apns_headers": {
                "apns-collapse-id": "WASHING_MACHINE"
            },
            "push": {
                "badge": 0,
                "sound": {
                    "name": "default",
                    "critical": 1,
                    "volume": 0.3
                }
            },
            "actions": [
                {
                    "action": "WASHINGM_EMPTIED",
                    "title": "Mark emptied"
                },
                {
                    "action": "WASHINGM_LATER",
                    "title": "Remind me later"
                }
            ]
        }
    }

When I’m using the new method for actionable notifications on iOS with Apple watch, the “mobile_app_notification_action” event is only fired when the Home Assistant app is open on the watch. If it’s not open, I see the notification, I can choose an option, but nothing happens. Did I miss something in my implementation or is someone else also seeing that behavioiur? (latest verions of HA and iOS app)

Not really sure I understand the ask. What I was saying there was that I had been using Node RED to normalize the schema of iOS and Android notifications. So I could send a notification using the Android style schema and also have that notification be cloned to my mac with as similar look and feel as possible. Now I was glad to not have to do as much of that anymore since the two companion apps are moving to standardize on one schema for notifications.

If I understand your ask you just want to send all your notifications from Node RED? That’s fine, just use a call service node. Maxym provided an example of what that looks like above. Although if your sole goal is to avoid writing YAML I’m not really sure Node RED is going to help you. As you can see, you just end up writing JSON which is the same thing but more annoying to read and write.

I don’t use HA for any automations, all of them are in NR due to its feature set. Previously, I was yamling in the ios: and automation in yaml and firing them from NR. What I’d like to do is not have to do this going forward and create the entire actionable notification in NR. Given the new format in the example above, I made the example below which worked in my config.

What I’m not sure of is how I can fire this entire config from within NR? Conversion to JSON isn’t a problem…

automation robovac:
  - alias: "Dustin Emptying"
    trigger:
    action:
      - alias: "Set up action variables"
        variables:
          action_empty: "{{ 'EMPTY_' ~ context.id }}"
      - alias: "Send the notification"
        service: notify.mobile_app_dks_iphone
        data:
          message: "Can you empty the dustbin?"
          data:
            actions:
              - action: "{{ action_empty }}"
                title: "Yes"
      - alias: "Wait for a response"
        wait_for_trigger:
          - platform: event
            event_type: mobile_app_notification_action
            event_data:
              action: "{{ action_empty }}"
      - alias: "Handle the response"
        choose:
          - conditions: "{{ wait.trigger.event.data.action == action_empty }}"
            sequence:
              - service: homeassistant.turn_off
                target:
                  entity_id: input_boolean.vacuum_dustbin_needs_emptying

Hi all! Building an automation for when me or my girlfriend arrive at various places with a little greeting notification. Trying to make it as dynamic as possible and therefor I´m searching for a way to notify the phone/user that triggered the automation.

So what I need help with is if there is a way to dynamiclly assign the phone to th notify event i.e.
notify.mobile_app_{{ trigger.zone.person }}_iphone ← something like this :slight_smile:

ps, I´m rather new to scripting in HA so if you have a solution it might be followed up with some dumb questions :slight_smile:

Thanks in advance!

+1 for this.
How you reset the input_number?

That would be one possibility:

service: input_number.set_value
data:
  value: 0
target:
  entity_id: input_number.yourinputnumber

Is there a change to the way the Event trigger type is handled now that automations use Trigger ID’s?
When adding multiple actions in an actionable notification and setting up the same amount of Event triggers ( 1 for each action) you get the option to create a Trigger ID in the Event trigger. But when you use the Choose option the new Trigger ID’s don’t appear in the list. Is this a method we should use (maybe in yaml rather than Visual Editor) or should we stick to the original prescribed option?

I found a way to include trigger ID’s in the same automation and it’s working perfectly.

I would also love to have a way to send a different action_data per action. This would highly improve the possibility of making a single reuseable dynamic automation that handles tapped actions.

1 Like

Is it actually a limitation of android not being able to add a video stream as attachment?

this unfortunately doesn’t attach the stream:

service: notify.mobile_app_pixel_4
data:
  title: Unifi Protect Alarm
  message: motion detected
  data:
    entity_id: camera.livingroom

I found many tutorials and examples for iPhone but not a single one for android in order to confirm it’s working.

Yes, Android isn‘t capable of streams in notifications

thanks for clarification!

unfortunately testing these kind of notifications on android is really a pain. I tested with two different android phones and they behave quite different regarding parameters. some parameters cause one phone to not get any notifications anymore while the other one works fine. Having to restart the os each time is a bummer, too.

I have found the same issue with the Trigger ID’s not showing up in the list. Are you willing to share how you got this to work?

Hey buddy - were you ever able to resolve this issue or find a solution you can share?
Thanks