avoir l'info via un script lua avec posibilité de mise à jour d'un device text et/ou alert et/ou notifications
si des fois cela peut vous servir
Code : Tout sélectionner
--[[
~/domoticz/scripts/lua/script_time_meteofrance_pluie.lua
Download JSON.lua : http://regex.info/blog/lua/json
]]--
-- --------------------------------
------ Tableau à éditer ------
--------------------------------
local debugging = false -- true pour voir les logs dans la console log Dz ou false pour ne pas les voir
local CityCode = 870850
local text_idx = 343 -- renseigner l'id du device text associé si souhaité, sinon nil
local rain_alert_idx = 699 -- 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
---------------------------------------------------------------------------
commandArray = {}
---------------------------------------------------------------------------
--Fonctions
---------------------------------------------------------------------------
function voir_les_logs (s)
if (debugging) then
print (s);
end
end
function format(str)
if (str) then
str = string.gsub (str, "De", "De ")
str = string.gsub (str, " ", " ")
end
return str
end
---------------------------------------------------------------------------
now=os.date("*t")
if now.min % 50 == 0 then
print('script_time_meteofrance_pluie.lua')
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() -- For Linux
--json = (loadfile "D:\\Domoticz\\scripts\\lua\\json.lua")() -- For Windows
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 = ''
for Index, Value in pairs( niveauPluieText ) do
PluieText = PluieText..format(Value)..' '
voir_les_logs("--- --- --- niveauPluieText["..Index.."] : ".. Value,debugging) -- fonctionne
end
voir_les_logs("--- --- --- PluieText : ".. PluieText,debugging) -- fonctionne
if text_idx ~= 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
end --if now.min
return commandArray