Page 2 sur 11

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 16 avr. 2023, 14:58
par MAidEN91
Dans ma requete JSON j'ai bien l'air de tour récupérer oui c'est pour ca que je pige pas pourquoi via le script ca ne passe pas :
[{"datetime":"2023-04-16","datetimeEpoch":1681596000,"tempmax":13.9,"tempmin":7.1,"temp":11.6,"feelslikemax":13.9,"feelslikemin":6.1,"feelslike":11.4,"dew":4.6,"humidity":62.8,"precip":0.0,"precipprob":0.0,"precipcover":0.0,"preciptype":null,"snow":0.0,"snowdepth":0.0,"windgust":34.6,"windspeed":19.8,"winddir":7.6,"pressure":1025.0,"cloudcover":83.8,"visibility":24.1,"solarradiation":368.7,"solarenergy":13.4,"uvindex":7.0,"severerisk":10.0,"sunrise":"06:59:55","sunriseEpoch":1681621195,"sunset":"20:43:23","sunsetEpoch":1681670603,"moonphase":0.87,"conditions":"Partially cloudy","description":"Becoming cloudy in the afternoon.","icon":"partly-cloudy-day","stations":null,"source":"fcst"}],"stations":{"AU951":{"distance":18969.0,"latitude":48.599,"longitude":2.064,"useCount":0,"id":"AU951","name":"F5POE Forges-les-bains FR","quality":0,"contribution":0.0},"LFPO":{"distance":35385.0,"latitude":48.73,"longitude":2.4,"useCount":0,"id":"LFPO","name":"LFPO","quality":49,"contribution":0.0},"LFPN":{"distance":34043.0,"latitude":48.75,"longitude":2.12,"useCount":0,"id":"LFPN","name":"LFPN","quality":50,"contribution":0.0}},"currentConditions":{"datetime":"14:35:00","datetimeEpoch":1681648500,"temp":15.0,"feelslike":15.0,"humidity":46.5,"dew":3.6,"precip":0.0,"precipprob":0.0,"snow":0.0,"snowdepth":0.0,"preciptype":null,"windgust":null,"windspeed":24.1,"winddir":355.0,"pressure":1025.0,"visibility":10.0,"cloudcover":88.0,"solarradiation":745.0,"solarenergy":2.7,"uvindex":7.0,"conditions":"Partially cloudy","icon":"partly-cloudy-day","stations":["AU951","LFPO","LFPN"],"source":"obs","sunrise":"06:59:55","sunriseEpoch":1681621195,"sunset":"20:43:23","sunsetEpoch":1681670603,"moonphase":0.87}}

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 16 avr. 2023, 18:06
par Keros
Je n'arrive pas à lire ton Json. Enregistre-le sous un fichier .json et ajoute-le à ton message (onglet fichier joint en dessous de la zonne de rédaction).

Tu n'as pas d'erreurs dans les logs de DomoticZ ?

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 17 avr. 2023, 10:03
par lost
Pour info, le PR intégrant nativement Visual Crossing a été intégré ce matin en béta, avec d'autres corrections mineures... Et OZW est toujours là pour ceux qui se refusent toujours à passer à ZwajeJS.

Probable que les build soient déjà dispo, je devrais faire la MAJ demain si j'ai un peu de temps.

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 17 avr. 2023, 11:41
par MAidEN91
Voici le fichier (ca correspond a la requete test d'exemple que tu as mis dans ton post) que j'ai custom avec ma KEY API et ma ville.

Au niveau de mes logs j'ai cette erreur qui correspond au Barometre et qui persiste, j'ai testé plusieurs types de widgets de type Barometre au cas ou mais ca ne change rien :
2023-04-17 11:40:06.232 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: There is no device with that name or id: Barometre
2023-04-17 11:40:06.232 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: An error occurred when calling event handler weathervisualcrossing
2023-04-17 11:40:06.232 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: ...moticz/scripts/dzVents/scripts/weathervisualcrossing.lua:52: attempt to index a nil value
Merci pour ton aide car la je galère :roll:

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 17 avr. 2023, 11:52
par Keros
Tu n'aurais pas deux widgets avec le même nom ?

Tu pourrais lancer cette adresse IP_domoticz:Port/json.htm?type=devices&rid=IDX dans ton navigateur en mettant l'adresse de DomoticZ et le numéro Idx de ton widget barometre et nous mettre le Json en pièce jointe.

Mets-nous également ton script en entier stp.

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 17 avr. 2023, 12:38
par MAidEN91
Voila ;)

Code : Tout sélectionner

--[[ --[[ ~/home/pi/domoticz/scripts/dzVents/scripts/weathervisualcrossing.lua

author : gso
       : modifié pour weathervisualcrossing par BernardC
MAJ : 11/04/2023
création : 24/03/2023
Principe :
lien pour inscription à  weather visual crossing:
https://www.visualcrossing.com/sign-up
lien pour récupérer la clé:
https://www.visualcrossing.com/account
requête type pour remplacer DarkSky API pour La localitée "Le Mans" dans Sarthe
https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/Le%20Mans/today?unitGroup=metric&include=fcst%2Ccurrent&key=<votre cle API>&options=nonulls&contentType=json
}

]]--

local scriptName = 'weather.visualcrossing'
local scriptVersion = '1.1'

--[[**********************************************
--      les 2 variables à renseigner 
--       suivant utilisateur
--**********************************************]]--
local Localite = 'morigny%20champigny'
local apiKey = 'ma clé' 
--**********************************************
--local uri = 'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/'..Localite..'?unitGroup=metric&include=events%2Cdays%2Ccurrent%2Chours%2Calerts&key='..apiKey..'&contentType=json'
local uri = 'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/'..Localite..'/today?unitGroup=metric&include=fcst%2Ccurrent&key='..apiKey..'&options=nonulls&contentType=json'

local prefix = 'WVC'

local StMeteo = { -- devices idx (à modifier en conséquence), fonction de maj donnée devices domoticz

    -- {idx = 0, cde = function (dz, idx, v) dz.devices(idx).updateTempHum(v.currentConditions.temp, v.currentConditions.humidity, dz.HUM_COMPUTE) end },
    -- Dew Point (°C) point rosée
    -- {idx = 0,   cde = function (dz, idx, v) dz.devices(idx).updateTemperature(v.currentConditions.dew) end },
   
    -- Pression amosphérique 
    --{idx = 0, cde = function (dz, idx, v) dz.devices(idx).updatePressure(v.currentConditions.pressure) end }, 

    --THB  Barometre
    {idx = 'Barometre', cde = function (dz, idx, v) 
        local precipprobr= v.currentConditions.precipprob -- probability of precipitation for tomorrow
        local clouds = v.currentConditions.cloudcover
        local baro = dz.BARO_NOINFO
        if v.currentConditions.precipprob >= 0.3 then baro = dz.BARO_RAIN
            elseif clouds >= 75 then baro = dz.BARO_CLOUDY
            elseif clouds >= 25 then baro = dz.BARO_PARTLYCLOUDY   -- et pas  BARO_PARTLY_CLOUDY comme dans wiki ??
            else baro = dz.BARO_SUNNY
        end
        dz.devices(idx).updateTempHumBaro(v.currentConditions.temp,v.currentConditions.humidity,dz.HUM_COMPUTE,v.currentConditions.pressure,baro)
    end },
   
    -- UV 
    {idx = 'UV', cde = function (dz, idx, v) dz.devices(idx).updateUV(v.currentConditions.uvindex) end },
    
    -- Couverture nuageuse
    {idx = 'Couverture nuageuse', cde = function (dz, idx, v) dz.devices(idx).updatePercentage(v.currentConditions.cloudcover) end },
    
    -- Visibilité en (km) 
    {idx = 'Visibilite', cde = function (dz, idx, v) dz.devices(idx).updateVisibility(v.currentConditions.visibility) end }, 

       -- Pluie  MAJ le 11/04/2023
    {idx = 'Pluie',  cde = function (dz, idx, v)
        if v.currentConditions.precip == nil then v.currentConditions.precip = 0 end
        if v.days[1].precip == nil then v.v.days[1].precip = 0 end
        --(hauteur en mm * 100 par heure, le compteur est total en mm)     
        dz.devices(idx).updateRain(v.currentConditions.precip*100, v.days[1].precip)
    end }, 

    -- Vent en m/s MAJ le 11/04/2023
    {idx = 'Vent', cde = function (dz, idx, v)  
        if v.currentConditions.windgust == nil then  v.currentConditions.windsgust = v.days[1].windgust end    
        degrees = v.currentConditions.winddir
        local quadrants = {"NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW"}
        local quad = 'N'
        if degrees <= 348.75 and degrees > 11.25 then quad = quadrants[tonumber(math.floor((degrees - 11.25) / 22.5)+1)] end
        dz.devices(idx).updateWind(degrees, quad, v.currentConditions.windspeed/3.6, v.currentConditions.windgust/3.6, v.currentConditions.temp, v.currentConditions.feelslike)
        -- bearing(°), direction(N S NNW..), speed(m/s), gust(m/s), temperature(°C), chill(°C)
        -- vitesse vent/3,6 pour adapter l'affichage, les données reçu sont en Km/H
    end },
    
--[[  -- devices à modifier pour l'ajout 
   
    -- Snow
    {idx = 'Neige',    cde = function (dz, idx, v) 
        if v.current.snow ~= nil  then dz.devices(idx).updateRain(v.current.snow['1h']*100, v.daily[1].snow)
        elseif v.daily[1] ~= nil then dz.devices(idx).updateRain(0, v.daily[1].snow) 
        else dz.devices(idx).updateRain(0, 0) end
    end }, --rate in mm * 100 per hour, counter is total in mm)
    
    -- Meteo
    {idx = Meteo,  cde = function (dz, idx, v)
        local txt = v.current.weather[1].description..' ('..v.current.weather[1].main..' - '..v.current.weather[1].id..')'
        dz.devices(idx).updateText(txt)
    end },
    
    -- Moon
    {idx = 'Lune',  cde = function (dz, idx, v)
        -- local dt  = os.date("%a %d %b à %X", v.daily[1].dt) -- UTC
        local moonrise  = os.date("%Hh%M", v.daily[1].moonrise) -- UTC
        local moonset   = os.date("%Hh%M", v.daily[1].moonset) -- UTC
        local p = v.daily[1].moon_phase*100 -- 0 and 1 are 'new moon', 0.25 is 'first quarter moon', 0.5 is 'full moon' and 0.75 is 'last quarter moon'.
        if p==0 or p==100 then phase = "Nouvelle Lune ?"
        elseif p<25     then phase = "Premier Croissant ?"
        elseif p==25    then phase = "Premier Quartier ?"
        elseif p<50     then phase = "Gibeuse Croissante ?"
        elseif p==50    then phase = "Pleine Lune  ?"
        elseif p<75     then phase = "Gibeuse Décroissante  ?"
        elseif p==75    then phase = "Dernier Quartier  ?"
        elseif p<100    then phase = "Dernier Croissant  ?"
        end
        -- luminosity
        p = 2*p 
        if p>100 then p = 200-p end
        local txt = "Lever à "..moonrise.."\nCoucher à  "..moonset.."\nPhase : "..phase.."  ("..p.."%)"
        dz.devices(idx).updateText(txt)
    end },
    
    -- Moon Phase (%)
    {idx = 'Lune phase',  cde = function (dz, idx, v)
        dz.devices(idx).updatePercentage(v.daily[1].moon_phase*100)
    end },
    
    -- Alerts
    --,"alerts":[{"sender_name":"METEO-FRANCE","event":"Moderate thunderstorm warning","start":1680321640,"end":1680386400,"description":"Moderate damages may occur, especially in vulnerable or in exposed areas and to people who carry out weather-related activities.","tags":["Thunderstorm"]}]}	

    {idx = 'Alerte', cde = function (dz, idx, v)
        if v.alerts ~= nil then
            local txt = ''
            for k, alert in ipairs(v.alerts) do
                local from  = os.date("%a %d %b à %X", alert['start'])
                local to    = os.date("%a %d %b à %X", alert['end'])
                txt = txt..k..'. '..alert.event.."\n"
                txt = txt..'   du '..from.."\n"
                txt = txt..'   au '..to.."\n"
                txt = txt..alert.description.."\n"
                -- txt = txt..alert.sender_name -- Meteo France
                txt = txt..'  tags : '..table.concat(alert.tags, ', ')..'\n\n'
            end
            -- updateAlertSensor(level, text): Function. Level can be domoticz.ALERTLEVEL_GREY, ALERTLEVEL_GREEN, ALERTLEVEL_YELLOW, ALERTLEVEL_ORANGE, ALERTLEVEL_RED. Supports command options.
            dz.devices(idx).updateAlertSensor(dz.ALERTLEVEL_RED, txt)
            dz.notify('Alerte Météo', txt, dz.PRIORITY_HIGH) -- notify(subject, message, priority, sound) domoticz.PRIORITY_LOW, PRIORITY_MODERATE, PRIORITY_NORMAL, PRIORITY_HIGH, PRIORITY_EMERGENCY
        else
            dz.devices(idx).updateAlertSensor(dz.ALERTLEVEL_GREEN, "Pas d'alerte")
        end 
    end },
]]--
}


-- LOOP
return {

    active =  true, -- false,
    on = {
        timer           = { "every 5 minutes" },
        httpResponses   = { "OWMcallback" }, -- correspond au caractère générique de rappel
    },

    logging = {   
        level  =   domoticz.LOG_ERROR, domoticz.LOG_INFO, --, domoticz.LOG_DEBUG, domoticz.LOG_MODULE_EXEC_INFO
        marker = '-- '..scriptName..' v'..scriptVersion
    },

    -- LOOP
    execute = function(dz, triggerItem)
        
        
        
        local function errorMessage(message,notify)   -- Ajouter une entrée au journal et notifier à tous les sous-systèmes
            dz.log(message, dz.LOG_ERROR)
            if notify then
                -- dz.notify(message) -- notify(subject, message, priority, sound): Fonction. Envoi d’une notification (Prowl). La priorité sera choisie entre  domoticz.PRIORITY_LOW, PRIORITY_MODERATE, PRIORITY_NORMAL, PRIORITY_HIGH, PRIORITY_EMERGENCY
            end
         end

        -- MAIN
        if triggerItem.isTimer then
            local url = uri
            dz.openURL({
                url     = url,
                method  = "GET",
                callback= 'OWMcallback'
            }).afterSec(1)
        end

        if triggerItem.isHTTPResponse then
            if triggerItem.ok and triggerItem.isJSON then
                local resultsTable = triggerItem.json
                print('reception de weathervisualcrossing')
                if resultsTable ~= nil and resultsTable.currentConditions ~= nil then
                    for k, d in ipairs(StMeteo) do
                        if d['idx'] ~= 0 then --0
                            d.cde(dz, d['idx'], resultsTable) 
                        end
                    end
                end
            else
                errorMessage("Probleme avec la reponse de weathervisualcrossing", false)
            end
        end
    
    end --execute
}


Et voici la derniere erreur quand je recréer un widget barometre (j'en ai bien que 1 seul avec ce nom) :

Code : Tout sélectionner

2023-04-17 12:40:05.627 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: Method updateTempHumBaro is not available for device "Barometre" (deviceType=Temp + Humidity, deviceSubType=THGN122/123/132, THGR122/228/238/268). If you believe this is not correct, please report.
2023-04-17 12:40:05.637 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: An error occurred when calling event handler weathervisualcrossing
2023-04-17 12:40:05.637 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: ...moticz/scripts/dzVents/scripts/weathervisualcrossing.lua:79: attempt to perform arithmetic on a nil value (field 'windgust')

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 17 avr. 2023, 13:09
par Keros
Ton widget est de type Temp + Hum. Il faut un Temp + Hum + Bar. Supprime-le et recréer-le.

Remet nous le Json.
Relance le script.
Mets nous les log

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 17 avr. 2023, 13:21
par MAidEN91
Voila avec le widget temp+hum+baro

Code : Tout sélectionner

2023-04-17 13:20:06.565 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: No status provided. Temperature + humidity not set
2023-04-17 13:20:06.574 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: An error occurred when calling event handler weathervisualcrossing
2023-04-17 13:20:06.574 Error: dzVents: Error: (2.5.3) -- weather.visualcrossing v1.1: ...moticz/scripts/dzVents/scripts/weathervisualcrossing.lua:79: attempt to perform arithmetic on a nil value (field 'windgust')

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 17 avr. 2023, 16:32
par Jeff
Un temp hum baro a besoin de 5 valeurs

Code : Tout sélectionner

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT;BAR;BAR_FOR

Re: [DzVents] Données Météo Weather Visual Crossing

Publié : 17 avr. 2023, 17:08
par Keros
Il y aurait bien les 5 Jeff :

Code : Tout sélectionner

dz.devices(idx).updateTempHumBaro(v.currentConditions.temp,v.currentConditions.humidity,dz.HUM_COMPUTE,v.currentConditions.pressure,baro)
Je pense que le problème est maintenant sur un autre Widget. Il faut que je teste le script.