Page 1 sur 1
DZVENTS comprends rien :(
Publié : 30 déc. 2019, 18:34
par e111111
Bonjour à tous et toutes et bonnes fêtes de fin d'année
Je me suis lancé dans DZVENTS car j'ai trouvé sur le net un script qui me convient pour ce que je veux faire, cependant, il nécessite quelques adaptations.
J'ai appris LUA et d'autres de cette façon, ce qui ne m'a jamais posé pb, mais là, je sèche, jamais vu un truc aussi obscur... Je ne comprends absolument pas ce "langage" qui me paraît très compliqué, et il n'y a pas foule d'exemples sur le net.
J'ai tenté d'éplucher les exemples fournis avec Domoticz, il y en a pas mal, mais bien que certains semblent peut-être approcher mes attentes, je suis malheureusement incapable d'en faire quoi que se soit à mon grand désarroi.
Le script charge tous les plannings présents dans Domoticz pour les modifier, mais j'ai besoin de ne modifier qu'un seul device, donc il me faudrait sélectionner un sélecteur d'après sa propriété "DevName" pour ne récupérer que ces plannings à lui et lui seul.
Une bonne âme pourrait-elle m'indiquer la manière de procéder si possible avec les explications ?
Je pense que sinon, je vais laisser tomber ce langage incompréhensible pour moi et revenir à LUA.
Merci d'avance pour votre aide
Re: DZVENTS comprends rien :(
Publié : 30 déc. 2019, 22:44
par boum
Bonjour,
Tout déjà, un petit élément de langage : dzVents est un système de script pour Domoticz, mais c'est aussi en langage Lua. Le langage de programmation est le même mais la façon d'accéder aux dispositifs est différent. La facilité de programmation est subjective entre les deux systèmes.
La doc de dzVents en anglais sur le Wiki de domoticz est globalement assez complète.
Sans un script de base sur lequel s'appuyer, il sera dur de t'aider. La difficulté vient peut-être du script d'origine qui n'a pas été prévu pour être modifié ou adapté. Mais comme ça, impossible à dire.
Au pire, tu pourrais toujours convertir le script dzVents en Lua commandArray.
Re: DZVENTS comprends rien :(
Publié : 31 déc. 2019, 09:34
par e111111
Bonjour Boum,
merci pour ta réponse,
Difficile de convertir du dzvents en LUA sans rien y comprendre...
Au cas ou, voici le lien vers le script dzvents que je cherche à modifier :
https://www.planete-domotique.com/blog/ ... ent-170190
J'avais laissé un message à son auteur, mais visiblement il n'était pas passé, du coup j'en ai laissé un autre, j'attends, peut-être qu'il voudra bien m'expliquer.
J'aimerais bien quand même comprendre dzvents qui permet de modifier des scripts à distance car pas besoin de passer par Winscp puisque l'accès et l'éditeur est directement intégré à Domoticz.
Je vais me plonger dans le wiki, mais en général je comprends mieux en travaillant directement sur des exemples concrets.
Re: DZVENTS comprends rien :(
Publié : 31 déc. 2019, 12:56
par boum
Alors oui, pour ta défense, le script n'est pas évident à comprendre. Il a été réalisé sur un serveur domoticz dédié à l'arrosage et donc tous les timers sont affectés.
Personnellement, je le modifierai ainsi :
Code : Tout sélectionner
return {
on = { variables = { 'GlobalOnOff' }, httpResponses = { 'CodeRetour' } },
data = {
Step = { initial = 'Appel initial' },
MasterInter = { initial = 'MasterInter non initialisé' },
Horo = { initial = 'Horo non initialisé' },
URLPlanningOn = { initial = 'URLPlanningOn non initialisée' },
URLPlanningOff = { initial = 'URLPlanningOff non initialisée' },
TabPlannings = { initial = nil },
NbPostesPlanning = { initial = 'NbPostesPlanning non initialisé' },
PostePlanningEc = { initial = 'PostePlanningEc non initialisé'
}
},
execute = function(domoticz, item)
local bavard = false
local emailNotification = 'xxx@xxx.com'
-- Filtre pour les timers à lister
local filterDevices = {
['Device Name 1'] = true,
['Other Device Name 2'] = true,
}
local getURLPlanning = function(domoticz, indexTab)
-- Mise en forme de la requête
local URLPlanningOnOff = ''
if domoticz.data.MasterInter == 'On' then
URLPlanningOnOff = domoticz.data.URLPlanningOn
else
URLPlanningOnOff = domoticz.data.URLPlanningOff
end
local currentTimerID = domoticz.data.TabPlannings[indexTab].TimerID
URLPlanningOnOff = URLPlanningOnOff .. currentTimerID
return URLPlanningOnOff
end
if bavard then
domoticz.log('Etape du script = ' .. domoticz.data.Step)
domoticz.log('Variable MasterInter = ' .. domoticz.data.MasterInter)
domoticz.log('Variable Horo = ' .. domoticz.data.Horo)
domoticz.log('Requête PlanningOn = ' .. domoticz.data.URLPlanningOn)
domoticz.log('Requête PlanningOff = ' .. domoticz.data.URLPlanningOff)
domoticz.log('Dispositifs concernés :')
for name,_ in pairs(filterDevices) do
domoticz.log(name .. ' (' .. domoticz.devices(name).state .. ')')
end
-- à 'décommenter' pour lister la table persistante des planifications dans la log
-- if domoticz.data.NbPostesPlanning ~= 'NbPostesPlanning non initialisé' then
-- for i = 1, domoticz.data.NbPostesPlanning do
-- local tab = domoticz.data.TabPlannings[i]
-- domoticz.log('Poste planning "' .. i .. '" : TimerID = ' .. tab.TimerID .. ', Active = ' .. tab.Active .. ', DevName = ' .. tab.DevName .. ', Time = ' .. tab.Time .. ', TimerCmd = ' .. tab.TimerCmd)
-- end
-- end
domoticz.log('Nombre de plannings = ' .. domoticz.data.NbPostesPlanning)
domoticz.log('Poste planning en cours = ' .. domoticz.data.PostePlanningEc)
end
if item.isVariable then
---- Trigger = changement d'état de la Variable GlobalOnOff ... donc premier appel du script
local MasterInter = ''
local IPGreenIQ = 'http://192.168.10.51:8080'
local GetPlannings = IPGreenIQ .. '/json.htm?type=schedules&filter=device'
---- Attention, idx sera l'index du schedule et non du device
local PlanningOn = IPGreenIQ .. '/json.htm?type=command¶m=enabletimer&idx='
local PlanningOff = IPGreenIQ .. '/json.htm?type=command¶m=disabletimer&idx='
local Jour = os.date("%d-%m-%Y")
local Heure = os.date("%X")
local Horo = " le " .. Jour .. " à " .. Heure
if item.value == 1 then MasterInter = 'On' else MasterInter = 'Off' end
---- Chargement des données persistantes
domoticz.data.MasterInter = MasterInter
domoticz.data.Horo = Horo
domoticz.data.URLPlanningOn = PlanningOn
domoticz.data.URLPlanningOff = PlanningOff
---- Récupération de la plannification des devices
domoticz.data.Step = 'Initialisation des variables, récupération de la planification'
if bavard then domoticz.log('Envoi de la requête ' .. GetPlannings) end
domoticz.openURL({
url = GetPlannings,
method = 'GET',
callback = 'CodeRetour',
})
elseif item.isHTTPResponse then
---- Trigger = Code retour openURL
if item.ok then
---- Retour de l'interrogation de la planification des devices (/json.htm?type=schedules&filter=device)
if domoticz.data.Step == 'Initialisation des variables, récupération de la planification' then
---- Mise en table de la planification
-- Conversion du résultat JSON de la requête vers la table TabPlanningsJson
local TabPlanningsJson = item.json.result
-- Comptage du nombre de postes pour initialiser la variable persistante NbPostesPlanning
local NbPostes = 0
---- Chargement de la table "persistante" TabPlannings
---- Structure de la table :
---- TimerID (Index de planification)
---- Active (Planification active ou non)
---- DevName (Nom du périphérique)
---- Time (Heure de la Planification)
---- TimerCmd (Action entreprise)
-- Déclaration de la table persistante TabPlannings en fonction du nombre de postes retourné par la commande json
domoticz.data.TabPlannings = {}
for i, planning in pairs (TabPlanningsJson) do
local deviceName = planning.DevName
if filterDevices[deviceName] then
if bavard then
domoticz.log('TabPlanningsJson --> Zone = ' .. planning["DevName"] .. ' - Heure = ' .. planning["Time"] .. ' - Timer = ' .. planning["TimerID"] .. ' - Actif = ' .. planning["Active"])
end
NbPostes = NbPostes + 1
domoticz.data.TabPlannings[NbPostes] = {
TimerID = planning.TimerID,
Active = planning.Acive,
DevName = deviceName,
Time = planning.Time,
TimerCmd = planning.TimerCmd,
}
end
end
domoticz.data.NbPostesPlanning = NbPostes
---- Envoi de la première requête d'activation ou de désactivation des plannings
-- Préparation des codes retours
domoticz.data.Step = 'Boucle de modification de la planification'
domoticz.data.PostePlanningEc = 1
local URLPlanningOnOff = getURLPlanning(domoticz, 1)
if bavard then domoticz.log('Envoi de la requête ' .. URLPlanningOnOff) end
domoticz.openURL({
url = URLPlanningOnOff,
method = 'GET',
callback = 'CodeRetour',
})
elseif domoticz.data.Step == 'Boucle de modification de la planification' then
-- On incrémente le compteur de poste dans la table des planifications
domoticz.data.PostePlanningEc = domoticz.data.PostePlanningEc + 1
-- On vérifie si tous les postes ont été traités
if domoticz.data.PostePlanningEc > domoticz.data.NbPostesPlanning then
---- C'est fini
-- Mise en forme tu texte de compte-rendu
local Jour = os.date("%d-%m-%Y")
local Heure = os.date("%X")
local Horo = " le " .. Jour .. " à " .. Heure
local MasterInter
if domoticz.data.MasterInter == 'On' then MasterInter = 'RÉACTIVATION' else MasterInter = 'DÉSACTIVATION' end
-- local Texte = "Demande de " .. MasterInter .. " de l'arrosage planifié " .. domoticz.data.Horo .. " - Procédure terminée " .. Horo
local Texte = MasterInter .. " de l'arrosage planifié " .. domoticz.data.Horo
if bavard then domoticz.log("--> Message = " .. Texte) end
-- Envoi du courriel
domoticz.email("GreenIq - Gestion de l'arrosage planifié", Texte, emailNotification)
-- Réinitialisation des données persistantes pour la prochaine utilisation
domoticz.data.Step = 'Appel initial'
domoticz.data.MasterInter = 'MasterInter non initialisé'
domoticz.data.Horo = 'Horo non initialisé'
domoticz.data.URLPlanningOn = 'URLPlanningOn non initialisée'
domoticz.data.URLPlanningOff = 'URLPlanningOff non initialisée'
domoticz.data.TabPlannings = {}
domoticz.data.NbPostesPlanning = 'NbPostesPlanning non initialisé'
domoticz.data.PostePlanningEc = 'PostePlanningEc non initialisé'
---- Bye bye
else
---- On continue
local URLPlanningOnOff = getURLPlanning(domoticz, domoticz.data.PostePlanningEc)
if bavard then domoticz.log('Envoi de la requête ' .. URLPlanningOnOff) end
domoticz.openURL({
url = URLPlanningOnOff,
method = 'GET',
callback = 'CodeRetour',
})
end
end
else
-- CodeRetour non OK
domoticz.log('--> Procédure GlobalOnOff - Code retour incorrect : ' .. item.statusCode .. ', ' .. item.statusText)
domoticz.log('Poste planning en cours = ' .. domoticz.data.PostePlanningEc)
local tab = domoticz.data.TabPlannings[domoticz.data.PostePlanningEc]
domoticz.log('Poste planning : TimerID = ' .. tab.TimerID .. ', Active = ' .. tab.Active .. ', DevName = ' .. tab.DevName .. ', Time = ' .. tab.Time .. ', TimerCmd = ' .. tab.TimerCmd)
end
end
end
}
C'est un premier jet, et je vois d'autres simplifications.
Mais cette version contient un tableau à remplir contenant les dispositifs à prendre en compte.
Re: DZVENTS comprends rien :(
Publié : 31 déc. 2019, 12:56
par boum
Il y a aussi potentiellement des erreurs de langage, je n'ai pas testé

Re: DZVENTS comprends rien :(
Publié : 31 déc. 2019, 13:23
par boum
Une version plus simplifiée :
Code : Tout sélectionner
return {
on = { variables = { 'GlobalOnOff' }, httpResponses = { 'CodeRetour' } },
data = {
Step = { initial = 'Appel initial' },
Horo = { initial = 'Horo non initialisé' },
TabPlannings = { initial = nil },
NbPostesPlanning = { initial = 0 },
PostePlanningEc = { initial = 0 },
},
execute = function(domoticz, item)
local bavard = false
local emailNotification = 'xxx@xxx.com'
local IPGreenIQ = 'http://192.168.10.51:8080'
local GetPlannings = IPGreenIQ .. '/json.htm?type=schedules&filter=device'
---- Attention, idx sera l'index du schedule et non du device
local URLPlanningOn = IPGreenIQ .. '/json.htm?type=command¶m=enabletimer&idx='
local URLPlanningOff = IPGreenIQ .. '/json.htm?type=command¶m=disabletimer&idx='
local MasterInter = (1 == domoticz.variables("GlobalOnOff"))
-- Filtre pour les timers à lister
local filterDevices = {
['Device Name 1'] = true,
['Other Device Name 2'] = true,
}
local changeURLPlanning = function(domoticz, indexTab)
-- Mise en forme de la requête
local URLPlanning = URLPlanningOff
if MasterInter then
URLPlanning = URLPlanningOn
end
local currentTimerID = domoticz.data.TabPlannings[indexTab].TimerID
URLPlanning = URLPlanning .. currentTimerID
if bavard then domoticz.log('Envoi de la requête ' .. URLPlanning) end
domoticz.openURL({
url = URLPlanning,
method = 'GET',
callback = 'CodeRetour',
})
end
if bavard then
domoticz.log('Etape du script = ' .. domoticz.data.Step)
domoticz.log('Variable MasterInter = ' .. MasterInter)
domoticz.log('Variable Horo = ' .. domoticz.data.Horo)
domoticz.log('Dispositifs concernés :')
for name,_ in pairs(filterDevices) do
domoticz.log(name .. ' (' .. domoticz.devices(name).state .. ')')
end
-- à 'décommenter' pour lister la table persistante des planifications dans la log
-- if domoticz.data.NbPostesPlanning ~= 0 then
-- for i = 1, domoticz.data.NbPostesPlanning do
-- local tab = domoticz.data.TabPlannings[i]
-- domoticz.log('Poste planning "' .. i .. '" : TimerID = ' .. tab.TimerID .. ', Active = ' .. tab.Active .. ', DevName = ' .. tab.DevName .. ', Time = ' .. tab.Time .. ', TimerCmd = ' .. tab.TimerCmd)
-- end
-- end
domoticz.log('Nombre de plannings = ' .. domoticz.data.NbPostesPlanning)
domoticz.log('Poste planning en cours = ' .. domoticz.data.PostePlanningEc)
end
if item.isVariable then
---- Trigger = changement d'état de la Variable GlobalOnOff ... donc premier appel du script
local Jour = os.date("%d-%m-%Y")
local Heure = os.date("%X")
local Horo = " le " .. Jour .. " à " .. Heure
---- Chargement des données persistantes
domoticz.data.Horo = Horo
---- Récupération de la plannification des devices
domoticz.data.Step = 'Initialisation des variables, récupération de la planification'
if bavard then domoticz.log('Envoi de la requête ' .. GetPlannings) end
domoticz.openURL({
url = GetPlannings,
method = 'GET',
callback = 'CodeRetour',
})
elseif item.isHTTPResponse then
---- Trigger = Code retour openURL
if item.ok then
---- Retour de l'interrogation de la planification des devices (/json.htm?type=schedules&filter=device)
if domoticz.data.Step == 'Initialisation des variables, récupération de la planification' then
---- Mise en table de la planification
-- Conversion du résultat JSON de la requête vers la table TabPlanningsJson
local TabPlanningsJson = item.json.result
-- Comptage du nombre de postes pour initialiser la variable persistante NbPostesPlanning
local NbPostes = 0
---- Chargement de la table "persistante" TabPlannings
---- On n'a besoin uniquement du TimerID, en debug (bavard), rajoute plusieurs autres information :
---- TimerID (Index de planification)
---- Active (Planification active ou non)
---- DevName (Nom du périphérique)
---- Time (Heure de la Planification)
---- TimerCmd (Action entreprise)
-- Déclaration de la table persistante TabPlannings en fonction du nombre de postes retourné par la commande json
domoticz.data.TabPlannings = {}
for i, planning in pairs (TabPlanningsJson) do
local deviceName = planning.DevName
-- Vérifie si le nom du dispositif correspond au filtre
if filterDevices[deviceName] then
-- ajoute une nouveau poste à activer/désactiver
local tab = { TimerID = planning.TimerID }
if bavard then
domoticz.log('TabPlanningsJson --> Zone = ' .. planning["DevName"] .. ' - Heure = ' .. planning["Time"] .. ' - Timer = ' .. planning["TimerID"] .. ' - Actif = ' .. planning["Active"])
tab.Active = planning.Acive
tab.DevName = deviceName
tab.Time = planning.Time
tab.TimerCmd = planning.TimerCmd
end
NbPostes = NbPostes + 1
domoticz.data.TabPlannings[NbPostes] = tab
end
end
domoticz.data.NbPostesPlanning = NbPostes
---- Envoi de la première requête d'activation ou de désactivation des plannings
-- Préparation des codes retours
domoticz.data.Step = 'Boucle de modification de la planification'
domoticz.data.PostePlanningEc = 1
changeURLPlanning(domoticz, 1)
elseif domoticz.data.Step == 'Boucle de modification de la planification' then
-- On incrémente le compteur de poste dans la table des planifications
domoticz.data.PostePlanningEc = domoticz.data.PostePlanningEc + 1
-- On vérifie si tous les postes ont été traités
if domoticz.data.PostePlanningEc > domoticz.data.NbPostesPlanning then
---- C'est fini
-- Mise en forme tu texte de compte-rendu
local Jour = os.date("%d-%m-%Y")
local Heure = os.date("%X")
local Horo = " le " .. Jour .. " à " .. Heure
local active
if MasterInter then active = 'RÉACTIVATION' else active = 'DÉSACTIVATION' end
-- local Texte = "Demande de " .. active .. " de l'arrosage planifié " .. domoticz.data.Horo .. " - Procédure terminée " .. Horo
local Texte = active .. " de l'arrosage planifié " .. domoticz.data.Horo
if bavard then domoticz.log("--> Message = " .. Texte) end
-- Envoi du courriel
domoticz.email("GreenIq - Gestion de l'arrosage planifié", Texte, emailNotification)
-- Réinitialisation des données persistantes pour la prochaine utilisation
domoticz.data.Step = 'Appel initial'
domoticz.data.Horo = 'Horo non initialisé'
domoticz.data.TabPlannings = {}
domoticz.data.NbPostesPlanning = 0
domoticz.data.PostePlanningEc = 0
---- Bye bye
else
---- On continue
changeURLPlanning(domoticz, domoticz.data.PostePlanningEc)
end
end
else
-- CodeRetour non OK
domoticz.log('--> Procédure GlobalOnOff - Code retour incorrect : ' .. item.statusCode .. ', ' .. item.statusText)
domoticz.log('Poste planning en cours = ' .. domoticz.data.PostePlanningEc)
local tab = domoticz.data.TabPlannings[domoticz.data.PostePlanningEc]
if bavard then
domoticz.log('Poste planning : TimerID = ' .. tab.TimerID .. ', Active = ' .. tab.Active .. ', DevName = ' .. tab.DevName .. ', Time = ' .. tab.Time .. ', TimerCmd = ' .. tab.TimerCmd)
else
domoticz.log('Poste planning : TimerID = ' .. tab.TimerID)
end
end
end
end
}
J'ai supprimé au maximum tout ce qui ne nécessitait pas d'être stocké dans les variables persistantes. Par exemple MasterInter peut être calculé à tout moment à partir de la variable utilisateur. De même, certaines URL sont des constantes.
La table contenant les informations des timers peut aussi être limitée à l'index du timer.
Bref j'espère que cela sera plus compréhensible.
Re: DZVENTS comprends rien :(
Publié : 31 déc. 2019, 13:44
par e111111
Super !
Tu es génial !!!!! Merci pour le temps passé !
Je n'aurais pas le temps de tester ça aujourd'hui, si je reste sur le PC on va me jeter des pierres
Mais dès demain je me précipite dessus et te tiens au courant .
Merci encore et bon réveillon à toi et à tous

Re: DZVENTS comprends rien :(
Publié : 01 janv. 2020, 10:40
par e111111
Hello,
tout d'abord bonne année à tous et particulièrement à Boum qui m'a bien aidé sur ce coup là.
J'ai testé tes scripts allégés, le premier fonctionne bien, le deuxième ne fait que désactiver et ne réactive pas, peut-être un peu trop dépopulé
Pas grave, j'en ai un qui fonctionne et est parfaitement adapté à mes besoins
Merci encore