Prévision de pluie en lua V2

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 <\>.
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Prévision de pluie en lua V2

Message par calouis »

oups...mon script
--[[
script_time_meteofrance_pluie.lua
Download JSON.lua : http://regex.info/blog/lua/json

auteur : papoo
version : 2.00
maj : 31/10/2016
date : 11/05/2016
Principe : V1 récupérer via l'API non documentée de météo France, les informations de précipitation
de votre commune sur un device text et/ou alert et/ou notifications. viewtopic.php?f=10&t=1991
V2 en plus des fonctions de la V1, Afficher via les variables utilisateurs, les prédictions de précipitations sur une heure par pas de 5 mn sur la custom page
avec création automatiques des variables nécessaire à l'execution de ce script.
Actualisation des données toutes les 5 minutes, couleurs et texte directement récupérés via l'api
pour trouver le code de votre commune => http://www.insee.fr/fr/methodes/nomenclatures/cog/
]]--
--------------------------------------------
------------ Variables à éditer ------------
--------------------------------------------

local debugging = true -- true pour voir les logs dans la console log Dz ou false pour ne pas les voir
local ip = "192.168.1.16:8082";
local CityCode = 621080 -- le code de votre commune augmenté d'un 0 à la fin
local text_idx = 764 -- renseigner l'id du device text associé si souhaité, sinon nil
local rain_alert_idx = 765 -- renseigner l'id du device alert associé si souhaité, sinon nil
local send_notification = 0 -- 0: aucune notification, 1: toutes, 2: précipitations faibles, modérées et fortes, 3: modérées et fortes, 4: seulement fortes
local system = "linux" -- Systeme d'exploitation sur lequel est éxécuté ce script : linux, windows, synology pour le chemin vers JSON.LUA
local CustomPage = "oui" -- pour afficher les prévisions de pluie à une heure sur la custom page via des variables, valeurs acceptées : oui ou nil

--------------------------------------------
----------- Fin variables à éditer ---------
--------------------------------------------
local VariablesPluie={}
VariablesPluie[1]={nom = "Pluie à 5mn",Id = "1"}
VariablesPluie[2]={nom = "Pluie à 10mn",Id = "2"}
VariablesPluie[3]={nom = "Pluie à 15mn",Id = "3"}
VariablesPluie[4]={nom = "Pluie à 20mn",Id = "4"}
VariablesPluie[5]={nom = "Pluie à 25mn",Id = "5"}
VariablesPluie[6]={nom = "Pluie à 30mn",Id = "6"}
VariablesPluie[7]={nom = "Pluie à 35mn",Id = "7"}
VariablesPluie[8]={nom = "Pluie à 40mn",Id = "8"}
VariablesPluie[9]={nom = "Pluie à 45mn",Id = "9"}
VariablesPluie[10]={nom = "Pluie à 50mn",Id = "10"}
VariablesPluie[11]={nom = "Pluie à 55mn",Id = "11"}
VariablesPluie[12]={nom = "Pluie à 60mn",Id = "12"}

commandArray = {}
--------------------------------------------
---------------- Fonctions -----------------
--------------------------------------------
function voir_les_logs (s, debugging)
if (debugging) then
if s ~= nil then
print ("<font color='#f3031d'>".. s .."</font>")
else
print ("<font color='#f3031d'>aucune valeur affichable</font>")
end
end
end

function format(str)
if (str) then
str = string.gsub (str, "De", "De ")
str = string.gsub (str, " ", "&nbsp;")
str = string.gsub (str, "Pas&nbsp;de&nbsp;précipitations", "<font color='#999'>Pas&nbsp;de&nbsp;précipitations</font>")
str = string.gsub (str, "Précipitations&nbsp;faibles", "<font color='#fbda21'>Précipitations&nbsp;faibles</font>")
str = string.gsub (str, "Précipitations&nbsp;modérées", "<font color='#fb8a21'>Précipitations&nbsp;modérées</font>")
str = string.gsub (str, "Précipitations&nbsp;fortes", "<font color='#f3031d'>Précipitations&nbsp;fortes</font>")
end
return str
end
function urlencode(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
--------------------------------------------
---------------------------------------------------------------------------
time = os.date("*t")
if time.min % 2 == 0 then -- toutes les 5 minutes
--if time.hour % 1 == 0 then -- toutes les heures


voir_les_logs("--- --- ---script_time_meteofrance_pluie_V2.lua --- --- --- ",debugging)
local delay = os.time()
if system == "windows" then
json = (loadfile "D:\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
elseif system == "synology" then
json = (loadfile "/volume1/@appstore/domoticz/var/scripts/lua/JSON.lua")() -- For Synology
else
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
end


local indexArray=0


local config=assert(io.popen('curl http://www.meteofrance.com/mf3-rpc-port ... de..'.json'))
local location = config:read('*all')
config:close()
local jsonLocation = json:decode(location)


local niveauPluieText={}
niveauPluieText = jsonLocation.niveauPluieText
-- concaténation des entrées de la table et formatage
local PluieText = ''
if niveauPluieText ~= nil then
for Index, Value in pairs( niveauPluieText ) do
PluieText = PluieText..format(Value)..' '
voir_les_logs("--- --- --- niveauPluieText["..Index.."] : ".. Value .." --- --- ---",debugging)
end
voir_les_logs("--- --- --- PluieText : ".. PluieText .. " --- --- ---",debugging)
end
if CustomPage ~= nil then
--Récuperation des informations toutes les 5mn pour rafraichir les données des variables
local dataCadran={}
dataCadran = jsonLocation.dataCadran
local InfoNiveauPluieText = {}
local InfoNiveauPluie = {}
local InfoColor = {}
if dataCadran ~= nil then
for i, Result in ipairs( dataCadran ) do
InfoNiveauPluieText = Result.niveauPluieText
InfoNiveauPluie = Result.niveauPluie
InfoColor = Result.color
voir_les_logs("--- --- --- index : ".. i .. " Info : ".. InfoNiveauPluieText.. " Niveau : ".. InfoNiveauPluie .. " couleur :" .. InfoColor .. " --- --- ---",debugging)
end
end
for key, valeur in pairs(VariablesPluie) do
if(uservariables[valeur.nom] == nil) then
commandArray[indexArray]={['OpenURL']=ip..'/json.htm?type=command&param=saveuservariable&vname='..urlencode(valeur.nom)..'&vtype=2&vvalue='..urlencode(otherdevices_lastupdate[valeur.nom])}
indexArray=indexArray+1
voir_les_logs("--- --- --- creation variable manquante "..valeur.nom.." --- --- --- ",debugging)
else
voir_les_logs("--- --- --- key :" .. key .." - "..valeur.nom.." --- --- --- ",debugging)
commandArray['Variable:'..valeur.nom] = tostring("<font color='#".. InfoColor[key] .."'>".. InfoNiveauPluieText[key] .."</font>")
end
end
end
if text_idx ~= nil and PluieText ~= nil then
commandArray[indexArray] = {['UpdateDevice'] = text_idx .. '|0| ' .. PluieText}
indexArray=indexArray+1
end

if string.find(niveauPluieText[1], "Pas de précipitations") then
if rain_alert_idx ~= nil then
commandArray[indexArray] = {['UpdateDevice'] = rain_alert_idx..'|1|Pas de précipitations'}
indexArray=indexArray+1
end
if send_notification > 0 and send_notification < 2 then
commandArray[indexArray] = {['SendNotification'] = 'Alerte Météo#Pas de précipitations prévue!'}
indexArray=indexArray+1
end
voir_les_logs("--- --- --- Pas de précipitations --- --- ---",debugging)

elseif string.find(niveauPluieText[1], "faibles") then
if rain_alert_idx ~= nil then
commandArray[indexArray] = {['UpdateDevice'] = rain_alert_idx..'|2|Précipitations Faibles'}
indexArray=indexArray+1
end
if send_notification > 0 and send_notification < 3 then
commandArray[indexArray] = {['SendNotification'] = 'Alerte Météo#Précipitations Faibles!'}
indexArray=indexArray+1
end
voir_les_logs("--- --- --- Précipitations Faibles --- --- ---",debugging)


elseif string.find(niveauPluieText[1], "modérées") then
if rain_alert_idx ~= nil then
commandArray[indexArray] = {['UpdateDevice'] = rain_alert_idx..'|3|Précipitations modérées'}
indexArray=indexArray+1
end
if send_notification > 0 and send_notification < 4 then
commandArray[indexArray] = {['SendNotification'] = 'Alerte Météo#Précipitations modérées!'}
indexArray=indexArray+1
end
voir_les_logs("--- --- --- Précipitations modérées --- --- ---",debugging)


elseif string.find(niveauPluieText[1], "fortes") then
if rain_alert_idx ~= nil then
commandArray[indexArray] = {['UpdateDevice'] = rain_alert_idx..'|4|Précipitations fortes'}
indexArray=indexArray+1
end
if send_notification > 0 and send_notification < 5 then
commandArray[indexArray] = {['SendNotification'] = 'Alerte Météo#Précipitations fortes!'}
indexArray=indexArray+1
end
voir_les_logs("--- --- --- Précipitations fortes --- --- ---",debugging)

else
print("niveau non defini")
end

delay = os.time() - delay
voir_les_logs("--- --- --- Delai d'execution du script : " .. delay .."ms --- --- ---",debugging)
end --if time
return commandArray
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Prévision de pluie en lua V2

Message par calouis »

Voici, si cela peut aider, la custompage.
car j'ai toujours cette même erreur :
2016-11-20 16:46:00.550 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_meteofrance_pluie_V2.lua: ...omoticz/scripts/lua/script_time_meteofrance_pluie_V2.lua:135: attempt to concatenate a nil value
Pièces jointes
pluie.png
pluie.png (583.82 Kio) Consulté 9420 fois
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Prévision de pluie en lua V2

Message par papoo »

pour une raison inconnue il semblerait que la création des variables ne fonctionne pas correctement chez toi
pourrais tu verifier STP dans les variables si elles ont été créées (partiellement ou totalement)
et si ce n'est pas le cas les créer manuellement comme le tableau ci dessous
2016-11-20 17_09_03-Domoticz.png
2016-11-20 17_09_03-Domoticz.png (21.29 Kio) Consulté 9415 fois
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Prévision de pluie en lua V2

Message par papoo »

il faudrait supprimer le point virgule à la fin de

Code : Tout sélectionner

local ip = "192.168.1.16:8082"
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Prévision de pluie en lua V2

Message par calouis »

Même erreur sans point virgule.
Les variables n'ont pas été créées...

Je vais les implanter, à suivre!
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Prévision de pluie en lua V2

Message par calouis »

C'est pas gagné car lorsque je clique sur Ajouter, j'ai ERR en réponse ?
Pièces jointes
variable.png
variable.png (45.66 Kio) Consulté 9406 fois
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Prévision de pluie en lua V2

Message par papoo »

tu as regarder toutes les pages de variables?
tu en a 63 et chaque page affiche 25 variables.
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Prévision de pluie en lua V2

Message par calouis »

Les voilà classées par alphabet et j'ai bien regardé les 3 pages ?
Pièces jointes
ERR_variable.png
ERR_variable.png (606.42 Kio) Consulté 9401 fois
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
calouis
Messages : 109
Inscription : 08 nov. 2015, 10:34
Localisation : 62

Re: Prévision de pluie en lua V2

Message par calouis »

Pour info, j'ai essayé sous Safari et Firefox, idem...
_ Raspberry Pi3 Stretch + Domoticz V4.11214
_ dzVents Version: 2.4.28
_ Python 3.5.3
_ usbZwave
_ RFX433XL USB Version: Pro XL1/1035
_ GW Xiaomi
_ station meteo Oregon & Netatmo
_ LMS
_ Yeelight
_ Tradfri
_ Zigate plugin 4.11.012 + Version : 031d
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Prévision de pluie en lua V2

Message par papoo »

Résumons
Tu ne pas créer les variables via Json et le script
Tu ne peux pas créer tes variables manuellement
As tu essayé de mettre la variable custompage dans le script à nil pour voir si le restant du code s'exécute sans erreur?
As tu essayer de nommer tes nouvelles variables autrement puis une fois créées, de les renommer?
La création d'une variable quelconque est elle possible?
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
Répondre