HTML5 Push Notifs: Error trying to configure action buttons

Hi, I am trying to configure the new HTML5 Push Notifications.

They work fine, as long as I only set a message. I get errors when I try to configure action buttons.

I can manually call the notification service using the developer tools and the provided example from https://home-assistant.io/components/notify.html5/ and the action buttons work fine.

I just can’t figure out how to implement this in the configuration.yaml without getting this error in the log file:

16-09-02 08:04:27 homeassistant.core: Invalid service data for notify.html5: extra keys not allowed @ data[‘actions’]. Got [OrderedDict([(‘action’, ‘button1’), (‘title’, ‘Lights ON’)]), OrderedDict([(‘action’, ‘button2’), (‘title’, ‘Lights OFF’)])]

Here’s what works from the “call service” developer tool:

{
  "message": "Welcome home!",
  "data": {
    "actions": [
      {
        "action": "button1",
        "title": "Lights ON"
      },
      {
        "action": "button2",
        "title": "Lights OFF"
      }
    ]
  }
}

And here’s what I think should work, but does not, in configuration.yaml:

 - alias: "Notify I am home"
    trigger:
      platform: zone
      event: enter
      zone: zone.home
      entity_id: device_tracker.patboud_nexus5
    action:
      service: notify.html5
      data:
        message: "Welcome home"
        actions:
          - action: "button1"
            title: "Lights ON"
          - action: "button2"
            title: "Lights OFF"

Thank you for your help, really can’t figure that one out, even if it may seem obvious for some of you!

PatBoud

It needs to be:

- alias: "Notify I am home"
    trigger:
      platform: zone
      event: enter
      zone: zone.home
      entity_id: device_tracker.patboud_nexus5
    action:
      service: notify.html5
      data:
        message: "Welcome home"
        data:
          actions:
            - action: "button1"
              title: "Lights ON"
            - action: "button2"
              title: "Lights OFF"
1 Like

It works! Thank you very much!

Pat

1 Like

I am trying to get my action up and running after this example but nothing happens when I press the button on the phone…
I got no errors in the config.

notify:
  - name: html5
    platform: html5
    gcm_api_key: 'XXX'
    gcm_sender_id: 'XXX'

scene:
  - name: test
    entities:
      light.vardagsrum:
        state: on
        brightness: 255

  - alias: "Test"
    trigger:
      platform: time
      after: "22:20:00"
    condition:
      - condition: time
        weekday:
          - mon
          - tue
          - wed
    action:
      service: notify.html5
      data:
        message: "test"
        data:
          actions:
            - action:
                service: scene.turn_on
                entity_id: scene.test
              title: "Lights ON"
            - action:
                service: scene.turn_off
                entity_id: scene.test
              title: "Lights OFF"

I looks like the format of the config is correct but noting happens…
How can I know it my HA get the info from my phone or is the action wrong?

Can someone point me in the right direction of this one?
I have tried the original setup in this thread now and I can call it and I get 2 buttons. Lights On and Lights Off.

- alias: "Notify I am home"
    trigger:
      platform: zone
      event: enter
      zone: zone.home
      entity_id: device_tracker.patboud_nexus5
    action:
      service: notify.html5
      data:
        message: "Welcome home"
        data:
          actions:
            - action: "button1"
              title: "Lights ON"
            - action: "button2"
              title: "Lights OFF"

But what I don’t understand is the action, is that pointing to an automation or a scene?
I have tried to make a automation alias called button1 and a scene called button2 but nothing works.

I dont need a working config, just a little push in the right direction.

First let me say i didn’t try this or set it up myself. i’m just sending some simple push notification right now.
But as far as i understand it, you need to make another automation with this trigger:

- alias: HTML5 push notification action button clicked
  trigger:
    platform: event
    event_type: html5_notification.clicked
    event_data:
     action: button1

So in this new automation you can setup in the action part what happens when you click button1.
For button2 you need to make another automation and change button1 into button2.
I think this is how it is supposed to work. so you might give it a try.

2 Likes

You are the man!
Thx a lot that works perfect!! :smiley:

Nice that you got it working! I think i will set it up soon too.

Now when that is working i only have the rest left… :smile:
But at least i know that everything is working with the push notification so now can i start working with the real function!

Hehe good luck with it! if you run in some trouble you can always ask. if i can (know enough :grinning:) i will help.

Thank you so much for this clarification. I wasted two hours trying to figure out actionable notifications until I came across your post. I really, really think this should be added to the documentation, which is even more confusing as the examples are written in both JSON and YAML.

1 Like

Sorry to revive something old but this thread has helped me SO much.

My question now is:
Is it possible to have 2 different action buttons for one notification comepared to another notification? Since the action buttons are specified in the particular notification call I wasnt sure if we could use many sets of action buttons.

eg: doorbell notification to have action1= turn light on, action2=TTS call
some is home notification to have action1= unlock door, action2=open garage

can we do that or are we restricted to 2 actions across the entire platform?

Hi i dont have multiple services for one button but have a look at the automation i use to run all buttons. I dont see why you couldn’t add more entities under the entity_id section for each of my sample actions.

https://hastebin.com/oyifimupov.hs

awesome! thanks so much. that certainly answers my question AND helps me create lots of actions in the one automation. much appreciated. cheers!

actually… one hiccup I see for myself trying to use your example. I use the generic media_player.play_pause service to pause whatever is playing in my house if the doorbell is pushed. how could I integrate that into your example given that I dont specify an entity_id?

as a work-around for the time being I have just included multiple entities…

action:
  - service: media_player.media_play_pause
    data_template:
      entity_id: '{% if trigger.event.data.action == "button1" %} media_player.lounge_speakers {% endif %}'
  - service: media_player.media_play_pause
    data_template:
      entity_id: '{% if trigger.event.data.action == "button1" %} media_player.house {% endif %}'

there is probably a much more elegant way of doing it…

was going to suggest that. maybe something like this
https://hastebin.com/bagawugope.hs

I’ll give it a try, thanks

Yes, 2 button is possible.

yeah, Juan’s example in post 12 has worked perfectly to enable much more than 2 options (overall) while still being limited to the 2 buttons per notification