Bonjour,
Je continue ma réinstallation, et ce matin j'ai remis le script météo France Pluie.
Dans les logs, j'ai un message: "2021-05-12 11:41:01.173 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_meteofrance_pluie.lua: ...i/domoticz/scripts/lua/script_time_meteofrance_pluie.lua:140: attempt to index a nil value (local 'jsonLocation')"
Ci-dessous mon script en question:
Code : Tout sélectionner
--[[
script_time_meteofrance_pluie.lua
Download JSON.lua : http://regex.info/blog/lua/json
auteur : papoo
maj : 11/04/2017
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. http://easydomoticz.com/forum/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. http://easydomoticz.com/forum/viewtopic.php?f=10&t=2788
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/
Dans le cas de l'utilisation de la variable ActivePage il vous faut ajouter
dans la partie mqtt du fichier frontpage_settings.js de la Custom Page ceci :
case "d4": // nom du bouton de la télécommande
if (message.nvalue == 0){ // status On
memo = $("div").find("[data-index=4]").remove(); // memorisation page 5 et suppression
mySwipe.setup(); // reorganisation
if (mySwipe.getPos() == 4) // si nous sommes sur la page supprimee
mySwipe.slide(3); // deplacement vers la page precedente ( la 4 )
}
if (message.nvalue == 1){ // status Off
$("div").find("[data-index=3]").after( memo ); // rajout de la page 5 juste après la page 4
mySwipe.setup(); // reorganisation
mySwipe.slide(4); // deplacement vers la page rajoutee
}
Si votre device ne s'appelle pas "d4" pnsez à modifier la variable ActivePage dans ce script avec le meme nom de device dans le fichier frontpage_settings.js
]]--
--------------------------------------------
------------ Variables à éditer ------------
--------------------------------------------
local nom_script = "script_time_meteofrance_pluie"
local version = "2.30"
local debugging = false -- true pour voir les logs dans la console log Dz ou false pour ne pas les voir
local ip = "*******:********@192.168.1.13:****" -- <username:password@>domoticz-ip<:port>
local CityCode = 440660 -- le code de votre commune augmenté d'un 0 à la fin
local text_idx = 99 -- renseigner l'id du device text associé si souhaité, sinon nil
local rain_alert_idx = 100 -- renseigner l'id du device alert associé si souhaité, sinon nil
local send_notification = 3 -- 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
local ActivePage = "d4" -- renseigner l'id du device switch associé si souhaité, sinon nil pour afficher ou masquer la page des prévisions de pluie sur la custom page
--------------------------------------------
----------- 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, " ", " ")
str = string.gsub (str, "Pas de précipitations", "<font color='#999'>Pas de précipitations</font>")
str = string.gsub (str, "Précipitations faibles", "<font color='#fbda21'>Précipitations faibles</font>")
str = string.gsub (str, "Précipitations modérées", "<font color='#fb8a21'>Précipitations modérées</font>")
str = string.gsub (str, "Précipitations fortes", "<font color='#f3031d'>Précipitations 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
--------------------------------------------
-------------- Fin Fonctions ---------------
--------------------------------------------
time = os.date("*t")
if ((time.min-1) % 5) == 0 then
--if time.min % 5 == 0 then -- toutes les 5 minutes
voir_les_logs("=========== ".. nom_script .." (v".. version ..") ===========",debugging)
local delay = os.time()
-- if system == "windows" then
-- json = (loadfile "C:\\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
-- chemin vers le dossier lua
if (package.config:sub(1,1) == '/') then
luaDir = debug.getinfo(1).source:match("@?(.*/)")
else
luaDir = string.gsub(debug.getinfo(1).source:match("@?(.*\\)"),'\\','\\\\')
end
curl = '/usr/bin/curl -m 5 -u domoticzUSER:domoticzPSWD ' -- ne pas oublier l'espace à la fin
json = assert(loadfile(luaDir..'JSON.lua'))() -- chargement du fichier JSON.lua
local indexArray=0
local config=assert(io.popen('curl http://www.meteofrance.com/mf3-rpc-portlet/rest/pluie/'..CityCode..'.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[i] = Result.niveauPluieText
InfoNiveauPluie[i] = Result.niveauPluie
InfoColor[i] = Result.color
voir_les_logs("--- --- --- index : ".. i .. " Info : ".. InfoNiveauPluieText[i].. " Niveau : ".. InfoNiveauPluie[i] .. " couleur :" .. InfoColor[i] .. " --- --- ---",debugging)
end
end
for key, valeur in pairs(VariablesPluie) do
if(uservariables[valeur.nom] == nil) then
commandArray[indexArray]={['OpenURL']=ip..'/json.htm?type=command¶m=saveuservariable&vname='..urlencode(valeur.nom)..'&vtype=2&vvalue='..urlencode(tostring("<font color='#".. InfoColor[key] .."'>".. InfoNiveauPluieText[key] .."</font>"))}
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 -- pour l'affichage dans un device text
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
if CustomPage ~= nil and ActivePage ~= nil then
commandArray[ActivePage]='Off'
end
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
if CustomPage ~= nil and ActivePage ~= nil then
commandArray[ActivePage]='On'
end
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
if CustomPage ~= nil and ActivePage ~= nil then
commandArray[ActivePage]='On'
end
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
if CustomPage ~= nil and ActivePage ~= nil then
commandArray[ActivePage]='On'
end
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)
voir_les_logs("========= Fin ".. nom_script .." (v".. version ..") =========",debugging)
end --if time
return commandArray
J'ai beau chercher, je ne trouve pas l'erreur!
si quelqu'un pouvait me donner la solution. Merci.