Custom android notification

Hi guys!

I’ve looked at the notification components that are integrated at the moment (thanks for the good work!)

But I didnt find any that fit my needs (some possibilities cost, some have restrictions). What i do like is the html5 notification. The downsite of it is, that you need to open HA to the web, what i currently dont want.

So i made a custom solution with:

  1. a simple android app, which just works as a background service
  2. google firebase service as message server (same like the html5 component)
  3. a simple service in python to call from HA

That is my first Android app and most credit goes to a tutorial on github. I would like to advance it, so i have a log of the notifications in the frontend of the app

Here is a example of the result:

image

by calling my service with

{
"title": "Its raining .. water",
"message": "But your front window is open",
"type": "warning"
}

or in automation

- alias: Test Notify
  trigger:
    platform: state
    entity_id: input_boolean.notify_home
  action:
    - service: notify.android
      data:
        message: "But your front window is open"
        title: "Its raining .. water"
        type: "warning"

So i just wanted to share this with you guys, maybe someone is interested

Sadly its not possible for other ppl to use this out of the box (the google-service.json is compiled in the app). With a little help of a good android programmer it might be possible :slight_smile:

8 Likes

Looks good. I’m wanting to use FCM as I find the HTML5 notifications are a bit unreliable and late. Can you please tell me how to set up the notify.android service?

@Alexxander0 can u share more detailss?

Wow! Nice Work! Have you tried setting up Actionable Notifications also?

Should open source it :wink:

2 Likes

Hi,

yeah i’ll upload the source code of the android app and the script of the HA.
Actionable Notifications are not possible yet and my skills are not good enough to make this happen.

Problem is if you want to use this app, you have to compile it with the Android Studio for your smartphone, because the firebase file with the credentials is compiled in the app. This might, depending on your android version, be a problem in case of the Android API version. Then you have to move the app to your smartphone

If someone can help to make a login process to login to the firebase (the google-services.json file), that would be good

1 Like

Here it is: https://github.com/Alexxander0/homeassistant_android_notification. Feel free to help or ask questions

2 Likes

Thanks for sharing your code. It gave me a little inspiration to see what I can come up with. Right now I’m using the legacy FCM http protocol where I just supply it the projectid and key instead of the oauth stuff. In the configuration.yaml file the user creates a unique id that is used as the topic for FCM. Then in the automation the user will supply the information (title, message, color, ACTIONS!, sensor). The actions would be received back via the http sensor. Automations would be triggered by the sensor changing states. I’ll post some more about it when I have a few more things buttoned up, but to give you an idea…sending the data through my custom_component fcm_android.py as:

{ 
 "to": "/topics/debug",
 "data" : {
	"body" : "The garage door is OPEN",
	"title" : "Garage Door",
	"color": "#ff00ff",
	"sensor": "fcm_responsp",
	"actions": [
			{ 
				"state": "ignore",
				"action": "Ignore"
			},
			{
				"state": "close",
				"action": "Close it"
			}
		]
	}
}

It’ll show up as a notification looking like:

Clicking on “CLOSE IT” will change the state of sensor.fcm_responsp to “close”

Untitled1

3 Likes

@Crewski Great job with Actionable Notifications!
I’m wondering here if there is any chance that these two projects could work together?


It is a great App for mobile frontend. It would be even better if it has notification support also.
Unfortunately the developer hasn’t shown any activity recently. I hope that app and Android notifications get more attention, as it is a much needed feature. iOS does that already for some time.

Speaking of development, as I understand there should be some sort of login process to login to Google firebase.
Maybe someone has more knowledge how to do it, so notifications could be used more easily?

Integration should be pretty easy. I’ve been super busy lately and haven’t had any time to develop it further. I do realize that having an http sensor probably isn’t the best approach…turns out you can just trigger automations from the REST API.

I do think a login to Firebase would be the best way to go, I’ll look into it at well. Just need to make sure I stay in the free realm!

@franzuu Whats the benefit from this App compared to the normal frontend? You still have to open your HA to the internet, dont you?

I added some methods to the project. Its now possible to control wlan/bluetooth/audio and start apps. Iam using it to mute, stop wlan after gone to work. Or when leaving home start bluetooth and spotify to connect to my car.

Will share code soon. If i got more time, gonna have a look into login for firebase

@Alexxander0 I’m using the Android App mainly because of widget support. I can quickly toggle grass water pump from home screen, without opening the App. Secondly you can customize the frontend however you like in the app (rearrenge tiles, disable some switches etc). About port forwarding, I’m using HA locally atm, because I have a closed port network provider.

I feel like the Android App (both of the ones I’ve come across that use websockets) is quicker to load.

I’ve made some significant changes to how I handled this and will be posting my custom component and app soon (in a different thread as to not confuse or take away from Alexxanders0’s great work). I emulated the HTML5 notifications so no Firebase logins are needed.

1 Like

Have you tried using Automate app for Android ?

I’m currently working on a solution that will included all the properties listed and will not require HA being opened to the web.
The parts are:

  1. Automate workflow that handle various types of messages via GCM (Cloud Message).
  2. Some sort of MQTT like response delivery. I’ve opted for Google Cloud Functions for Phone->Cloud and Google Cloud Pubsub for Cloud -> Home (I work for Google so I already know the products).
  3. Component hosted at home that listens on messages from (2).
  4. Component hosted at home that implements persistency of notifications, acknowledgements or responses.

I’ve already implemented 1-3 and it works for GPS tracking (i.e. I’m polling GPS from home) and simple notifications and alarms.
I’m working on 4 using Appdaemon.

2 Likes

Awesome! I use Notifications for Android TV / FireTV for my Android box, but was too lazy to configure my Tasker app for interacting with Hass on my phone.
I’ll check it out! Thxalot!

Can you share this when you have it finished?

Yes. I will share it with relevent instruction on how to set this up.
The notification piece has been working reliably for me for few weeks already, however I’ve integrated few more features into it like GPS polling and home presence detection. Once finished and battle tested I will share the entire project.

2 Likes