Getting Google Cloud Notifications to Work on 4.10717

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

Post Reply
Ittiz
Posts: 47
Joined: Tuesday 03 January 2017 0:37
Target OS: Linux
Domoticz version: 13939
Location: USA
Contact:

Getting Google Cloud Notifications to Work on 4.10717

Post by Ittiz »

Many of us who can't use the beta version have noticed that phone app notifications have stopped working in the current Stable version (4.10717). It's due to a change in Google's notification API and not an issue with Domoticz. If you have a large z-wave network like I do then you can't upgrade to the beta to fix the issue. However there IS a way to get it working.

I took a look at Google's new API and found a way to restore phone notifications using Custom HTTP/Action notifications. So this will work as long as you're not already using that feature. There are a couple other caveats. You'll need an SQLite database viewer. Also if you use Android and iPhones together you either need to only use Android notifications, or there will be some limitations with the android notifications. Which I'll touch on later.

My goal was to create a Custom HTTP/Action that would mimic the one that's generated by Domoticz but connects to the new API used by Google. To that end I looked in the newest beta version of Domoticz's source code on Github to figure out how it currently interfaces with Google. I then created an Custom HTTP/Action to mimic that request.

The first thing you need to do is open up the Notification settings in your Domoticz instance. Scroll down to the Custom HTTP/Action box. Then you need to get your phone's unique registration ID for the domoticz app. You're not able to find this information anywhere inside Domoticz because if someone gets the ID they can spam your phone with notifications. You can only find this inside the database. The database is in the Domoticz folder and it's called domoticz.db.

You'll need to open the database file using an SQLite viewer and view the MobileDevices table. In the MobileDevices table the field that contains your phone's unique ID is the SenderID. You DON'T need the UUID field. Now for every phone you want to receive notifications copy the SenderID for that phone from the database into the TO field in the Custom HTTP/Action box in Domoticz. You'll need to surround every ID with double quotes (") and separate them with a comma followed by a space (, ). It should look like this:

Code: Select all

"PhoneID-1", "PhoneID-2", "PhoneID-3"
If you have both Android and iPhones you'll need to type "default" into the FIELD#1 field for your Android to make a sound when a Domoticz notification arrives. If you only have iPhones you can change this from "default" to other sound options available from Apple. If you only have Androids you can leave this field blank as the app will control what notification sound is used.

The next thing you'll need is to copy and paste the following URL into the URL/Action field: https://fcm.googleapis.com/fcm/send That is the new URL for Google's notification API.

For people WITH iPhones you need to copy and paste the following JSON packet into the POST Data field. This is what tells the Google API the contents of the notification. Note: If you want to use both Android and iPhones together you need to use this code. The issue is the Domoticz notifications on Android will only be able to use the default notification sound.

Code: Select all

{"registration_ids": [#TO], "notification" : {"subject": "#SUBJECT", "body": "#MESSAGE", "sound": "#FIELD1", "extradata": " ", "priority": "#PRIORITY", "deviceid": "0", "message": "#SUBJECT", "content_available": true } }
For people who only want notifications to go to Android phones copy and paste the following JSON packet into the POST Data field. Note: If you want an iPhone to receive notifications DON'T use this JSON packet use the one above instead!

Code: Select all

{"registration_ids": [#TO], "data" : {"subject": "#SUBJECT", "body": "#MESSAGE", "extradata": " ", "priority": "#PRIORITY", "deviceid": "0", "message": "#SUBJECT", "content_available": true } }
Moving along you need to copy and paste application/json into the POST Content-Type field. This tells Google you're transferring the info via JSON.

Lastly you'll need to copy and paste Authorization: key=AIzaSyBnRMroiDaXCKbwPeOmoxkNiQfjWkGMre8 into the POST Headers field. This is Domoticz's unique app key and it tells Google it's a Domoticz notification.

Now save your settings and then click the test button in the Custom HTTP/Action box. If you did everything correctly and all goes well you should receive a notification on your phone from Domoticz.

Finally you'll need to go and check that HTTP notifications are turned on for all you're devices. I recommend leaving the GCM notifications on for all your devices, but just disable GCM from the notifications tab in the settings. That way when you can finally upgrade Domoticz to a later version all you have to do is enable GCM and disable the HTTP notifications in the settings screen. If you forget to disable HTTP notifications then you'll receive two notifications at once instead of one.
Last edited by Ittiz on Sunday 27 December 2020 2:23, edited 1 time in total.
ihpoznan
Posts: 1
Joined: Wednesday 08 August 2018 20:33
Target OS: -
Domoticz version:
Contact:

Re: Getting Google Cloud Notifications to Work on Stable

Post by ihpoznan »

Good job, thanks.
Geitje
Posts: 170
Joined: Monday 22 January 2018 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Getting Google Cloud Notifications to Work on Stable

Post by Geitje »

Finally someone who gives a hug to these stable-users! 8-)
Domoticz beta, on Raspberry Pi 3B, Raspian Buster
Zwave, Zigate, RFlink etc.
Ittiz
Posts: 47
Joined: Tuesday 03 January 2017 0:37
Target OS: Linux
Domoticz version: 13939
Location: USA
Contact:

Re: Getting Google Cloud Notifications to Work on Stable

Post by Ittiz »

No problem. There is a way to get iPhones and Android devices working normally together, but it's more complicated and involves adding a dummy device and LUA scripting on top of the HTTP notifications.
Nadhyr
Posts: 14
Joined: Wednesday 29 April 2015 13:28
Target OS: Windows
Domoticz version: 2.2859
Location: FRANCE
Contact:

Re: Getting Google Cloud Notifications to Work on Stable

Post by Nadhyr »

THANKS !!!!
Domoticz Version: 4.10717
Synology 216 + II ( 1,6ghz 8GB )
Zwave - RF Link
Roozen
Posts: 8
Joined: Monday 23 December 2019 17:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Kerkrade, Netherlands
Contact:

Re: Getting Google Cloud Notifications to Work on Stable

Post by Roozen »

@Ittiz,
Thanks for your clear explanation.
Unfortunally I can not get it work.

Below what I filled-in for notifications to one android device with domoticz lite.
The log file does not give any error, but no notification arrived to mobile phone

Log:
2020-03-15 13:14:07.888 Status: Notification: Domoticz test
2020-03-15 13:14:08.168 Notification sent (http) => Success
Any idea what I am doing wrong?
Screenshot.png
Screenshot.png (25.02 KiB) Viewed 4146 times
Ittiz
Posts: 47
Joined: Tuesday 03 January 2017 0:37
Target OS: Linux
Domoticz version: 13939
Location: USA
Contact:

Re: Getting Google Cloud Notifications to Work on Stable

Post by Ittiz »

Looks like you're missing the "8" at the end of the authorization key.
Roozen
Posts: 8
Joined: Monday 23 December 2019 17:53
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Kerkrade, Netherlands
Contact:

Re: Getting Google Cloud Notifications to Work on Stable

Post by Roozen »

Thanks for your reply.
Today I updated to version 2020.1 and the notification works via gcn
Tmaster2018
Posts: 6
Joined: Sunday 11 March 2018 11:52
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Portugal
Contact:

Re: Getting Google Cloud Notifications to Work on 4.10717

Post by Tmaster2018 »

Ittiz thank you .that tuturial save my day. my sd card corrupt and i had to restore an 2018 sd clone ,and like you ,because zwave and some issues on on/off script run ,i cannot upgrade from 4.9700.

using you help, i used this curl comand that i found online and it worked like an script on domoticz activation"on action" .

Code: Select all

curl -X POST --header "Authorization:key=AIzaSyBnRMroiDaXCKbwPeOmoxkNiQfjWkGMre8" --header "Content-Type:application/json" https://fcm.googleapis.com/fcm/send -d '{"to": " MYPHONEID_FROM_DATABASE_BLABLA_replacethis ", "notification": {"body": "Yellow"},"priority": "high"}'
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest