Hello,
Just a small post to share my configuration to use ntfy.sh with home assistant and action on notification.
In shell_command :
ntfy: >
curl
-X POST
--url 'https://USERNAME:PASSWORDM@URL_NTFY/{{ topic | default("maison") }}'
--data "{{ message }}"
--header 'X-Title: {{ title }}'
--header 'X-Tags: {{ tags | default("") }}'
--header 'X-Priority: {{ priority | default("default") }}'
--header 'X-Actions: {{ actions | default("") | replace("%ha%","URL_HA/api/events/ntfy,method=POST,headers.Authorization=Bearer LONG_LIFE_TOKEN") }}'
--header 'X-Click: {{ click | default("") }}'
--header 'X-Icon: {{ icon | default("") }}'
Don’t forget to replace :
-
USERNAME
: username for ntfy.sh -
PASSWORD
: password for ntfy.sh -
URL_NTFY
: url of your ntfy.sh -
URL_HA
: url of your HA -
LONG_LIFE_TOKEN
: HA long token (on your profils page)
After that you can use action in automation like that :
alias: ask test
description: ""
trigger: []
condition: []
action:
- variables:
action_open: "{{ 'OPEN_' ~ context.id }}"
action_close: "{{ 'CLOSE_' ~ context.id }}"
- service: shell_command.ntfy
data:
topic: loic
title: coucou
message: The blinds are half-open. Do you want to adjust this?
actions: >-
http,Open,%ha%,body={"action":"{{action_open}}"};
http,Close,%ha%,body={"action":"{{action_close}}"};
- wait_for_trigger:
- platform: event
event_type: ntfy
event_data:
action: "{{ action_open }}"
- platform: event
event_type: ntfy
event_data:
action: "{{ action_close }}"
- choose:
- conditions: "{{ wait.trigger.event.data.action == action_open }}"
sequence:
- service: cover.open_cover
target:
entity_id: cover.some_cover
data: {}
- conditions: "{{ wait.trigger.event.data.action == action_close }}"
sequence:
- service: cover.close_cover
target:
entity_id: cover.some_cover
data: {}
mode: single
I hope it’s can help user to use action with ntfy.sh.