Page 1 of 1

Getting Google Cloud Notifications to Work on 4.10717

Posted: Thursday 28 November 2019 22:50
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.

Re: Getting Google Cloud Notifications to Work on Stable

Posted: Sunday 08 December 2019 23:13
by ihpoznan
Good job, thanks.

Re: Getting Google Cloud Notifications to Work on Stable

Posted: Monday 09 December 2019 0:45
by Geitje
Finally someone who gives a hug to these stable-users! 8-)

Re: Getting Google Cloud Notifications to Work on Stable

Posted: Sunday 15 December 2019 21:35
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.

Re: Getting Google Cloud Notifications to Work on Stable

Posted: Tuesday 25 February 2020 16:17
by Nadhyr
THANKS !!!!

Re: Getting Google Cloud Notifications to Work on Stable

Posted: Sunday 15 March 2020 11:20
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 4166 times

Re: Getting Google Cloud Notifications to Work on Stable

Posted: Friday 27 March 2020 20:05
by Ittiz
Looks like you're missing the "8" at the end of the authorization key.

Re: Getting Google Cloud Notifications to Work on Stable

Posted: Monday 30 March 2020 19:05
by Roozen
Thanks for your reply.
Today I updated to version 2020.1 and the notification works via gcn

Re: Getting Google Cloud Notifications to Work on 4.10717

Posted: Thursday 26 August 2021 12:46
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"}'