Use ntfy.sh with Home Assistant
2023-02-12
1 minute
Just a quick note if you want to use ntfy.sh with Home Assistant.
Setup
I added the following section to my /config/configuration.yaml
file:
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-Click: {{ click }}'
--header 'X-Icon: {{ icon }}'
Usage
To send send a notification, I use this YAML action in an Automation. It’s not necessary to provide all parameters. I ran with these four. As far as I know: Theoretically only topic
is required by ntfy. But this simple shell_command
action does not check if you set a topic.
service: shell_command.ntfy
alias: Send ntfy.sh
data:
tags: monocle_face
topic: test
title: Waschmaschine
message: Die Waschmaschine ist fertig!
Set default values
If you want to, you can also define default values. For example in this codeblock I’ve set the default topic to “test”. So if I don’t specify a topic when calling the command, it will fallback to test.
shell_command:
ntfy: >
curl
-X POST
--url 'https://ntfy.sh/{{ topic | default("test") }}'
--data '{{ message }}'
--header 'X-Title: {{ title }}'
--header 'X-Tags: {{ tags }}'
--header 'X-Priority: {{ priority }}'
--header 'X-Delay: {{ delay }}'
--header 'X-Actions: {{ actions }}'
--header 'X-Click: {{ click }}'
--header 'X-Icon: {{ icon }}'