Est-ce moi mais malgré le passage a
Code : Tout sélectionner
-- Parameters to change according to you needs
debug=false
Code : Tout sélectionner
-- Parameters to change according to you needs
debug=false
Code : Tout sélectionner
-- Parameters to change according to you needs
debug=false
-- Json config loadfile
config = '/home/pi/domoticz/scripts/vigicrue/vigicrue.json'
-- for Windows
-- config = 'C:\\Program Files (x86)\\Domoticz\\scripts\\vigicrue.json'
-- JSON.lua path
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
-- for Windows
--json = (loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\JSON.lua")()
-- Curl path
curl = '/usr/bin/curl'
-- for Windows
-- curl = 'C:\\cygwin\\bin\\curl'
-- End of parameters
time = os.date("*t")
-- Function to update sensor
local function update(idx, value1)
local cmd = idx..'|0|'..value1
--print(cmd)
table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
local function sendnotif(station, result, type, channel)
if (type == "height") then
local cmd = 'Water level is high for station '..station..'#Current level is '..result..'m for'..station..'#0#sound#extradata#'..channel
if (debug) then print("NotifHeight: "..cmd) end
elseif (type == "speed") then
local cmd = 'Water speed level is high for station '..station..'#Current speed level: '..result..'m3/s for '..station..'#0#sound#extradata#'..channel
if (debug) then print("NotifSpeed: "..cmd) end
end
table.insert (commandArray, { ['SendNotification'] = "cmd" } )
if (debug) then print("Notif: Sent") end
end
-- function to get data from url
local function getdata(urlh,urls)
local DataHeight = assert(io.popen(curl..' -s "'..urlh..'"'))
local BlocJsonHeight = DataHeight:read('*all')
DataHeight:close()
local JsonHeight = json:decode(BlocJsonHeight)
local Height = JsonHeight.Serie.ObssHydro
local Name = JsonHeight.Serie.LbStationHydro
local DataSpeed = assert(io.popen(curl..' -s "'..urls..'"'))
local BlocJsonSpeed = DataSpeed:read('*all')
DataSpeed:close()
local JsonSpeed = json:decode(BlocJsonSpeed)
local Speed = JsonSpeed.Serie.ObssHydro
return Height, Speed, Name
end
commandArray = {}
if (time.min == 0 or time.min == 30) then
local file = assert(io.open(config, "r"))
local json_text = file:read("*all")
file:close()
local Conf = json:decode(json_text)
Station = Conf.station
for k,v in pairs(Station) do
local IDStation = v
local IDXHeight = Conf.idx.height[v]
local IDXSpeed = Conf.idx.speed[v]
local NotifHeightV = Conf.notifications.height[v].value
local NotifHeightA = Conf.notifications.height[v].active
local NotifSpeedV = Conf.notifications.speed[v].value
local NotifSpeedA = Conf.notifications.speed[v].active
local urlHeight = 'https://www.vigicrues.gouv.fr/services/observations.json/index.php?CdStationHydro='..IDStation..'&GrdSerie=H&FormatSortie=simple'
local urlSpeed = 'https://www.vigicrues.gouv.fr/services/observations.json/index.php?CdStationHydro='..IDStation..'&GrdSerie=Q&FormatSortie=simple'
ResultHeight,ResultSpeed,StationName=getdata(urlHeight,urlSpeed)
if (#ResultHeight ~= 0) then
if (debug) then print("ResultHeight: "..ResultHeight[#ResultHeight][2]) end
update(IDXHeight, ResultHeight[#ResultHeight][2])
if (NotifHeightA == "true") then
if (tostring(ResultHeight[#ResultHeight][2]) > NotifHeightV) then
table.insert(commandArray, {['SendNotification'] = 'Water level is high for station '..StationName..'#Current level is '..ResultHeight[#ResultHeight][2]..'m for '..StationName..'#0#sound#extradata#telegram'})
end
end
else
if (debug) then print('Height level is empty.') end
end
if (#ResultSpeed ~= 0) then
if (debug=true) then print("ResultSpeed: "..ResultSpeed[#ResultSpeed][2]) end
update(IDXSpeed, ResultSpeed[#ResultSpeed][2])
if (NotifSpeedA == "true") then
if (tostring(ResultSpeed[#ResultSpeed][2]) > NotifSpeedV) then
table.insert(commandArray, {['SendNotification'] = 'Water speed level is high for station '..StationName..'#Current speed level: '..ResultSpeed[#ResultSpeed][2]..'m3/s for '..StationName..'#0#sound#extradata#telegram'})
end
end
else
if (debug=true) then print('Speed is empty.') end
end
end
end
return commandArray
J'ai une vieille version....chatainsim a écrit : 12 oct. 2021, 14:08 Le debug à false affiche juste moins d'infos dans les logs de domoticz.
Il faut commenter la ligne 56 : commandArray['SendNotification'] pour ne plus avoir les notifications
Code : Tout sélectionner
-- Parameters to change according to you needs
debug=true
-- Station ID, from one to many
Station = {'K490003010'}
-- IDX of sensor for height value | STATION_ID='IDX_SENSOR'
SIDXHeight = {K490003010='439'} -- SIDXHeight = {K490003010='215', L800001020='218'}
-- IDX of sensor for speed value | STATION_ID='IDX_SENSOR'
SIDXSpeed = {K490003010='440'}
-- JSON.lua path
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")
-- Curl path
curl = '/usr/bin/curl'
-- End of parameters
time = os.date("*t")
-- Function to update sensor
local function update(idx, value1)
local cmd = idx..'|0|'..value1
--print(cmd)
table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
-- function to get data from url
local function getdata(urlh,urls)
local DataHeight = assert(io.popen(curl..' -s "'..urlh..'"'))
local BlocJsonHeight = DataHeight:read('*all')
DataHeight:close()
local JsonHeight = json:decode(BlocJsonHeight)
local Height = JsonHeight.Serie.ObssHydro
local DataSpeed = assert(io.popen(curl..' -s "'..urls..'"'))
local BlocJsonSpeed = DataSpeed:read('*all')
DataSpeed:close()
local JsonSpeed = json:decode(BlocJsonSpeed)
local Speed = JsonSpeed.Serie.ObssHydro
return Height, Speed
end
local function test_error(url)
local DataTest = assert(io.popen(curl..' -s --max-time 8 "'..url..'"'))
local BlocJsonTest = DataTest:read('*all')
DataTest:close()
JsonTest = json:decode(BlocJsonTest)
Test = JsonTest[1].error_msg
end
commandArray = {}
if (time.min == 0 or time.min == 30) then
for k,v in pairs(Station) do
local IDStation = v
local IDXHeight = SIDXHeight[v]
local IDXSpeed = SIDXSpeed[v]
local urlHeight = 'https://www.vigicrues.gouv.fr/services/observations.json/index.php?CdStationHydro='..IDStation..'&GrdSerie=H&FormatSortie=simple'
local urlSpeed = 'https://www.vigicrues.gouv.fr/services/observations.json/index.php?CdStationHydro='..IDStation..'&GrdSerie=Q&FormatSortie=simple'
local status, retval = pcall(test_error,urlHeight);
if (status) then
print("Error, station inconnu")
commandArray['SendNotification']='subject#Erreur, station '..IDStation..' inconnu ou problème temporaire du site Vigicrue, merci de vérifier : '..urlHeight..'#0#sound#extradata#telegram'
else
ResultHeight,ResultSpeed=getdata(urlHeight,urlSpeed)
if (#ResultHeight ~= 0) then
if (debug) then print("ResultHeight: "..ResultHeight[#ResultHeight][2]) end
update(IDXHeight, ResultHeight[#ResultHeight][2])
else
if (debug) then print('Height level is empty.') end
end
if (#ResultSpeed ~= 0) then
if (debug) then print("ResultSpeed: "..ResultSpeed[#ResultSpeed][2]) end
update(IDXSpeed, ResultSpeed[#ResultSpeed][2])
else
if (debug) then print('Speed is empty.') end
end
end
end
end
return commandArray
Code : Tout sélectionner
-- Parameters to change according to you needs
debug=true
-- Station ID, from one to many
Station = {'K490003010'}
-- IDX of sensor for height value | STATION_ID='IDX_SENSOR'
SIDXHeight = {K490003010='610'}
-- IDX of sensor for speed value | STATION_ID='IDX_SENSOR'
SIDXSpeed = {K490003010='609'}
-- JSON.lua path
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
-- Curl path
curl = '/usr/bin/curl'
-- End of parameters
time = os.date("*t")
-- Function to update sensor
local function update(idx, value1)
local cmd = idx..'|0|'..value1
--print(cmd)
table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
-- function to get data from url
local function getdata(urlh,urls)
local DataHeight = assert(io.popen(curl..' -s "'..urlh..'"'))
local BlocJsonHeight = DataHeight:read('*all')
DataHeight:close()
local JsonHeight = json:decode(BlocJsonHeight)
local Height = JsonHeight.Serie.ObssHydro
local DataSpeed = assert(io.popen(curl..' -s "'..urls..'"'))
local BlocJsonSpeed = DataSpeed:read('*all')
DataSpeed:close()
local JsonSpeed = json:decode(BlocJsonSpeed)
local Speed = JsonSpeed.Serie.ObssHydro
return Height, Speed
end
local function test_error(url)
local DataTest = assert(io.popen(curl..' -s --max-time 8 "'..url..'"'))
local BlocJsonTest = DataTest:read('*all')
DataTest:close()
JsonTest = json:decode(BlocJsonTest)
Test = JsonTest[1].error_msg
end
commandArray = {}
if (time.min == 0 or time.min == 30) then
for k,v in pairs(Station) do
local IDStation = v
local IDXHeight = SIDXHeight[v]
local IDXSpeed = SIDXSpeed[v]
local urlHeight = 'https://www.vigicrues.gouv.fr/services/observations.json/index.php?CdStationHydro='..IDStation..'&GrdSerie=H&FormatSortie=simple'
local urlSpeed = 'https://www.vigicrues.gouv.fr/services/observations.json/index.php?CdStationHydro='..IDStation..'&GrdSerie=Q&FormatSortie=simple'
local status, retval = pcall(test_error,urlHeight);
if (status) then
print("Error, station inconnu")
commandArray['SendNotification']='subject#Erreur, station '..IDStation..' inconnu ou problème temporaire du site Vigicrue, merci de vérifier : '..urlHeight..'#0#sound#extradata#telegram'
else
ResultHeight,ResultSpeed=getdata(urlHeight,urlSpeed)
if (#ResultHeight ~= 0) then
if (debug) then print("ResultHeight: "..ResultHeight[#ResultHeight][2]) end
update(IDXHeight, ResultHeight[#ResultHeight][2])
else
if (debug) then print('Height level is empty.') end
end
if (#ResultSpeed ~= 0) then
if (debug) then print("ResultSpeed: "..ResultSpeed[#ResultSpeed][2]) end
update(IDXSpeed, ResultSpeed[#ResultSpeed][2])
else
if (debug) then print('Speed is empty.') end
end
end
end
end
return commandArray