Can I have a method of combining a variable with different results into a message body.
rule “Armement et serrures ON”
when
Item AlarmeStatut changed to “ARMEE PERSONNE”
then
var String date = sdf.format( new Date() )
var serrure_status = “”
Serrures?.members.forEach(item|
if (item.state == OFF) {
item.sendCommand(ON)
serrure_status = (item.name + “: etait ouverte maintenant fermee \n”)
sendMail(“XXX”, “Armement”, serrure_status)
}
)
var message = ("Armement en mode " + AlarmeStatut.state + " par usager " + AlarmeStatut_usager.state + " le " + date “\n” + serrure_status)
sendMail(“XXX”, “Armement”, message)
end
I would like to combine the result of serrure_status and send it in the message text. Currently doesn’t work. The wonly way that it works is if I send it with diferent emails ( so a 2 iteration of 2, will give me 3 emails)
Would the += operator to concatenate strings work here?
rule "Armement et serrures ON"
when
Item AlarmeStatut changed to "ARMEE PERSONNE"
then
var String date = sdf.format( new Date() )
var serrure_status = ""
Serrures?.members.forEach(item|
if (item.state == OFF) {
item.sendCommand(ON)
serrure_status += item.name + ": etait ouverte maintenant fermée\n"
}
)
var message = "Armement en mode " + AlarmeStatut.state + " par usager " + AlarmeStatut_usager.state + " le " + date "\n" + serrure_status
sendMail("XXX", "Armement", message)
end
Thanks for the input.
So, if I understand correctly, the variable serrure_status -->
serrure_status += item.name + “: etait ouverte maintenant fermée\n”
will get added with the correct lines as the loop is gooing. In a case that
we have to iteration that trigger the condition, my mail message variable
will have 3 lines Inside. One for the status, and the 2 others with ITEM X
and ITEM Z output.
I will try it this evening and come back with the response