Page 1 of 1

FCM (Firebase Cloud Messaging) Notifications on iOS  [Solved]

Posted: Thursday 21 May 2020 19:33
by elzorrovega
Hello All,

Domoticz Version 2020.2 is running on RasberryPI and I have DOMOTICZ iOS app (paid version) running on various iOS devices. I had been playing with a dzVent script to send notification for battery levels and I had managed to get a notification to my iPhone. I tried to repeat the exercise but no luck.

My devices are registered in the mobile device page in Domoticz server. In this same page there is a test button. When I press on this button I get a test notification on the desired iOS device.

I decided to investigate and I saw the JSON command used by the TEST button. I then integrated this command in my dzVent script as follows:

Code: Select all

domoticz.openURL('http://192.168.1.30:8080/json.htm?type=command&param=testnotification&subsystem=fcm&extradata=midx_1')
The testnotification command works and a notification is sent to a specific device.

I looked in the https://www.domoticz.com/wiki/Domoticz_ ... e_readable and I found this entry
You can post a notification to a specific notification system with:

/json.htm?type=command&param=sendnotification&subject=SUBJECT&body=THEBODY&subsystem=SUBSYSTEM
SUBJECT = a string you want to use as subject
THEBODY= a string you want to use as body
SUBSYSTEM= the notification method you want to use
Decided to try the following line in my script:

Code: Select all

domoticz.openURL('http://192.168.1.30:8080/json.htm?type=command&param=sendnotification&subject=THESUBJECT&body=THEBODY&subsystem=fcm&extradata=midx_1')
I tried many variants; I looked in the Forums for examples but I could not find anything close. To my limited understanding it seems that FCM is the newer version of GCM (Google Cloud Messaging), Furthermore, it was recently integrated into the Domoticz Server application.

Here is Log information where I see the testnotification sending fcm with success. One then sees THESUBJECT notification but nothing arrives on the iOS. The catch is how to get sendnotification command to be a little more verbose!

Code: Select all

 2020-05-21 19:22:36.694 Notification sent (fcm) => Success
2020-05-21 19:22:36.702 Active notification Subsystems: browser, email (2/13)
2020-05-21 19:22:36.706 Status: Notification: THESUBJECT
2020-05-21 19:22:38.038 OpenZWave: Domoticz has send a Switch command! NodeID: 2 (0x02)
2020-05-21 19:22:38.041 (Z-Stick Gen5) Usage (Unknown)
2020-05-21 19:22:38.045 (Z-Stick Gen5) General/kWh (kWh Meter)
2020-05-21 19:22:38.061 (Z-Stick Gen5) Light/Switch (Fibaro Wall Plug 1)
2020-05-21 19:22:38.037 Status: User: Admin initiated a switch command (1/Fibaro Wall Plug 1/Off)
2020-05-21 19:22:38.202 Status: dzVents: Info: Handling events for: "Fibaro Wall Plug 1", value: "Off"
2020-05-21 19:22:38.202 Status: dzVents: Info: ------ Start internal script: Swirchoff: Device: "Fibaro Wall Plug 1 (Z-Stick Gen5)", Index: 1
2020-05-21 19:22:38.203 Status: dzVents: Info: ------ Finished Swirchoff 
Does anyone have any suggestions? :?

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Thursday 21 May 2020 20:05
by waaren
elzorrovega wrote: Thursday 21 May 2020 19:33 Does anyone have any suggestions? :?
According the dzVents wiki

notify(subject, message, priority, sound, extra, subsystem): Function. Send a notification (like Prowl). Priority can be like domoticz.PRIORITY_LOW, PRIORITY_MODERATE, PRIORITY_NORMAL, PRIORITY_HIGH, PRIORITY_EMERGENCY. For sound see the SOUND constants below. subsystem can be a table containing one or more notification subsystems. See domoticz.NSS_subsystem types.


Below example should send the message every minute to your mobile. If not check the settings again and look at domoticz logfile.

Code: Select all

return 
{
	on = 
	{
		timer = 
		{
			'every minute',
		},
	},
	
	logging =
	{
        level = domoticz.LOG_DEBUG,
    },

	execute = function(dz)
		dz.notify('from dzVents', 'with love', dz.PRIORITY_NORMAL, '', '', dz.NSS_FIREBASE)
	end
}

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Friday 22 May 2020 0:40
by elzorrovega
Hello Waaren.
Thanks for your reply.
I tried the script you suggested and added the JSON calls: testnotification and sendnotification.
Since I am not reading personal e-mails all the time, I would like to have a discreet notification that informs me that an important event occurs at home.

Please find the script along with log

Results:
  • Notify command ..domoticz.NSS_FIREBASE.midx_1 sends e-mail
    Notify command ..mix_1, domoticz.NSS_FIREBASE.. sends neither e-mail nor notification
    Notify command ..domoticz.NSS_FIREBASE sends neither e-mail nor notification
    JSON command ..testnotification.. sends notification
    JSON command ..sendnotification.. no notification
SCRIPT

Code: Select all

return 
{
    active = true,
	on = 
	{
		timer = 
		{
			'every 05 minutes',
		},
	},
	
	logging =
	{
        level = domoticz.LOG_DEBUG,
        marker = "FCM"
    },

	execute = function(domoticz,timer)
-- Sends e-mail but not notification
--		domoticz.notify('from dzVents', 'with love', domoticz.PRIORITY_NORMAL, '', '', domoticz.NSS_FIREBASE.midx_1)
-- Sends neither e-mail nor notification
		domoticz.notify('from dzVents', 'with love', domoticz.PRIORITY_NORMAL, '', '', domoticz.NSS_FIREBASE)
		domoticz.openURL('http://192.168.1.30:8080/json.htm?type=command&param=testnotification&subsystem=fcm&extradata=midx_1')
		domoticz.openURL('http://192.168.1.30:8080/json.htm?type=command&param=sendnotification&subject=THESUBJECT&body=THEBODY&subsystem=fcm&extradata=midx_1')
    end
}
LOGS

Code: Select all

 2020-05-22 00:10:00.783 Notification sent (fcm) => Success
2020-05-22 00:10:00.789 Active notification Subsystems: browser, email (2/13)
2020-05-22 00:10:00.208 Status: dzVents: Info: FCM: ------ Start internal script: Notify:, trigger: "every 05 minutes"
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: url = http://192.168.1.30:8080/json.htm?type=command&param=testnotification&subsystem=fcm&extradata=midx_1
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: method = GET
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: post data = nil
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: headers = nil
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: callback = nil
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: url = http://192.168.1.30:8080/json.htm?type=command&param=sendnotification&subject=THESUBJECT&body=THEBODY&subsystem=fcm&extradata=midx_1
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: method = GET
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: post data = nil
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: headers = nil
2020-05-22 00:10:00.209 Status: dzVents: Debug: FCM: OpenURL: callback = nil
2020-05-22 00:10:00.210 Status: dzVents: Info: FCM: ------ Finished Notify
2020-05-22 00:10:00.210 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-05-22 00:10:00.238 Status: Notification: from dzVents
2020-05-22 00:10:00.241 Status: Notification: Domoticz test
2020-05-22 00:10:00.792 Status: Notification: THESUBJECT 

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Friday 22 May 2020 10:03
by waaren
elzorrovega wrote: Friday 22 May 2020 0:40 I tried the script you suggested and added the JSON calls: testnotification and sendnotification.
See my remarks and addition in your script. Can you please try this amended script without modification and share the resulting loglines?

I do not follow you with regards to the midx_1. What is it and what do you expect as message ?

Code: Select all

return 
{
    active = true,
	on = 
	{
		timer = 
		{
			'every 05 minutes',
		},
	},
	
	logging =
	{
        level = domoticz.LOG_DEBUG,
        marker = "FCM"
    },

	execute = function(domoticz)
		-- domoticz.notify('from domoticzVents', 'with love', domoticz.PRIORITY_NORMAL, '', '', domoticz.NSS_FIREBASE.midx_1) 
		-- domoticz.NSS_FIREBASE.midx_1 is nil so this should send to all active notification subsystems

		-- domoticz.notify('from domoticzVents', 'with love', domoticz.PRIORITY_NORMAL, '', '', domoticz.NSS_FIREBASE)
		-- This should send to fcm so I wonder what domoticz.NSS_FIREBASE is on your system
		domoticz.log('domoticz.NSS_FIREBASE is defined as ' .. tostring(domoticz.NSS_FIREBASE), domoticz.LOG_DEBUG)
		domoticz.notify('from domoticzVents', 'with love', domoticz.PRIORITY_NORMAL, '', '', 'fcm')
		
    end
}

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Friday 22 May 2020 11:02
by elzorrovega
Hello,

I added a parenthesis at the end of line 24 to close log command.
Otherwise, the script is as you suggested. Please find the logfile .
Neither notifications nor e-mails are sent.

As to midx_1, this is the mobile id given in the mobile device page. Please see attached image of web page. TEST buttons on the same web page will send the JSON command which uses midx_1 as the extradata. Testnotification command uses a different midx_? for each registered mobile device.

The following JSON command will send a Test notification to the first register device mobile device.

Code: Select all

domoticz.openURL('http://192.168.1.30:8080/json.htm?type=command&param=testnotification&subsystem=fcm&extradata=midx_1')
Thus, my interest to send a message to when Alarm is Set; when Alarm is On, etc.

SCRIPT

Code: Select all

return 
{
    active = true,
	on = 
	{
		timer = 
		{
			'every 05 minutes',
		},
	},
	
	logging =
	{
        level = domoticz.LOG_DEBUG,
        marker = "FCM"
    },

	execute = function(domoticz)
		-- domoticz.notify('from domoticzVents', 'with love', domoticz.PRIORITY_NORMAL, '', '', domoticz.NSS_FIREBASE.midx_1) 
		-- domoticz.NSS_FIREBASE.midx_1 is nil so this should send to all active notification subsystems

		-- domoticz.notify('from domoticzVents', 'with love', domoticz.PRIORITY_NORMAL, '', '', domoticz.NSS_FIREBASE)
		-- This should send to fcm so I wonder what domoticz.NSS_FIREBASE is on your system
		domoticz.log('domoticz.NSS_FIREBASE is defined as ' .. tostring(domoticz.NSS_FIREBASE), domoticz.LOG_DEBUG)
		domoticz.notify('from domoticzVents', 'with love', domoticz.PRIORITY_NORMAL, '', '', 'fcm')
		
    end
}
LOG

Code: Select all

 2020-05-22 10:50:00.598 Status: dzVents: Info: FCM: ------ Start internal script: Notify2:, trigger: "every 05 minutes"
2020-05-22 10:50:00.598 Status: dzVents: Debug: FCM: domoticz.NSS_FIREBASE is defined as fcm
2020-05-22 10:50:00.598 Status: dzVents: Info: FCM: ------ Finished Notify2
2020-05-22 10:50:00.599 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-05-22 10:50:00.623 Status: Notification: from domoticzVents
2020-05-22 10:53:13.403 (Z-Stick Gen5) Temp (Hall Temp.)
2020-05-22 10:53:13.442 (Z-Stick Gen5) Lux (Hall Lux)
2020-05-22 10:53:13.517 (Z-Stick Gen5) Light/Switch (Hall Motion Sensor ON)
2020-05-22 10:53:26.119 (Z-Stick Gen5) Temp (Living Temp.)
2020-05-22 10:53:26.159 (Z-Stick Gen5) Lux (Living Lux)
2020-05-22 10:53:26.233 (Z-Stick Gen5) Light/Switch (Living Motion Sensor ON)
2020-05-22 10:55:00.192 Status: dzVents: Info: FCM: ------ Start internal script: Notify2:, trigger: "every 05 minutes"
2020-05-22 10:55:00.192 Status: dzVents: Debug: FCM: domoticz.NSS_FIREBASE is defined as fcm
2020-05-22 10:55:00.192 Status: dzVents: Info: FCM: ------ Finished Notify2
2020-05-22 10:55:00.193 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-05-22 10:55:00.221 Status: Notification: from domoticzVents 
Image

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Friday 22 May 2020 11:22
by waaren
elzorrovega wrote: Friday 22 May 2020 11:02 As to midx_1, this is the mobile id given in the mobile device page. Please see attached image of web page.
Think I understand now.

Can you try this one ?

Code: Select all

return
{
    active = true,
    on =
    {
        timer =
        {
            'every 05 minutes',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = "FCM"
    },

    execute = function(domoticz)
        domoticz.notify('from domoticzVents', 'with love', domoticz.PRIORITY_NORMAL, '', 'midx_1', domoticz.NSS_FIREBASE)
    end
}


Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Friday 22 May 2020 13:00
by elzorrovega
Hello again,

I tried the latest version of the script and there is still neither e-mail nor notification.

One of the stanzas from a Police songs says:
Too much information is going through my head.
Too much information is driving me insane
Overkill ...
As I said previous, It would be cool to have DOMOTICZ issue notification alerts on a smartphone to filter out the "junk" messages be they from professional or personal sources. Getting to the essentials.

Should I try PROWL or Telegram apps to receive notifications?

Please see the screen shot of the test notification which I received from the JSON testnotification command.

Image

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Friday 22 May 2020 15:05
by waaren
elzorrovega wrote: Friday 22 May 2020 13:00 Should I try PROWL or Telegram apps to receive notifications?
Image
Sorry but I cannot replicate this issue. Maybe because I have only one android device connected.
I use gmail, fcm, telegram and pushover for my notifications. No real preference as they all have there pros and cons.

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Friday 22 May 2020 16:28
by waaren
elzorrovega wrote: Friday 22 May 2020 13:00 Should I try PROWL or Telegram apps to receive notifications?
Image
Just tested with an additional Android phone and the syntax with 'midx_' as extra data works as expected in the domoticz.notify
The message only arrives at the mobile with that ID.

Funny thing is that the first mobile phone is midx_3 and the second mobile phone use midx_4 and not midx_1 and midx_2, as I expected.


Code: Select all

return 
{
    active = true,
	on = 
	{
		timer = 
		{
			'every 5 minutes',
		},
	},
	
	logging =
	{
        level = domoticz.LOG_DEBUG,
        marker = "FCM"
    },

	execute = function(domoticz)
		domoticz.notify('from dzVents', 'with love: to first device', domoticz.PRIORITY_NORMAL, '', 'midx_3', domoticz.NSS_FIREBASE) 		
		domoticz.notify('from dzVents', 'with love: to second device', domoticz.PRIORITY_NORMAL, '', 'midx_4', domoticz.NSS_FIREBASE) 		
		domoticz.notify('from dzVents', 'with love: to all devices', domoticz.PRIORITY_NORMAL, '', nil, domoticz.NSS_FIREBASE) 		
    	end
}


Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Friday 22 May 2020 18:42
by elzorrovega
Hello Waaren,

Your last post made me think that there must have been something obvious which I missed.
If it worked for you, my issue was elsewhere.

Sorry for my clumsiness but the Google Cloud Messaging parameter was not enabled.

Because the test button worked in both the Mobile Devices and on Notification Setting pages, I assumed that this parameter should left disabled as per default setting.

I would recommend a cosmetic change to the GUI. Please add FCM Messaging along side the Google Cloud Messaging Title. It would help newbies like me to leave you in peace.

Now that the Notifications page is set. I am getting a James Bond message on the phone and a Zorro message on the Pad.

Thanks a lot for your patience and sorry for the blooper. :D :D :D

En Garde!

Image

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Sunday 24 May 2020 19:19
by elzorrovega
Hello,

If a solution is of interest to you. Please follow link below.

https://www.domoticz.com/forum/viewtopi ... 09#p248538

ElZorroVega :D

Re: FCM (Firebase Cloud Messaging) Notifications on iOS

Posted: Saturday 06 November 2021 14:43
by user4563
Thank you all.. I was looking for a solution to isolate FCM messages per device and came across this. Works like a charm!