Page 7 sur 8
Re: [LUA] Vigicrue
Publié : 12 oct. 2021, 14:04
par ebretteville
Bonjour,
Est-ce moi mais malgré le passage a
J'ai toujours les notifications dans telegram.
Re: [LUA] Vigicrue
Publié : 12 oct. 2021, 14:08
par chatainsim
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
Re: [LUA] Vigicrue
Publié : 12 oct. 2021, 14:12
par ebretteville
Ligne 76 plutôt non?!
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
Re: [LUA] Vigicrue
Publié : 12 oct. 2021, 14:17
par ebretteville
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
J'ai une vieille version....
Re: [LUA] Vigicrue
Publié : 12 oct. 2021, 14:31
par chatainsim
C'est dans le fichier vigicrue.json qu'il faut faire les modifs du coup
Mettre active a false
Re: [LUA] Vigicrue
Publié : 12 oct. 2021, 21:53
par ebretteville
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
Voilà le code et je ne comprends pas, pas d'erreurs dans les logs, mais mes devices ne sont pas updatés
Re: [LUA] Vigicrue
Publié : 14 oct. 2021, 10:35
par ebretteville
Un petit up car j'ai tenté le passage à vigicrue v2 et je n'arrive plus à faire fonctionner l'outil. Les idx sont à jours, l'id station actualisé (j'en ai qu'une à suivre, peut-être la syntaxe indiqué dans mon message précédent est inadapté), l'arborsecence pour le fichier LUA.json est actualisé.
Je ne vois pas ce qui peut ne pas fonctionner
Re: [LUA] Vigicrue
Publié : 14 oct. 2021, 10:47
par chatainsim
A priori tu avais bien déjà la V2, non ?
celle ci :
https://github.com/chatainsim/scripts_d ... icrue2.lua
Pas d'erreur dans les logs ?
as tu activé le mode debug ?
Après, je ne m'en sert plus depuis un moment.
Il faut que je replonge dans le code pour voir ce si côté vigicrue, leurs données ont changées.
Re: [LUA] Vigicrue
Publié : 14 oct. 2021, 10:54
par ebretteville
j'étais sans doutes sur la v1, non pas forcément d'erreurs dans les logs malgré les debug=true.
Je reste en vigilance sur le fil. Ce plugin lua en bord de rivière pour moi est un vrai plus j'avoue. Bravo pour le boulot
Re: [LUA] Vigicrue
Publié : 14 oct. 2021, 14:59
par chatainsim
Je viens de faire l'essai avec ta station et je n'ai pas de problème.
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
Est-ce que le chemin vers le fichier JSON.lua est le bon ?
Les IDX sont corrects ?
Edit: je viens de voir une erreur dans ton script :
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() <-- il te manque les deux parenthèses en fin de ligne