Android actionable notifications

Hey guys, sorry I didn’t add the “target” attribute to the table in the OP…it’s in there now. All you have to do is add

target: unnamed device_2

to your notification. This goes at the root, along with title and message.

@Shayne_Bergan I handled the timestamps on the Home Assistant side so that I know when the notification was actually called, not when it’s received…though these two time are typically very close. I use

message: "Anna is home at {{ now().strftime('%I:%M %p') }}."

1 Like

@Crewski That worked perfectly, Thanks heaps.

Is it correct to have configuration.yaml set like:

notify:
  - name: android
    platform: fcm-android

and not

notify:
  - platform: fcm-android
    name: android
  1. I copied fcm-android.py to \config\custom_components\notify\fcm-android.py
  2. Installed https://drive.google.com/open?id=17q0VR3T96k0SyQYujfpbNipAI33jdEYZ
  3. Hass is installed on Docker on Synology and I’m using Synologys nginx to make it available to the internet

When trying to send notification like proposed here https://www.home-assistant.io/components/notify.html5/#testing I don’t get anything.

notify.android does not show under services.

What am I missing?

Thanks for your help.
Best regards, Marko

In the settings where you turn on Push Notifications, do you get a toast message that says that you are registered?

After selecting push messages, do you now have a fcm-android-registrations.conf file in your config/ ? And in that file is there at least 1 JSON object with a name and token?

As far as the setup you have it right. I guess I should also mention to reboot after putting the fcm-android in place, but I’m assuming you already did that.

Thanks for quick reply. I did reboot it.

I see that I am missing fcm-android-registrations.conf and I’m failing at getting one…

When using your version of HA app (release 2018-09-11 10:55:25) it crashes when checking or unchecking Settings > Push Notification with error HomeAssist keeps stopping. Tried with local http and external https. Tried with HANotify v1-0-1.apk installed beside and without.

When using HANotify v1-0-1.apk it gives me error Something went wrong. Also tried local http as well as external https.

Hello,
Another android application that have support for HANotify you can find here:

Ionut

1 Like

Sounds like we need to test if the rest api service is exposed through NGINX (which I have no experience with). Only reason I’m thinking this is because the examples show a separate “location” for websockets.

The fcm-android.py exposes 2 endpoints, /api/notify.fcm-android and /api/notify.fcm-android/callback. Using either Postman from a separate computer (I’m guessing) or a Rest Api app on your phone (https://play.google.com/store/apps/details?id=com.sn.restandroid) lets try to hit the first endpoint.

So, send a POST request to https://yourdomain.com:8123/api/notify.fcm-android (make sure /api/notify.fmc-android is all lowercase). Include the header x-ha-access with your api_password. Hit send, what do you get?
If you get a response that says

{
    "message": "Invalid JSON"
}

then there is proper communication and the api service is working. If you get something else (such as a 404 error) then the problem is most likely with the NGINX setup.

1 Like

No success. From API service I get 404 error. It does not matter if request goes to https domain name or local http IP address.

I guess it should work at least on local IP address, bypassing Nginx reverse proxy? Right?

Postman result (domain name):

Postman result (local ip address):

Interest thing is that custom components ggts_token and tts are loaded without issues and are in the same folder as notify.

Result when using custom components for google tts. So other components get loaded.

Can I check any other log files? Can I do some more debugging?

Thanks for assistance.

Hey guys,

So I placed fcm-android.py into /custom_components/notify/ and put in

  • name: android
    platform: fcm-android

under notify in config.yaml

Hassio is giving me this error:

 File "/config/custom_components/notify/fcm-android.py", line 9
<!DOCTYPE html>
^

SyntaxError: invalid syntax

and the Hanotify app is saying “something went wrong”

you copied it wrong from the repo. make sure you click the Raw button before you copy and paste

2 Likes

Thanks @atomicpapa
It’s working great now.

Can someone please tell me how I can send custom actions clicked “fcm_android_notifications.clicked” from tasker using the same token and then building automations around that in HA?

Basically just like the action that pressing on the button on the notification does but a custom one

I hope this makes sense

You just need to send a POST request to https://yourhaurl.com:8123/api/notify.fcm-android/callback. In the header you need x-ha-access: yourapipassword. The body needs to be a json with:

action: whatever you want the action to be
type: clicked
token: the token for the device. You can get this from the fcm_android_registrstions.conf.

The code from the app that does this is:

val dataJSON = JSONObject()
    dataJSON.put("action", action)
    dataJSON.put("type", "clicked")
    dataJSON.put("token", FirebaseInstanceId.getInstance().token)
1 Like

Thanks so much for making this @Crewski! Beautiful functionality that has me re-thinking my whole setup to see how I can integrate it.

Just one question: is there a way to make the notifications pop up like a regular notification instead of just appearing in the status bar?

EDIT: actually, one more question: can it be set up so the notification is automatically dismissed after x seconds?

@Crewski
Thank you, but I’m not understanding it clearly.

Looking at the http post task in tasker, I can’t see where I could put the json code you provided.

I’m also not clear on “the header”

I’d you do use tasker, I’d really appreciate it if you can tell what goes in which specific fields?
Thanks you

@poebae

1st question, you can press and hold on the notification then press on “details” there you can elevate the “importance” of this notification

2nd question, you’ll probably need tasker and autonotifications for that (afaik)

Hmm, the only options I see are

“Show notifications” (enabled)
“Channel human readable title” (enabled)
“Advanced -> Show notification dot” (enabled)

(Google Pixel on Android Pie)

Sorry, forgot to mention that I’m on Android Oreo, you might not have it in your rom version?

Try clicking on the “Channel human readable title” text itself, sometimes you have other settings inside

1 Like

You legend! You were exactly right, tapping on it gave me the option to change the behaviour to “Make sound and pop up on screen”.

Thanks a lot :slight_smile:

Thanks. Did the trick for me. Clumsy me. :upside_down_face:

For dismissing, you can use the “dismiss” function of HANotify. In order to use it, you have to use “tag” as well. So basically you would just make an automation that sends one with tag of “dismissthis” (or whatever you want). Then add a delay for X seconds. The next action will have the same tag but with “dismiss” as true. Let me know if that makes sense.

I haven’t used tasker in a long time. A quick search found that you can’t add the headers in the tasker app alone. But if you install RESTask it looks like it handles it. The JSON with the action, type, and token are put into the body. Hopefully that’ll get you going in the right direction.