Actionable Notifications in Home Assistant

The option to have Home Assistant send notification is absolutely amazing all on it's own, but being able to send actionable notifications is just mind blowing to me.  I use these notifications now to remind me when my Office Air Conditioning unit is still running at a certain time in the evening, and I use the actionable part to turn off the AC if needed.   My wife receives a notification if the house alarm hasn't been set by a certain time, and when we are away can call and make sure everyone is okay, and even set the alarm for them.

Today, I'll show you how to setup actionable notifications in home assistant.  While we'll be using my AC Unit setup as our example, just think about the 100s of ways notifications can help you and yours better improve the smart home functionality.

Setup

First, make sure you have devices with the Home Assistant mobile app already connected to your HA install. Make sure the devices have an identification that allows them to be uniquely identified.  

Hint:

On iOS, I go into iOS Settings >> General >> About, and tap the device name (usually just "iPhone" by default), and  I change it to identify who's device its is.  This will help you tremendously if you have multiple iOS users in your household.

In HA itself, make sure that each person has a device assigned to his her User.  Click Configuration in the left menu, then People in the right side / center menu.  Now, click each person, and make sure they have the right device assigned to them.  If not, pick the right device(s) for them from the drop-down menu, then Save.  

If you make these changes, it may help to reboot Home Assistant, so it picks up on these changes.

Setting Up our Notification Automation

Go to Configuration >> Automation, then select to create a new Automation from teh bottom right corner button.  Just screate a new blank automation, and then in the Automation setup form, name it something easy to identify.  I used "Notify - Turn Off AC".

Next, under the Trigger, we'll use a ' Time'.  This isn't required.  You can use any type of trigger needed.  On one of my automations, I use a Button trigger for my father, which sends everyone a notification if he needs some assistance with anything.

We select 'Time', then set 'Fixed Time'.  I set my normal automation to 21:00:00 (9:00 PM).  In the video I used a time much closeer to whene I was recording just so it would trigger quickly.

Next, under conditions (you don't always need a condition), I used 'State', and chose my AC Unit smart plug switch.  I made the condition that the state shoudl be 'on'.   If it's 'off' already, no need to send me a notification about it.

Now, we want to add our Notification action.  From the action section, choose 'Call Service'.  On the next line, enter notify. and look at the options in the menu that comes up.  You should see your device listed specifically, along with any other devices you have setup and assigned to users.  The other options is to enter notify.notify which will send a notification to all devices / users that are setup in your Home Assistant install.

Next, fill in the Message are with the Notification message you want to see, and optionally, the Title sectioni with a simple notification title.

Save your selection, and your automation, and scroll back to the top.  Click the "Run Automation" link to test it and make sure you receive your notification.  

If you did, then excellent! Let's keep going.  If not, double check that you have your users assigned devices, and the the devices are named in a way that makes them unique from each other.  Try rebooting HA if you didn't earlier, or if you make any changes.  Finally, just check your automation, and make sure you didn't make a typo.

Create our Action Button on our Notification

Now that you get your notification, let's create an action button.  Head back down to the Action section, and check the box next to 'Data'.  In the text editor section to the right, enter the following:

actions:
  - action: Turn_Off_AC   # unique identifier for an action when pressed
    title: Turn Off AC Now # What the action button will say.

Feel free to adjust the action: and title: text to suit your automation and notification needs.

At this point, you can run your test again, and then (on iOS) press and hold the notification for a couple of seconds, and your action option should appear below the notification.  You can touch the action option, but at this point it won't actually do anything.  Which brings us to our next step.

Scroll back down to the bottom of our Automation, and add a new Action section.  

Select Wait for trigger from the drop down, then put in a timeout.  I suggest this so you don't hang up your HA install if you miss the notification for some reason.   I set mine to 60 seconds, but feel free to enter the number of seconds that make sense for you.

Next, add a new Trigger, and select 'Event'.  Under "Event Type" enter the text:

ios.notification_action_fired

For android use:

mobile_app_notification_action

Under "Event Data" enter the text

actionName: Turn_Off_AC  <– This needs to match the action: field you entered in the previous Action >> Data section.

Now, you'll create a 3rd new Action below that, and select the action you wnat Home Assistant to take when the Action button is tapped on your device. In my case I wanted the AC Unit to turn off, so I selected 'Device', then my AC Unit from the Device List, and made sure it was set to turn off the device.

Voila!  You now have the tools to setup Actionable Notifications in Home Assistatn. Use it well, and enjoy!