Multiple SendNotification Topic is solved

Moderator: leecollings

Post Reply
User avatar
Plaagje
Posts: 42
Joined: Thursday 30 April 2015 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Netherlands
Contact:

Multiple SendNotification

Post by Plaagje »

Could someone explain why is only the second (message 2) notification is send, and how i should code it to get both messages send??

Code: Select all

commandArray = {}
if (devicechanged['MyDeviceName'] == 'On') then
	commandArray['SendNotification']='message 1'
	commandArray['SendNotification']='message 2'
end
return commandArray
-Plaagje
User avatar
Siewert308SW
Posts: 290
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Multiple SendNotification

Post by Siewert308SW »

That's because while Domoticz is trying to sent the first mail it doesn't see the second sendmail command as it's busy and fails on that.
You could use a function script for that.
It's a simple Lua function which i use in my fire alarm script to set multiple mails when my alarm is triggered.

Code: Select all

function mail(subject, body, address)
		commandArray[#commandArray+1]={["SendEmail"]=subject.."#"..body.."#"..address }
end
call it with:

Code: Select all

if devicechanged['Dummy'] == 'On' then
	mail('Domoticz mail', 'This is a sample body text', '[email protected]')
        mail('Domoticz mail', 'This is a sample body text', '[email protected]')
        mail('Domoticz mail', 'This is a sample body text', '[email protected]')
end
p.s
Functions i keep in a function library lua file.
And call that library each time i need a function, that way i don't need to write all function in each lua script.
Last edited by Siewert308SW on Sunday 09 April 2017 0:24, edited 1 time in total.
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
User avatar
Plaagje
Posts: 42
Joined: Thursday 30 April 2015 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Netherlands
Contact:

Re: Multiple SendNotification

Post by Plaagje »

I'm using telegram as a notification service, so it seems to me it should be "instant".

You mention that the first message is sent and therefore it skips the second message.. but i experience the other way around.
Only the second message is send...
User avatar
Siewert308SW
Posts: 290
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Multiple SendNotification

Post by Siewert308SW »

Plaagje wrote:I'm using telegram as a notification service, so it seems to me it should be "instant".

You mention that the first message is sent and therefore it skips the second message.. but i experience the other way around.
Only the second message is send...
Don't know about telegram but could be the same principal.
Same behaviour i see when you call devicechanged to print in Lua.
It's doesn't show the chronological order but spitting out the printed as it suites Domoticz.
Doesn't bother me though.

As for the function.
Replace "SendEmail" with "SendNotification" and it should work.
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Multiple SendNotification

Post by G3rard »

Check this text from https://www.domoticz.com/wiki/Events.

The commandArray also supports nested tables to send the same command type multiple times. To do this, give the command a numeric index (not alphanumeric with or without quotes!) and place the required action in a nested table:

Code: Select all

 commandArray = {}
 commandArray[1]={['OpenURL']='www.cam1.com/api/movecamtopreset.cgi' }
 commandArray[2]={['OpenURL']='www.cam2.com/api/movecamtopreset.cgi' }
 commandArray[3]={['OpenURL']='www.cam3.com/api/movecamtopreset.cgi' }
 return commandArray
Not using Domoticz anymore
asjmcguire
Posts: 71
Joined: Saturday 13 July 2013 2:45
Target OS: Linux
Domoticz version: 3.5877
Location: Scotland
Contact:

Re: Multiple SendNotification

Post by asjmcguire »

The correct answer is the one posted by G3rard - and the reason is simple.
The CommandArray is not processed until it had been returned by the script.

So what you are doing is saying - hey CommandArray when you get returned from this script, I want you to send this notification. The next line is you saying - actually, forget that - overwrite my previous instruction about sending a notification - with this new one, send this notification instead.

Think of it like ordering in a restaurant - the waiter (CommandArray) comes and asks you what you want - you tell him Chicken. Then you change your mind and say Lasagna. Once the waiter leaves the table and passes the order to the kitchen, that's when the instruction gets processed.

By providing the instructions in an array instead, you are saying to the waiter I want [0] this and [1] this and [2] this.

For future reference you should remember this as all programming languages work this way. If you say:

electricUse = value / 1000
electricUse = "kW"
Then the variable electricUse = "kW" not "2.465kW".

If you have an array:
electric['house'] = 12345
electric['house'] = 0
then electric['house'] = 0
AEOTEC ZStick, 11 ZWave Nodes, RFXCOMM, 50ish Byron Sockets.. HE851 (PIR), 2x HE852 (DoorContact)
WS2300, CM180, CC128, 2xTHGR122NX, 2xPiZeroW w/DS18B20, 8Ch 1W Relay Board.
8 Panasonic IP Cams, 1 16ch CCTV DVR + 15 CCTV Cams
User avatar
Plaagje
Posts: 42
Joined: Thursday 30 April 2015 10:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Location: Netherlands
Contact:

Re: Multiple SendNotification

Post by Plaagje »

Thank you for the explanation!

-Plaagje
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest