Home » Blog » How to use Actionable Notifications to Alert for Empty Printer Cartridges

How to use Actionable Notifications to Alert for Empty Printer Cartridges

Hi!
Did you know that you can create actionable notifications in Home Assistant? This way you can get a message on your phone and choose some actions within that message. Home Assistant will perform your chosen action after you’ve chosen a specific action. In this video, I’ll show you how you will get a message on your phone when your printer ink cartridges are almost empty and what actions you can perform within that message. Let’s go!


⭐⭐⭐ NOTE: ⭐⭐⭐

This article accompanies a YouTube video. I wrote it for people who would rather read than watch a video. In order to keep doing this, I would like to ask you to also check out the video, leave a comment under the video, give the video a thumbs up and subscribe to my YouTube channel. This means that the video is offered more often to new visitors so that they also stay informed of the latest tutorials about Home Assistant.

Thank you for your support!

Ed

Watch the video here

So, what are actionable notifications?

Actionable notifications are messages that you receive on your phone and that present a couple of actions that you can perform within that message. We will create the following use case in this tutorial. When your printer ink cartridges are almost empty, you will get a message on your phone. Within that message you get three options:

  1. Order new cartridges
  2. Remind me later
  3. and Ignore

For this, we will use the actionable notification functionality of Home Assistant. You can also check the documentation online if you like to know more about this. The link is in the description below. https://companion.home-assistant.io/docs/notifications/actionable-notifications/

After you’ve created the script, automations, and helper for this use case, it will look like this on your phone.

Actionable notifications always work together with automations that handle the actions within the notification. So, if you choose a certain action within a notification, an automation will trigger based on that event and perform the action that you’ve chosen.

For this use case, we are going to create a script, a helper, and three automations. This use case is one example that shows how you can use actionable notifications. You can alter this example to your needs for different use cases of course.

Create the script for our actionable notifications

We start with creating a script. The script sends the actionable notification to your phone. You might wonder why I use a script for this. Well, this is because I want to be able to let Home Assistant remind me using a notification again when I click “Remind” in the actionable notification. So, I can call this script multiple times instead of having to create multiple automations with the same code.

You can create a script by going to Settings > Automations & Scenes. Then go to the Scripts tab and click on Add Script.

The script looks like this:

  • The name is “Notify: Printer Cartridge is almost empty”
  • Within sequence, I’ve added a “call service” action and the service in my case is “Notifications: Send a notification via mobile_app_iphone_x_ed”.
  • The Message is “Your printer cartridges are almost empty”
  • The title is “Printer alert”
  • The actionable part is filled in in the Data field.

What you see here are the actions that will be shown below the message on your phone. For each action, you can add some parameters. Not all parameters work the same for Android and iPhone. iPhone has some more parameters that you can use. See the documentation of actionable notifications for this. The link is in the description below.

The Actions in our Script

  • We start with actions:
  • Each action has an identifier. In our case, these identifiers are ORDER_URI, REMIND and IGNORE. We will use these three action IDs later as identifiers in automations.
  • The Action ORDER_URI leads us to the URL where I can buy new cartridges for my printer.
  • The title is the “action” message that is shown on my phone. In this case “Order new cartridges now”
  • The icon shows an icon next to the action message. This is only supported on iPhones at this moment. You cannot use mdi: icons like you normally would use in Home Assistant. The icons that you can use here can be found on https://sfsymbols.com/
  • And the URI contains the URL where I can buy my cartridge.

So, when I click on “Order new cartridges now”, I will be led to the URL where I can order the cartridges.

  • The Action REMIND makes sure that I get a reminder later to order the cartridges.
  • This action also has a title and an icon

So, when I click “Remind me later”, I will get a reminder every day at 12 PM that my ink cartridges are almost empty. This is handled by an automation that I will show later in this tutorial.

  • The last action is called IGNORE and just ignores the message.
  • This action also has a title and an icon
  • I also added the option destructive: true. because of this option, the message will be shown in RED on iPhones.

So, when I click “Ignore”, the message will be ignored and it will make sure that I won’t get reminders anymore.

You can test the script by clicking on Run Script. The script will just show the message and the options that you can choose, but no actions will be performed yet.

Create the helper for our actionable notifications

To make sure that the reminder action works, we are going to need to create a helper. This helper will store if we want to get a reminder or not. For this, we use the boolean or toggle helper.

You can create a helper by going to Settings > Devices and Services. Then go to the Helpers tab en click Create Helper. Select the type Toggle.
Give the helper the name “printer_ink_reminder” and click Create.

Create an automation that checks if cartridges are below a certain value

Now we are going to create three automations. The first automation checks if the cartridges of our printer are below a certain value. If this is the case, then it will call the script that we’ve just created.

You can create an automation by going to Settings > Automations & Scenes. Then go to the Automations tab and click on Create Automation. After that, click on Start with an empty automation.

Our automation looks like this:

  • The automation has the name “Notify: Printer ink is low”
  • I’ve created two triggers: one for the black and white cartridge and one for the color cartridge.
  • The first trigger is of type Device and the trigger is “Canon MX510 series Black value changes”
  • At “below” I’ve set the value to 20. So, I want to get a message if the cartridge percentage dropped below 20%.
  • I did the same for the color cartridge.
  • Then, at Actions, I will just call the script that we’ve just created. You can do that by selecting the action type “call service” and selecting our created script in the dropdown list that is shown after that.

Create an automation that handles the actions in the automation

So, if the black or color ink cartridge is below 20%, this automation triggers the script and we will get an actionable notification on our phone. However, the actions still do not work. In this next automation, we will bring the actions to life.

Create a new automation by going to Settings > Automations & Scenes. Then go to the Automations tab and click on Create Automation. After that, click on Start with an empty automation.

This new automation looks like this:

  • The name of the automation is “Notify: Handle printer ink notification actions”

The Triggers

  • We are creating three EVENT triggers in this automation:
    • One that triggers when the reminder event is fired
    • One that triggers if the cartridge ordered event is fired
    • and one that triggers when the ignore event is fired.
  • The first trigger is of type EVENT and the event type is “mobile_app_notification_action”
  • We add the action that we defined in our script within the field Event data. In this case that is action: REMIND
  • We give this trigger the Trigger ID “set-reminder”. I’ve created a tutorial about trigger IDs. They are very powerful, so check that tutorial out if you do not know how Trigger IDs work.

So, this trigger triggers based on the action REMIND of the mobile_app_notification_action event. We will create an action later that turns our “printer_ink_reminder” helper on.

  • The second trigger is also of type EVENT and the event type is again “mobile_app_notification_action”
  • In this case the action is: ORDER_URI
  • We give this trigger the Trigger ID “cartridge-ordered”

So, this trigger triggers based on the action ORDER_URI of the mobile_app_notification_action event. We will create an action later that turns our “printer_ink_reminder” helper off. We do not really need any reminder notifications anymore after we’ve ordered new cartridges right?

  • The third trigger is also of type EVENT and the event type is again “mobile_app_notification_action”
  • In this case, the action is: IGNORE
  • We give this trigger the Trigger ID “ignore”

This trigger will also turn the “printer_ink_reminder” helper off.

Profile Picture Ed

If my videos help you and if you want to stay up to date with my tutorials and not miss anything to increase your knowledge of Home Assistant and Smart Home, subscribe to my channel and tick the bell. It also helps if you post a comment. This way more people get notified about these videos. I need your support so that I can keep creating these videos for you.

Oh, and don’t forget to hit the thumbs up for this video. This allows me to make more tutorials for you.

By supporting me, you also support my work as a music therapist to help people with mental issues.

Thank you!

The Actions

Now, let’s set up the actions for this automation.

  • We start with a Choose Action, because we have three different triggers.
  • Within the Choose action we create three options
  • The condition within option 1 is “Triggered By”
  • And the trigger ID is “set-reminder”
  • The action within this option is of type “call service” and the service is Input boolean: Turn On
  • The entity that we want to turn on is our “printer_ink_reminder” helper.
  • The condition within option 2 is also “Triggered By”
  • And the trigger ID is “cartridge-ordered”
  • The action within this option is of type “call service” and the service is Input boolean: Turn Off
  • The entity that we want to turn off is our “printer_ink_reminder” helper.
  • The same count for option 3.
  • The condition within option 3 is also “Triggered By”
  • And the trigger ID is “ignore”
  • The action within this option is of type “call service” and the service is also Input boolean: Turn Off
  • The entity that we want to turn off is our “printer_ink_reminder” helper.

So, basically, this automation turns the “printer_ink_reminder” helper on and off. Now we only have to create one more automation that acts upon the status of the “printer_ink_reminder” helper

Explanation of Events

This might sound like magic to you and I can totally understand that. Home Assistant uses events to trigger actions. So, Home Assistant listens for events and as soon as an event is triggered, it will perform actions. You can check this yourself by going into the Developer Tools and going to Events. On the right side of the screen, you see a list of active listeners. You can fill the Listen to Events field with one of these listeners and see what it returns. In our case that is “mobile_app_notification_action”. If you click on “Start Listening” after that and run the script and select an action in your notification, you will see that it shows the Action. These actions can be intercepted by automations, which is exactly what we are doing here.

Create an automation that reminds the user that the ink cartridges are low.

Now, let’s create our last automation to get everything to work!
Create a new automation by going to Settings > Automations & Scenes. Then go to the Automations tab and click on Create Automation. After that, click on Start with an empty automation.

Our automation is named “Notify: Remind Printer Cartridges almost empty”.

I added a trigger that is of type time and in this example, it will trigger daily at 12 PM.

Now, we only want this automation to trigger when our “printer_ink_reminder” helper is turned on, so we add a condition to check the value of that helper. At Condition, I added a state condition. The entity is the “printer_ink_reminder” helper and the state that we want to check is “On”. So, with this condition, the automation will only trigger if the “printer_ink_reminder” helper’s state is on.

At action, we add a call service action and select the script that we created before. So this automation sends us a reminder to our phone every day at 12 PM.

Download the code used in this video

You can download all the code that I created in this video via the download link in the description below. Downloading is free, but you can also choose to make a donation just before you download the code. Please consider sponsoring me, if my work saves you time. This way you support me so that I can keep making these videos for you.

Download the code here!

And with this, our use case is finished! Let me know in the comments if you managed to get it to work. Do you have other use cases for actionable notifications? Let me know in the comments!

I hope this video helped you and I want to thank everyone who has supported me in making these videos and tutorials so far. I could never have done this without you. Thank you! You can support me through Patreon, Ko-Fi or by joining my channel. If you also want to support me, look in the description of this video for the links. With that, you make it possible that I can continue to make these videos for you.

Oh, don’t forget to give this video a thumbs up, subscribe to my channel, and hit the notification bell.

I will see you soon!

Bye bye!


,

RELATED POSTS

Back to all articles