Re: [LUA] Horaires de marées
Publié : 01 déc. 2021, 22:03
A minima, son DomoticZ devrait tourner un peu mieux 
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
Code : Tout sélectionner
local scriptName = 'maree'
local scriptVersion = '2.0'
-- Dummy à créer :
local textDeviceIdx = 133
local port = 122
return {
active = false,
logging = {
level = domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting
marker = scriptName..' '..scriptVersion
},
on = {
timer = {'every 6 hours'},
httpResponses = {
scriptName,
},
},
execute = function(domoticz, item)
if item.isTimer then
local url = "http://horloge.maree.frbateaux.net/ws"..port..".js"
domoticz.log('Requesting data from maree.fr', domoticz.LOG_DEBUG)
domoticz.openURL({url = url, method = 'GET', callback = scriptName}).afterSec(7)
end
if not item.isHTTPResponse then return end
local response = item
if (not response.ok) or (response.trigger ~= scriptName) then
domoticz.log('Last http response was not what expected. Trigger: '..response.trigger, domoticz.LOG_ERROR)
domoticz.log(response.data, domoticz.LOG_ERROR)
return
end
if response.trigger == scriptName then
local horaires = ""
local coeff = ""
domoticz.log('maree data has been received', domoticz.LOG_DEBUG)
local contents = response.data
--domoticz.log('data : '..contents, domoticz.LOG_DEBUG)
for _,v in ipairs(response.lines) do
--domoticz.log(v)
if (string.find(tostring(v),"Coef")~= nil ) then
domoticz.log ("coeff : "..v:sub(46):gsub(";",""))
coeff = v:sub(46):gsub(";","")
end
if (string.find(tostring(v),"marégramme")~= nil ) then
domoticz.log ("horaires : "..v:sub(48,v:find("<div")-1):gsub("<b>",""):gsub("</b>",""):gsub("<br>"," "))
horaires = v:sub(48,v:find("<div")-1):gsub("<b>",""):gsub("</b>",""):gsub("<br>"," ")
end
end
domoticz.devices(textDeviceIdx).updateText('Coeff '..coeff.." "..horaires)
end
end
}
Code : Tout sélectionner
local scriptName = 'maree'
local scriptVersion = '2.0'
-- Dummy à créer :
local textDeviceIdx = 54
local port = 8
return {
active = true,
logging = {
level = domoticz.LOG_DEBUG, -- Uncomment to override the dzVents global logging setting
marker = scriptName..' '..scriptVersion
},
on = {
timer = {'every minute'},
-- timer = {'every 6 hours'},
httpResponses = {
scriptName,
},
},
execute = function(domoticz, item)
if item.isTimer then
local url = "http://horloge.maree.frbateaux.net/ws"..port..".js"
domoticz.log('Requesting data from maree.fr', domoticz.LOG_DEBUG)
domoticz.openURL({url = url, method = 'GET', callback = scriptName}).afterSec(7)
end
if not item.isHTTPResponse then return end
local response = item
if (not response.ok) or (response.trigger ~= scriptName) then
domoticz.log('Last http response was not what expected. Trigger: '..response.trigger, domoticz.LOG_ERROR)
domoticz.log(response.data, domoticz.LOG_ERROR)
return
end
if response.trigger == scriptName then
local horaires = ""
local coeff = ""
domoticz.log('maree data has been received', domoticz.LOG_DEBUG)
local contents = response.data
domoticz.log('data : '..contents, domoticz.LOG_DEBUG)
for _, v in ipairs(response.lines) do
--domoticz.log(v)
if (string.find(tostring(v),"Coef")~= nil ) then
domoticz.log ("coeff : "..v:sub(46):gsub(";",""))
coeff = v:sub(46):gsub(";","")
end
if (string.find(tostring(v),"marégramme")~= nil ) then
domoticz.log ("horaires : "..v:sub(48,v:find("<div")-1):gsub("<b>",""):gsub("</b>",""):gsub("<br>"," "))
horaires = v:sub(48,v:find("<div")-1):gsub("<b>",""):gsub("</b>",""):gsub("<br>"," ")
end
end
domoticz.devices(textDeviceIdx).updateText('Coeff '..coeff.." "..horaires)
end
end
}Code : Tout sélectionner
2021-12-06 12:13:00.483 Status: dzVents: Info: maree 2.0: ------ Start internal script: maree_coef:, trigger: every minute
2021-12-06 12:13:00.483 Status: dzVents: Debug: maree 2.0: Requesting data from maree.fr
2021-12-06 12:13:00.483 Status: dzVents: Debug: maree 2.0: OpenURL: url = http://horloge.maree.frbateaux.net/ws8.js
2021-12-06 12:13:00.484 Status: dzVents: Debug: maree 2.0: OpenURL: method = GET
2021-12-06 12:13:00.484 Status: dzVents: Debug: maree 2.0: OpenURL: post data = nil
2021-12-06 12:13:00.484 Status: dzVents: Debug: maree 2.0: OpenURL: headers = nil
2021-12-06 12:13:00.484 Status: dzVents: Debug: maree 2.0: OpenURL: callback = maree
2021-12-06 12:13:00.484 Status: dzVents: Info: maree 2.0: ------ Finished maree_coef
2021-12-06 12:13:07.757 Status: dzVents: Info: Handling httpResponse-events for: "maree
2021-12-06 12:13:07.757 Status: dzVents: Info: maree 2.0: ------ Start internal script: maree_coef: HTTPResponse: "maree"
2021-12-06 12:13:07.758 Status: dzVents: Debug: maree 2.0: maree data has been received
2021-12-06 12:13:07.758 Status: dzVents: Debug: maree 2.0: data : //Horloge
2021-12-06 12:13:07.758 document.getElementById( "Aiguille" ).title="Cliquez pour plus de détails sur la marée du jour";
2021-12-06 12:13:07.758 <b>PM 13h00</b><div title=\"Cliquez pour afficher le marégramme et les prédictions des marées sur 7 jours\">+ d'info</div>";
2021-12-06 12:13:07.758 Status: dzVents: Info: maree 2.0: ------ Finished maree_coef
2021-12-06 12:13:07.758 Error: dzVents: Error: (2.4.28) maree 2.0: An error occurred when calling event handler maree_coef
2021-12-06 12:13:07.758 Error: dzVents: Error: (2.4.28) maree 2.0: ...omoticz/scripts/dzVents/generated_scripts/maree_coef.lua:47: bad argument #1 to 'ipairs' (table expected, got nil)