Push Notification with Pushbullet

Loading

When there is a problem, there is a solution.

What is the problem?

We’ve been experiencing intermittent slow down which download speed just goes up and down unexpectedly.  I already have internet speed test scheduled on my Home Assistant (HA) every 15 minutes, but what I would really like to do next is to get push notification when it happens, when internet speed is below certain threshold.

As you can see below, here are my internet speed as visualized in a graph, not very steady at all. Next with the help of HA automation and notification, I’ll have lots of information right at my fingertip, hopefully to negotiate with the internet provider’s customer service.

What’s the solution?

As a follow up to my last article on “Home Assistant – Open Source Home Automation Platform”, I’m excited to share with you that I was able to leverage the notification features in HA to provide an elegant solution to this problem.

The notification services in HA is called “Automation”.  There are quite a few of integration platform already available for you to pick and choose from, all you will need to do is to decide which one you would like to use and do some configuration.

Let’s get started?

Let me show you a working example of how to configure HA to do exactly what I need, notify me when my internet speed is slow.

There are a few ways to do the configuration, but as a techie, I prefer to edit the configuration files directly.  The configuraton.yaml file contains all the HA configuration, and automations.yaml is an extension with all the automation definition.

Here is how you will configure an automation when internet speed is slow. I named it “Super Slow Internet Speed”, and it is triggered when download speed is below 50 Mbps.

- id: '1530313819030'
  alias: Super Slow Internet Speed
  trigger:
  - below: '50'
    entity_id: sensor.speedtest_download
    platform: numeric_state
  condition: []

Next you will need to define some action which tells HA what to to do when it happens.  A simple action can be to create a notification box on HA web console to highlight this event, using a persistent notification service.

  action:
  - service: persistent_notification.create
    data:
      title: 'Internet Status'
      message: '**Super Slow** Download speed'

This is really cool and a small notification box is displayed on the web console.  Although I find the notification box somewhat lacking as it does not tell me when this event happened and what the speed was at that time.

I need a better solution.

After some research I find that I can format the message with lots of dynamic information, it may look a bit cryptic to you now, but this will show a timestamp and the actual speed that triggered this event.  I also added a notification_id, this way it will rewrite the same notification box instead of creating a new box each time.

  action:
  - service: persistent_notification.create
    data:
      notification_id: '1000'
      title: 'Internet Status'
      message: '{{now().strftime("%b %d, %Y %I:%M%p")}} **Super Slow** Download speed is {{states.sensor.speedtest_download.state}} Mbit/s'

Here is what the notification box looks like now, much better:

Now I’m still unhappy, as this will require me to go to the web console to find out, it is more of a pull method.  So my next challenge is: how can I get a push notification to my cell phone so that I will be alerted?

I need a even better solution.

I was very happy to find that HA already have a few push notification platform integrated and available. The one I tested is Pushbullet, for more details, here is a link to Pushbullet’s website.  Pushbullet is free for the basic service, you will need to sign up for an account, and you will get an api_key.  In HA, a notify section need to be created in the configuration.yaml file with the provided API key:

notify:
  - name: mypushbullet
    platform: pushbullet
    api_key: <YOUR API KEY>

Once that is setup, I created 2 actions when slow internet is detected:

  1. Send a message via Pushbullet to my phone.
  2. Display the notification on the web console.

This way, I will be notified on my phone when it happens, and I will also see it on the web console.

Here is the example for the automation configuration:

- id: '1530313819040'
  alias: Super Slow Internet Speed
  trigger:
  - below: '50'
    entity_id: sensor.speedtest_download
    platform: numeric_state
  condition: []
  action:
  - service: notify.mypushbullet
    data:
      message: '{{now().strftime("%b %d, %Y %I:%M%p")}} **Super Slow** Download speed is {{states.sensor.speedtest_download.state}} Mbit/s'
  - service: persistent_notification.create
    data:
      notification_id: '1000'
      title: 'Internet Status'
      message: '{{now().strftime("%b %d, %Y %I:%M%p")}} **Super Slow** Download speed is {{states.sensor.speedtest_download.state}} Mbit/s'

To receive the notification messages:

For your phone and other devices, you will need to download the Pushbullet app. Once you have it setup, you will get all the notification messages.  Here is a sample screenshot:

Some of you may have noticed that the screenshot shows other internet speed messages, just for the fun of it, my setup will detect super slow speed, slow speed, normal speed, and super fast speed.  In addition, as it is hard to wait for the actual event to happen, there is a feature in HA where you can trigger the event manually, so that you can test the end-to-end notification actions.

Conclusion:

Cool! right? I hope that you will also give this a try.  For your reference, I will provide a copy of this sample configuration.yaml and automation.yaml files in my github repository soon.

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

[…] check out the next article “Home Assistant – Push Notification” to see how to setup and send notification messages to your […]

christian nitescu
5 years ago

Hi,
Interesting how to article. Hassio push notification with Pushbullet. My question is what does id mean: ‘1530313819040’
and the entire file should enter the cofigurations.yaml file or automations.yaml file.
Can you explain litte.
Thank you
Christian

5 years ago

The id is just the unique identifier for the automation within the Home Assistant Automations.Yaml file. It has no special meaning and can be anything just has to be unique.