--[[
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, " ", " ")
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
--------------------------------------------
---------------------------------------------------------------------------
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¶m=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
Prévision de pluie en lua V2
Re: Prévision de pluie en lua V2
oups...mon script
_ 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
_ 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
Re: Prévision de pluie en lua V2
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
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 (583.82 Kio) Consulté 9415 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
_ 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
Re: Prévision de pluie en lua V2
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
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
Re: Prévision de pluie en lua V2
il faudrait supprimer le point virgule à la fin de
Code : Tout sélectionner
local ip = "192.168.1.16:8082"Re: Prévision de pluie en lua V2
Même erreur sans point virgule.
Les variables n'ont pas été créées...
Je vais les implanter, à suivre!
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
_ 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
Re: Prévision de pluie en lua V2
C'est pas gagné car lorsque je clique sur Ajouter, j'ai ERR en réponse ?
- Pièces jointes
-
- variable.png (45.66 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
_ 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
Re: Prévision de pluie en lua V2
tu as regarder toutes les pages de variables?
tu en a 63 et chaque page affiche 25 variables.
tu en a 63 et chaque page affiche 25 variables.
Re: Prévision de pluie en lua V2
Les voilà classées par alphabet et j'ai bien regardé les 3 pages ?
- Pièces jointes
-
- ERR_variable.png (606.42 Kio) Consulté 9396 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
_ 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
Re: Prévision de pluie en lua V2
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
_ 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
Re: Prévision de pluie en lua V2
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?
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?