Actionable notifications returning the text of the message

Hello, I am trying to configure an actionable iOS notification in order to switch back on/off some light.

To be more specific, I have multiple separate lights which after an amount of time X, they are switched off. I would like to create an action in order to switch back on that specific light.

AFAIK I didn’t find a way for the notification to return back, within the category and/or the action the message of the notification inside the ios.notification_action_fired event. I would like to keep just one category and select the proper further actions by using that text in order to understand which light triggered that notification. In case it’s not possible I will have to create inside the configuration.yaml file one category for every light I have.

Any clue on how can I do it?

Here are some snippets from what I do.

Note the action_data here from my one automation:

    - service: notify.mobile_app_xxx
      data:
        title: "Security"
        # timer.rhs_garage_door_timer -> XXX's garage door
        message: >-
          {% set name = None %}
          {% if trigger.event.data.entity_id | regex_search("lhs", ignorecase=True) %}
            {% set name = "YYY's garage door" %}
          {% elif trigger.event.data.entity_id | regex_search("rhs", ignorecase=True) %}
            {% set name = "XXX's garage door" %}
          {% else %}
            {% set name = "The main gate" %}
          {% endif %}
          {% set cover_entity = trigger.event.data.entity_id | replace('_timer', '') | replace('timer.', '') %}
          {% set cover_last_changed = states["cover"][cover_entity].last_changed %}
          {{ name }} has been left open for {{ ((as_timestamp(utcnow()) - as_timestamp(cover_last_changed) + 5) // 60) | int }} min.
        data:
          apns_headers:
            # group notifications by the timer entity
            'apns-collapse-id': "{{ trigger.event.data.entity_id }}"
          push:
            category: "cover_open"
          action_data:
            # convert this to the cover entity to use in the automation that receives this
            cover_id: "{{ trigger.event.data.entity_id | replace('_timer', '') | replace('timer', 'cover') }}"
            timer_id: "{{ trigger.event.data.entity_id }}"

And in another automation this is how I access it:

    - service: cover.close_cover
      data:
        entity_id: "{{ trigger.event.data.action_data.cover_id }}"

In my case, I have a timer that starts if the main gate or garage doors are opened. After the timeout, it will send a notification and in that notification I need to know which entity triggered it. I think this is similar to what you need.

Hello @parautenbach thanks for your answer. I think I wasn’t enough clear. I know I can send notifications based on some conditions… what I would like to do is to understand which notification was answered.

I will try once again. Let’s say I have two lights.

I switch the first off, I get a notification.

A few moments later, I switch the second one, I get another notification.

The notification is actionable, this way I can switch the light back on. The issue is, I can’t see any way to dinamically understand which notification was answered on the phone.

AFAIK I will have to define multiple/different identifier inside my yaml ios configuration. I would like to understand if I can get back from the notification the id or some text I can push (not visible). That way I will be able to define one only identifier “SWITCH_BACK_ON” and I will be able to associate the right action inside Node-Red using a simple switch.

I hope it’s more clear now.

Thanks for your support.

What I sent you doesn’t have to do with conditions. You can include custom data in the notification (via action_data) from HA to the device, which will be included in the event’s payload when the action is triggered on the device, and hence echoed back to HA. In your case, put the light entity in your action data and that way you’ll know which one was triggered.

Hello @parautenbach I am using Node-Red to create automations. I wrote the code this way:

{
    "title": "Light off",
    "message": "Light off after 15 minutes",
    "data": {
        "push": {
            "category": "outdoor_light_notification",
            "summary": "outdoor_light",
            "entity_id": "light.outdoor_light"
        }
    }
}

I tried with both entity_id or action_data but in both cases, when I answered directly from the notification, what I got back in Node-Red was a payload without the entity_id information.

I can’t help you with Node-Red. You should ask this in the third party and Node-Red section on the forum. The companion app and HA work fine as I described.

Ok, thank you @parautenbach, I will use your info in order to understand how to translate it inside NodeRed.

1 Like