Page 1 of 1
Multiple SendNotification
Posted: Saturday 08 April 2017 23:53
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
Re: Multiple SendNotification
Posted: Sunday 09 April 2017 0:19
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:
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.
Re: Multiple SendNotification
Posted: Sunday 09 April 2017 0:22
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...
Re: Multiple SendNotification
Posted: Sunday 09 April 2017 0:29
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.
Multiple SendNotification
Posted: Sunday 09 April 2017 0:31
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
Re: Multiple SendNotification
Posted: Sunday 09 April 2017 5:29
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
Re: Multiple SendNotification
Posted: Sunday 09 April 2017 14:01
by Plaagje
Thank you for the explanation!
-Plaagje