Page 6 sur 18
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 21:40
par vr6man
j'ai ca
level = domoticz.LOG_DEBUG,
2019-03-06 21:39:00.748 Status: dzVents: Info: Darksky Rain Probability v1.0 : ------ Start external script: prevision pluie.lua:, trigger: every 3 minutes
2019-03-06 21:39:00.748 Status: dzVents: Error (2.4.6): Darksky Rain Probability v1.0 : There is no uservariable with that name or id: api_forecast_io
2019-03-06 21:39:00.748 Status: dzVents: Error (2.4.6): Darksky Rain Probability v1.0 : An error occured when calling event handler prevision pluie
2019-03-06 21:39:00.749 Status: dzVents: Error (2.4.6): Darksky Rain Probability v1.0 : .../pi/domoticz/scripts/dzVents/scripts/prevision pluie.lua:67: attempt to index a nil value
2019-03-06 21:39:00.749 Status: dzVents: Info: Darksky Rain Probability v1.0 : ------ Finished prevision pluie.lua
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 21:53
par denis_brasseur
Reprend tout depuis le debut, tu n'a pas la variable api_forecast_io.
Reprend le post depuis le debut et dans sa totalité
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 22:00
par vr6man
j'ai tout relu mais je ne vois pas parler de api_forecast_io
que faut il que je créé en plus et ou ?
merci
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 22:06
par denis_brasseur
Relis le premier post de papoo, tout y est, le nom des devices, l'utilisation de l'idx, le fonctionement toute les 30 mn et les variables.
Ainsi que proba_pluie_h
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 22:10
par vr6man
Comme dis jai tout relu je ne vois pas ou je ne comprends pas
peux tu me dire ce que je dois faire de plus que mon script ?
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 22:18
par papoo
papoo a écrit : 17 sept. 2018, 17:58
la clé secrète DarkSky, la latitude et la longitude de mon domicile sont contenus dans 3 variables utilisateurs
Code : Tout sélectionner
local DarkSkyAPIkey = domoticz.variables('api_forecast_io').value
local geolocalisation = domoticz.variables('Latitude').value..","..domoticz.variables('Longitude').value
si vous souhaitez inscrire ces informations dans le script, commentez les deux lignes ci-dessus, décommentez les deux lignes suivantes :
Code : Tout sélectionner
--local DarkSkyAPIkey = "1a2bf34bf56c78901f2345f6d7890f12"
--local geolocalisation = "45.87,1.30" -- latitude,longitude
en les personnalisant avec vos données personnelles
soit tu créé 3 variables utilisateurs (réglages => pluis d'options => variables utilisateurs) dans lesquels tu stockes ton api, ta lattitude et ta longitude
soit tu commente les deux lignes appelant les variables utilisateurs et tu renseignes ces informations directement dans le script en decommentant comme indiqué
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 22:22
par vr6man
papoo
je comprends pas l'erreur
ma clé API et les longitude sont dans le script:
Code : Tout sélectionner
--[[ darksky.lua for [ domoticzVents >= 2.4 ]
author/auteur = papoo
update/mise à jour = 15/09/2018
creation = 15/09/2018
https://pon.fr/dzvents-darksky-et-probabilite-de-pluie/
This script requires prior registration to the DarkSky API
Ce script nécessite l'inscription préalable à l'API DarkSky
Enter the URL and request a free API key
Entrez l'URL et demandez une clé API gratuite
https://darksky.net/dev
]]--
local proba_pluie_h = {}
--[[
Add, modify or delete variables proba_pluie_h [] by changing the number (hour) between []
the name "in quotation marks" or the idx without quotes (avoid accents) of the device of percentage of rain at [x] associated time, nil if not used
This script can potentially retrieve the 48 available time forecasts. Create as many percent virtual sensors as you would expect from the hourly forecasts.
for my part, I only get the forecasts at 1 hour, 2 hours, 4 hours, 6 hours, 12 hours and 24 hours.
Only 48 possible forecasts
Ajoutez, modifiez ou supprimez les variables proba_pluie_h[] en changeant le nombre (heure) entre []
renseigner ensuite le nom "entre guillemets" ou l'idx sans guillemets (évitez les accents) du device pourcentage probabilité pluie à [x] heure associé, nil si non utilisé
Ce script peut potentiellement récupérer les 48 prévisions horaires disponible. Créez autant de capteurs virtuels pourcentage correspondant aux prévisions horaires que vous souhaitez.
pour ma part, je ne récupère que les prévisions à 1 heure, 2 heures, 4 heures, 6 heures, 12 heures et 24 heures.
Seulement 48 prévisions possible
My DarkSky secret key, the latitude and longitude of my home are contained in 3 user variables
Ma clé secrète DarkSky, la latitude et la longitude de mon domicile sont contenus dans 3 variables utilisateurs
local DarkSkyAPIkey = domoticz.variables('api_forecast_io').value
local geolocalisation = domoticz.variables('Latitude').value..","..domoticz.variables('Longitude').value
If you want to enter this information directly into the script, comment on the two lines above, uncomment the following two lines
Si vous souhaitez inscrire ces informations dans le script, commentez les deux lignes ci-dessus, décommentez les deux lignes suivantes
--local DarkSkyAPIkey = "1a2bf34bf56c78901f2345f6d7890f12"
--local geolocalisation = "45.87,1.30" -- latitude,longitude
by personalizing them with your personal data
finally, you can choose the level of logs, only one level can be active; comment on others in the section
en les personnalisant avec vos données personnelles.
enfin vous pouvez choisir le niveau de "verbiage" des logs, seulement un niveau peut être actif; commenter les autres dans la section logging
]]--
proba_pluie_h[1]= "Proba Pluie 1h"
proba_pluie_h[2]= nil
proba_pluie_h[3]= nil
proba_pluie_h[4]= "Proba Pluie 4h"
proba_pluie_h[5]= nil
proba_pluie_h[6]= nil
proba_pluie_h[12]= "Proba Pluie 12h"
proba_pluie_h[24]= "Proba Pluie 24h"
proba_pluie_h[36]= nil
proba_pluie_h[48]= nil
return {
active = true,
on = { timer = { 'every 3 minutes' }, -- remember only 1000 requests by day, 30mn = 48 requests
httpResponses = { "trigger" } -- Trigger the handle Json part
},
logging = { -- level = domoticz.LOG_INFO, -- Seulement un niveau peut être actif; commenter les autres
-- level = domoticz.LOG_ERROR, -- Only one level can be active; comment others
level = domoticz.LOG_DEBUG,
-- level = domoticz.LOG_MODULE_EXEC_INFO,
marker = "Darksky Rain Probability v1.0 " },
data = { rainForecast = {initial = {} }, -- Keep a copy of last json just in case
},
execute = function(domoticz, item)
local DarkSkyAPIkey = domoticz.variables('api_forecast_io').value
local geolocalisation = domoticz.variables('Latitude').value..","..domoticz.variables('Longitude').value
local DarkSkyAPIkey = "xxxxxx"
local geolocalisation = "47.896976,0.034682" -- latitude,longitude
local Forecast_url = "https://api.darksky.net/forecast/" -- url
local extraData = "?units=ca&exclude=currently,minutely,daily,alerts,flags"
local function debugMessage(message)
domoticz.log(message,domoticz.LOG_DEBUG)
end
if (item.isTimer) then
domoticz.openURL({
url = Forecast_url..DarkSkyAPIkey.."/"..geolocalisation..extraData,
callback = 'trigger'
})
end
if (item.isHTTPResponse and item.ok) then
-- we know it is json but dzVents cannot detect this
-- convert to Lua
local json = domoticz.utils.fromJSON(item.data)
-- json is now a Lua table
if #item.data > 0 then
domoticz.data.rainForecast = domoticz.utils.fromJSON(item.data)
rt = domoticz.utils.fromJSON(item.data)
else
domoticz.log("Problem with response from DarkSky (no data) using data from earlier run",domoticz.LOG_ERROR)
rt = domoticz.data.rainForecast -- json empty. Get last valid from domoticz.data
if #rt < 1 then -- No valid data in domoticz.data either
domoticz.log("No previous data. are DarkSkyAPIkey and geolocalisation ok?",domoticz.LOG_ERROR)
return false
end
end
debugMessage("heure systeme")
debugMessage(os.date('%Y-%m-%d %H:%M:%S', time))
local now = tonumber(os.time(os.date("*t")))
j = 1
for i = 1,48 do
if now > tonumber(json.hourly.data[j].time) then
local h = domoticz.utils.round((now - tonumber(json.hourly.data[j].time)) / 3600,0)
j = j+h
debugMessage("j : "..j)
end
if proba_pluie_h[i] then
debugMessage("heure "..i)
debugMessage(os.date('%Y-%m-%d %H:%M:%S', json.hourly.data[j].time))
debugMessage(json.hourly.data[j].time)
debugMessage(json.hourly.data[j].precipProbability)
domoticz.devices(proba_pluie_h[i]).updatePercentage(json.hourly.data[j].precipProbability*100)
end
if j == 48 then break end
j = j +1
end
end
end
}
qu'est ce que je dois faire de plus ?
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 22:23
par papoo
correction
Code : Tout sélectionner
--[[ darksky.lua for [ domoticzVents >= 2.4 ]
author/auteur = papoo
update/mise à jour = 15/09/2018
creation = 15/09/2018
https://pon.fr/dzvents-darksky-et-probabilite-de-pluie/
This script requires prior registration to the DarkSky API
Ce script nécessite l'inscription préalable à l'API DarkSky
Enter the URL and request a free API key
Entrez l'URL et demandez une clé API gratuite
https://darksky.net/dev
]]--
local proba_pluie_h = {}
--[[
Add, modify or delete variables proba_pluie_h [] by changing the number (hour) between []
the name "in quotation marks" or the idx without quotes (avoid accents) of the device of percentage of rain at [x] associated time, nil if not used
This script can potentially retrieve the 48 available time forecasts. Create as many percent virtual sensors as you would expect from the hourly forecasts.
for my part, I only get the forecasts at 1 hour, 2 hours, 4 hours, 6 hours, 12 hours and 24 hours.
Only 48 possible forecasts
Ajoutez, modifiez ou supprimez les variables proba_pluie_h[] en changeant le nombre (heure) entre []
renseigner ensuite le nom "entre guillemets" ou l'idx sans guillemets (évitez les accents) du device pourcentage probabilité pluie à [x] heure associé, nil si non utilisé
Ce script peut potentiellement récupérer les 48 prévisions horaires disponible. Créez autant de capteurs virtuels pourcentage correspondant aux prévisions horaires que vous souhaitez.
pour ma part, je ne récupère que les prévisions à 1 heure, 2 heures, 4 heures, 6 heures, 12 heures et 24 heures.
Seulement 48 prévisions possible
My DarkSky secret key, the latitude and longitude of my home are contained in 3 user variables
Ma clé secrète DarkSky, la latitude et la longitude de mon domicile sont contenus dans 3 variables utilisateurs
--local DarkSkyAPIkey = domoticz.variables('api_forecast_io').value
--local geolocalisation = domoticz.variables('Latitude').value..","..domoticz.variables('Longitude').value
If you want to enter this information directly into the script, comment on the two lines above, uncomment the following two lines
Si vous souhaitez inscrire ces informations dans le script, commentez les deux lignes ci-dessus, décommentez les deux lignes suivantes
local DarkSkyAPIkey = "1a2bf34bf56c78901f2345f6d7890f12"
local geolocalisation = "45.87,1.30" -- latitude,longitude
by personalizing them with your personal data
finally, you can choose the level of logs, only one level can be active; comment on others in the section
en les personnalisant avec vos données personnelles.
enfin vous pouvez choisir le niveau de "verbiage" des logs, seulement un niveau peut être actif; commenter les autres dans la section logging
]]--
proba_pluie_h[1]= "Proba Pluie 1h"
proba_pluie_h[2]= nil
proba_pluie_h[3]= nil
proba_pluie_h[4]= "Proba Pluie 4h"
proba_pluie_h[5]= nil
proba_pluie_h[6]= nil
proba_pluie_h[12]= "Proba Pluie 12h"
proba_pluie_h[24]= "Proba Pluie 24h"
proba_pluie_h[36]= nil
proba_pluie_h[48]= nil
return {
active = true,
on = { timer = { 'every 3 minutes' }, -- remember only 1000 requests by day, 30mn = 48 requests
httpResponses = { "trigger" } -- Trigger the handle Json part
},
logging = { -- level = domoticz.LOG_INFO, -- Seulement un niveau peut être actif; commenter les autres
-- level = domoticz.LOG_ERROR, -- Only one level can be active; comment others
level = domoticz.LOG_DEBUG,
-- level = domoticz.LOG_MODULE_EXEC_INFO,
marker = "Darksky Rain Probability v1.0 " },
data = { rainForecast = {initial = {} }, -- Keep a copy of last json just in case
},
execute = function(domoticz, item)
local DarkSkyAPIkey = domoticz.variables('api_forecast_io').value
local geolocalisation = domoticz.variables('Latitude').value..","..domoticz.variables('Longitude').value
local DarkSkyAPIkey = "xxxxxx"
local geolocalisation = "47.896976,0.034682" -- latitude,longitude
local Forecast_url = "https://api.darksky.net/forecast/" -- url
local extraData = "?units=ca&exclude=currently,minutely,daily,alerts,flags"
local function debugMessage(message)
domoticz.log(message,domoticz.LOG_DEBUG)
end
if (item.isTimer) then
domoticz.openURL({
url = Forecast_url..DarkSkyAPIkey.."/"..geolocalisation..extraData,
callback = 'trigger'
})
end
if (item.isHTTPResponse and item.ok) then
-- we know it is json but dzVents cannot detect this
-- convert to Lua
local json = domoticz.utils.fromJSON(item.data)
-- json is now a Lua table
if #item.data > 0 then
domoticz.data.rainForecast = domoticz.utils.fromJSON(item.data)
rt = domoticz.utils.fromJSON(item.data)
else
domoticz.log("Problem with response from DarkSky (no data) using data from earlier run",domoticz.LOG_ERROR)
rt = domoticz.data.rainForecast -- json empty. Get last valid from domoticz.data
if #rt < 1 then -- No valid data in domoticz.data either
domoticz.log("No previous data. are DarkSkyAPIkey and geolocalisation ok?",domoticz.LOG_ERROR)
return false
end
end
debugMessage("heure systeme")
debugMessage(os.date('%Y-%m-%d %H:%M:%S', time))
local now = tonumber(os.time(os.date("*t")))
j = 1
for i = 1,48 do
if now > tonumber(json.hourly.data[j].time) then
local h = domoticz.utils.round((now - tonumber(json.hourly.data[j].time)) / 3600,0)
j = j+h
debugMessage("j : "..j)
end
if proba_pluie_h[i] then
debugMessage("heure "..i)
debugMessage(os.date('%Y-%m-%d %H:%M:%S', json.hourly.data[j].time))
debugMessage(json.hourly.data[j].time)
debugMessage(json.hourly.data[j].precipProbability)
domoticz.devices(proba_pluie_h[i]).updatePercentage(json.hourly.data[j].precipProbability*100)
end
if j == 48 then break end
j = j +1
end
end
end
}
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 22:25
par papoo
tu n'as pas commenté les lignes appelant les variables utilisateur ni decommenté les variables local, ça ne pouvait pas fonctionner
commenter une ligne => ajouter deux tirets -- devant la ligne concernée
décommenter une ligne => retirer les deux tirets devant la ligne concernée
Re: DZVents : DarkSky et probabilité de pluie
Publié : 06 mars 2019, 22:29
par vr6man
ok donc il me faut juste faire :
Code : Tout sélectionner
--local DarkSkyAPIkey = domoticz.variables('api_forecast_io').value
--local geolocalisation = domoticz.variables('Latitude').value..","..domoticz.variables('Longitude').value
local DarkSkyAPIkey = "xxxxxxx"
local geolocalisation = "47.896976,0.034682" -- latitude,longitude