LUA et notifications trop rapprochées

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
Biocef
Messages : 39
Inscription : 13 déc. 2014, 14:59

LUA et notifications trop rapprochées

Message par Biocef »

Bonjour,

Je rencontre quelques soucis avec des notifications qui s'enchainent.
J'utilise Telegram pour sa réactivité et sa gratuité.
Quand j'active l'alarme je dois recevoir une notification m'indiquant si une porte ou une fenêtre est restée ouverte. Le script que j'ai écrit envoi une notification par ouvrant resté ouvert ainsi qu'une pour confirmer l'activation de l'alarme.
Lorsque plusieurs portes sont ouvertes les notifications s'enchainent trop rapidement et je ne reçois que la dernière.

Par exemple avec ce script je ne reçois que la notification 5 :

Code : Tout sélectionner

if (devicechanged[test] == 'On') then
        commandArray['SendNotification']='#Notif1.##1#0#telegram'
        commandArray['SendNotification']='#Notif2.##1#0#telegram'
        commandArray['SendNotification']='#Notif3.##1#0#telegram'
        commandArray['SendNotification']='#Notif4.##1#0#telegram'
        commandArray['SendNotification']='#Notif5.##1#0#telegram'
end
Mon script d'alarme contient ceci :

Code : Tout sélectionner

if (devicechanged[alarme] == 'On') then
        commandArray['SendNotification']='#L\'alarme est activée.##1#0#telegram'
end
if (devicechanged[alarme] == 'On') then if (otherdevices[cuisine] == 'Open') then
        commandArray['SendNotification']='#Attention : La porte de la cuisine n\'a pas été fermée.##1#0#telegram'
  end
  end

if (devicechanged[alarme] == 'On') then if (otherdevices[sous_sol] == 'Open') then
        commandArray['SendNotification']='#Attention : La porte du sous-sol n\'a pas été fermée.##1#0#telegram'
  end
  end
if (devicechanged[alarme] == 'On') then if (otherdevices[entree] == 'Open') then
        commandArray['SendNotification']='#Attention : La porte d\'entrée n\'a pas été fermée.##1#0#telegram'
  end
Au vue du code vous aurez certainement compris que je ne suis pas expert, je fais au mieux avec ce que je trouve à gauche à droite :?
Est-il possible de décaler des notifications de quelques secondes ?
Comment feriez-vous pour recevoir toutes les notifications ?
Merci d'avance !
lost
Messages : 1511
Inscription : 12 nov. 2016, 11:01

Re: LUA et notifications trop rapprochées

Message par lost »

Biocef a écrit : 14 août 2020, 14:09 Le script que j'ai écrit envoi une notification par ouvrant resté ouvert ainsi qu'une pour confirmer l'activation de l'alarme.
Lorsque plusieurs portes sont ouvertes les notifications s'enchainent trop rapidement et je ne reçois que la dernière.

Par exemple avec ce script je ne reçois que la notification 5 :

Code : Tout sélectionner

if (devicechanged[test] == 'On') then
        commandArray['SendNotification']='#Notif1.##1#0#telegram'
        commandArray['SendNotification']='#Notif2.##1#0#telegram'
        commandArray['SendNotification']='#Notif3.##1#0#telegram'
        commandArray['SendNotification']='#Notif4.##1#0#telegram'
        commandArray['SendNotification']='#Notif5.##1#0#telegram'
end
C'est "normal", ciblant juste SendNotification sans précaution, chaque nouvelle ligne remplace le contenu de la table et seul le dernier gagne et sera effectivement exécuté en sortie de script après retour de la table modifiée. Ce serait pareil avec un même nom de switch ou autre...

Il faut bien comprendre que l’exécution n'est pas faite juste au moment ou on mets les commandes en table, mais après exécution du script.

Voir:

Code : Tout sélectionner

commandArray[#commandArray + 1] = { SendNotification = 'subject#body#prio#sound#extraData#subSystem1;subSystem2;subSystem3'
Ici:
https://www.domoticz.com/wiki/LUA_commands

Ou plus d'explications ici:
https://www.domoticz.com/wiki/Events

A partir de
The commandArray also supports nested tables to send the same command type multiple times.
Biocef
Messages : 39
Inscription : 13 déc. 2014, 14:59

Re: LUA et notifications trop rapprochées

Message par Biocef »

Ça marche impec, merci !!!

Code : Tout sélectionner

if (devicechanged[test] == 'On') then
        commandArray[#commandArray + 1] = { SendNotification = '#Test1.##1#0#telegram'}
        commandArray[#commandArray + 1] = { SendNotification = '#Test2.##1#0#telegram'}
        commandArray[#commandArray + 1] = { SendNotification = '#Test3.##1#0#telegram'}
        commandArray[#commandArray + 1] = { SendNotification = '#Test4.##1#0#telegram'}
        commandArray[#commandArray + 1] = { SendNotification = '#Test5.##1#0#telegram'}
end
Répondre