Skip to content

Home Assistant Service Notification Support Added #1294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

caronc
Copy link
Owner

@caronc caronc commented Feb 21, 2025

Description:

Related issue (if applicable): #1235

Addition of the following accepted Home Assistant URLs (allowing direct service notifications - to those that support it):

  • {schema}://{host}/{accesstoken}/{target}
  • {schema}://{host}:{port}/{accesstoken}/{target}
  • {schema}://{user}@{host}/{accesstoken}/{target}
  • {schema}://{user}@{host}:{port}/{accesstoken}/{target}
  • {schema}://{user}:{password}@{host}/{accesstoken}/{target}
  • {schema}://{user}:{password}@{host}:{port}/{accesstoken}/{target}

A target follows the following set of logic:

  • service
    • default domain is always 'notify' if one isn't detected
  • service:target
  • service:target1,target2,target3
  • domain.service
  • domain.service:target
  • domain.service:target1,target2,target3
    • targets can be comma/space separated if more hten one

You can specify more then one target by just separating it with a / (slash) on the URL... i.e:

  • hassio://hostname/long.lived.token/my_subsystem/my_subsystem2:targetA

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • No lint errors (use flake8)
  • 100% test coverage

Testing

Anyone can help test this source code as follows:

# Create a virtual environment to work in as follows:
python3 -m venv apprise

# Change into our new directory
cd apprise

# Activate our virtual environment
source bin/activate

# Install the branch
pip install git+https://github.com/caronc/apprise.git@1235-hassio-notify-services

# Test out the changes with the following command:
apprise -t "Test Title" -b "Test Message" \
  'hassio://host/long-lived-token/service'

@caronc caronc linked an issue Feb 21, 2025 that may be closed by this pull request
Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.37%. Comparing base (0553bf7) to head (5d835e0).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1294   +/-   ##
=======================================
  Coverage   99.36%   99.37%           
=======================================
  Files         159      159           
  Lines       20724    20813   +89     
  Branches     3725     3751   +26     
=======================================
+ Hits        20593    20682   +89     
  Misses        121      121           
  Partials       10       10           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@svenjochems
Copy link

svenjochems commented Apr 22, 2025

Hi,
I tried testing this branch but was unsuccessful.

Persistent notifications with the original url still works as expected.
Calling a different service fails with Bad Request - Unsupported Parameters., error=400, not sure if I am passing the service incorrectly.

root@7f43bf5a3b5e:/# apprise -vvv -t "Test Title" -b "Test Message" 'hassio://ha.lan/<token>/notify.mobile_app_gsm_sven'
2025-04-22 20:01:59,216 - DEBUG - Could not load translation path: /usr/local/lib/python3.13/site-packages/apprise/i18n/en
2025-04-22 20:01:59,801 - DEBUG - Notification Plugin 110(s) and 157 Schema(s) loaded in 0.5742s
2025-04-22 20:01:59,803 - DEBUG - Loaded HomeAssistant URL: hassio://ha.lan/x...x/notify.mobile_app_gsm_sven?batch=no&format=text&overflow=upstream
2025-04-22 20:01:59,804 - DEBUG - Home Assistant POST URL: http://ha.lan:8123/api/services/notify/mobile_app_gsm_sven (cert_verify=True)
2025-04-22 20:01:59,805 - DEBUG - Home Assistant Payload: {'title': 'Test Title', 'message': 'Test Message', 'notification_id': 'f07e49aa-920a-47a8-a4b0-63689d42056d'}
2025-04-22 20:01:59,824 - WARNING - Failed to send Home Assistant notification: Bad Request - Unsupported Parameters., error=400.
2025-04-22 20:01:59,824 - DEBUG - Response Details:
b'400: Bad Request'

Edit: I think the parameter notification_id may not be supported by other notification services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom notifications with Home Assistant
2 participants