Taking Home Assistant Notifications to the Next Level with ntfy.sh

Taking Home Assistant Notifications to the Next Level with ntfy.sh

Hey, everyone! Theo here. If you're into Home Automation as much as I am, you know the value of a good notification system. Today, we're talking about spicing up Home Assistant with ntfy.sh notifications. I've moved away from the default Home Assistant notifier for various reasons, and I'm here to show you how you can too.

Why ntfy.sh?

So, why switch? The built-in Home Assistant notifier is alright, but it's not as flexible as I’d like. ntfy.sh offers:

  • Customizable alerts

  • Versatility in backend support

  • Native app support for iOS and Android

It’s geeky, it’s cool, and most importantly, it gives you more control!

Setting Up ntfy.sh the Easy Way

Instead of diving into Python and pip installs, you can use Home Assistant's shell_command to set up ntfy.sh. It's a simple, effective method that gets the job done.

Configuring configuration.yml in Home Assistant

To add ntfy.sh as a shell command, edit your Home Assistant's configuration.yml file like so:

# Adding ntfy as a shell command
shell_command:
  ntfy: >
    curl
    -X POST
    --url 'https://ntfy.sh/{{ topic }}'
    --data '{{ message }}'
    --header 'X-Title: {{ title }}'
    --header 'X-Tags: {{ tags }}'
    --header 'X-Priority: {{ priority }}'
    --header 'X-Delay: {{ delay }}'
    --header 'X-Actions: {{ actions }}'
    --header 'X-Markdown: {{ markdown }}'
    --header 'X-Click: {{ click }}'
    --header 'X-Icon: {{ icon }}'

This part sets up a shell command called ntfy. It uses curl to POST a message to the ntfy.sh service. The syntax allows for an array of customizable fields like title, tags, and even the notification's icon.

Using ntfy.sh in Automation

Now that ntfy.sh is set as a shell command, let’s use it in an automation task:

automation:
  - alias: 'Notify When Door Opens'
    trigger:
      platform: state
      entity_id: binary_sensor.door
      to: 'on'
    action:
      service: shell_command.ntfy
      data:
        topic: 'home'
        message: 'Door Open!'
        title: 'Security Alert'

Breaking it down:

  • alias:: The name of our automation.

  • trigger:: The door sensor going 'on' will trigger this automation.

  • action:: The ntfy shell command is executed here.

  • data:: The message, and title fields specify what the notification will look like and say.

  • topic, yes you also need a topic in the data, but I wanted to clarify that you should pick a unique name for it. Home, is not really unique and I'm guessing more people will use this topic. So every time somebody is sending a notification to home, you will also receive it. So it's best to create a unique one, like the initials of your name hash real topic or something like that. If I would want to have a home topic, I would name it : tvdsluijs_home.

Connecting ntfy.sh App on iOS and Android

For real-time updates, you should install the ntfy.sh mobile app. Once you sign in, you're set to receive your customized notifications. Just connect to your own topic (that is why it should be a unique topic name. And you will receive the notifications on your phone.

Benefits

Switching to ntfy.sh brings:

  • Enhanced control

  • Multi-platform versatility

  • More personalization for your smart home experienceSo there you have it—a fun and simple way to add a layer of sophistication to your Home Assistant notifications with ntfy.sh. Feel free to hit me up in the comments with your thoughts or questions. Keep hacking your home!

Did you find this article valuable?

Support Theo van der Sluijs by becoming a sponsor. Any amount is appreciated!