Meteoconcept

Posez ici vos questions d'utilisation, de configuration de DomoticZ, de bugs, de conseils sur le logiciel lui même dans son utilisation et son paramétrage.
Des forums spécifiques sont ouverts ci-dessous pour regrouper les différents sujets.
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: Meteoconcept

Message par Neutrino »

Les limitations sont sur les commandes shell. Logique en soit.
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
will
Messages : 32
Inscription : 01 nov. 2018, 19:26

Re: Meteoconcept

Message par will »

Bonjour,

J'avance un peu dans la réalisation du script et l'apprentissage de dz vent mais y'a quelque choses qui cloche

Je comprend pas encore tous de ce script mais la chaine XML semble posé un problème :?:

Code : Tout sélectionner

return 
{
	on = 
	{
		timer = {
			'every 1 minutes' -- just an example to trigger the request
		},
		httpResponses = {
			'trigger' -- must match with the callback passed to the openURL command
		}
	},
	logging = 
	{
		level = domoticz.LOG_INFO,
		marker = 'template',
	},
	
	execute = function(domoticz, item)
        if item.isTimer then
			domoticz.openURL(
		 {
				url = 'https://api.meteo-concept.com/api/forecast/daily/0?token=XXX&insee=XXX',
				method = 'GET',
				callback = 'trigger', -- see httpResponses above.
			})

			elseif item.ok then -- statusCode == 2xx
			local rt =  domoticz.utils.fromXML(item.data)
			
			domoticz.utils.dumpTable(rt)
            local dsl = rt.rsp.dsl._attr
            
            -- get one value
            domoticz.log('line-status: ' .. dsl.line_status,domoticz.LOG_DEBUG)

            -- get all values
           for key, value in pairs(dsl) do
                domoticz.log(key .. ': '.. value,domoticz.LOG_DEBUG)
			end
			
			else
				domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
				domoticz.log(item, domoticz.LOG_ERROR)
			end

   end
}


et le log associé

Code : Tout sélectionner

2023-01-19 18:57:00.226 Error: dzVents: Error: (3.1.8) template: Error parsing xml to LUA table: (invalid xml string) {"city":{"insee":"83126","cp":83500,"name":"La Seyne-sur-Mer","latitude":43.088,"longitude":5.8709,"altitude":45},"update":"2023-01-19T11:07:09+01:00","forecast":{"insee":"83126","cp":83500,"latitude":43.088,"longitude":5.8709,"day":0,"datetime":"2023-01-19T01:00:00+0100","wind10m":40,"gust10m":102,"dirwind10m":314,"rr10":0,"rr1":0,"probarain":10,"weather":1,"tmin":4,"tmax":8,"sun_hours":6,"etp":2,"probafrost":10,"probafog":0,"probawind70":70,"probawind100":10,"gustx":102}}
2023-01-19 18:57:00.226 Error: dzVents: Error: (3.1.8) template: An error occurred when calling event handler essais meteo
2023-01-19 18:57:00.226 Error: dzVents: Error: (3.1.8) template: ...oticz\scripts\dzVents\generated_scripts/essais meteo.lua:31: attempt to index a nil value (local 'rt')

Merci à l'âme charitable qui pourrait m'aider à avancer ...
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: Meteoconcept

Message par Neutrino »

Le fichier XML retourné par l'API semble pas très valide.
Peux-tu poster un exemple complet de l'XML renvoyé ?
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
will
Messages : 32
Inscription : 01 nov. 2018, 19:26

Re: Meteoconcept

Message par will »

le retour de la requête par mon navigateur

Code : Tout sélectionner

<response>
<city>
<insee>83126</insee>
<cp>83500</cp>
<name>La Seyne-sur-Mer</name>
<latitude>43.088</latitude>
<longitude>5.8709</longitude>
<altitude>45</altitude>
</city>
<update>2023-01-19T11:07:09+01:00</update>
<forecast>
<insee>83126</insee>
<cp>83500</cp>
<latitude>43.088</latitude>
<longitude>5.8709</longitude>
<day>0</day>
<datetime>2023-01-19T01:00:00+0100</datetime>
<wind10m>40</wind10m>
<gust10m>102</gust10m>
<dirwind10m>314</dirwind10m>
<rr10>0</rr10>
<rr1>0</rr1>
<probarain>10</probarain>
<weather>1</weather>
<tmin>4</tmin>
<tmax>8</tmax>
<sun_hours>6</sun_hours>
<etp>2</etp>
<probafrost>10</probafrost>
<probafog>0</probafog>
<probawind70>70</probawind70>
<probawind100>10</probawind100>
<gustx>102</gustx>
</forecast>
</response>
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: Meteoconcept

Message par Neutrino »

L'XML est valide.
A la relecture du message d'erreur, j'ai l'impression que ton API revoie du JSON. :shock:
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
will
Messages : 32
Inscription : 01 nov. 2018, 19:26

Re: Meteoconcept

Message par will »

Un grand merci .

oui c'est du Json.....

Et voici le script qui tourne: monpremier :lol:

Code : Tout sélectionner

return {
	on = {
		timer = {
			'every 1 minutes' -- just an example to trigger the request
		},
		httpResponses = {
			'trigger' -- must match with the callback passed to the openURL command
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'template',
	},
	execute = function(domoticz, item)

		if (item.isTimer) then
			domoticz.openURL({
				url = 'https://api.meteo-concept.com/api/forecast/daily/0?token=xxx&insee=83126',
				method = 'GET',
				callback = 'trigger', -- see httpResponses above.
			})
		end

		if (item.isHTTPResponse) then

			if (item.ok) then
				if (item.isJSON) then

					local tempmini = item.json.forecast.tmin  --  temp mini de la journée

					-- update some device in Domoticz
					domoticz.devices('tempmini').updateText(tempmini)
				end
			else
				domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
				domoticz.log(item, domoticz.LOG_ERROR)
			end

		end

	end
}
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: Meteoconcept

Message par Keros »

Commencer par un script avec un traitement Json, ce n'est pas le plus facile. Bravo :)
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
will
Messages : 32
Inscription : 01 nov. 2018, 19:26

Re: Meteoconcept

Message par will »

Bonjour à tous,

J'ai complété le script pour le mettre en production :

Code : Tout sélectionner

return {
	on = {
		timer = {
			'every 1 minutes' -- just an example to trigger the request
		},
		httpResponses = {
			'trigger' -- must match with the callback passed to the openURL command
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'template',
	},
	execute = function(domoticz, item)

		if (item.isTimer) then
			domoticz.openURL({
				url = 'https://api.meteo-concept.com/api/forecast/daily/1?token=xxx&insee=83126',
				method = 'GET',
				callback = 'trigger', -- see httpResponses above.
			})
		end

		if (item.isHTTPResponse) then

			if (item.ok) then
				if (item.isJSON) then

                    --Température
					local tempmini = item.json.forecast.tmin  
                    local tempmaxi = item.json.forecast.tmax
                   
                   --Temps sensible
                    local temps  = item.json.forecast.weather
                   
                    --Vent   
                    local vitvent  = item.json.forecast.wind10m --km/h
                    local vitventms = (vitvent * 1000)/3600  --m/s
                    
                    local vitrafale  = item.json.forecast.gust10m --km/h
                     local vitrafalems = (vitrafale * 1000)/3600 --m/s
                    
                    local dirvent  = item.json.forecast.dirwind10m
    
                    --Cumul de pluie
                    local cumulmm  = item.json.forecast.rr10
                    local cumulmaxi  = item.json.forecast.rr1
                    local Probapluie  = item.json.forecast.probarain

                    --Ensoleillement
                    local Hsoleil  = item.json.forecast.sunHours

                    --Probabilité de gel entre 0 et 100%
                    local probagel  = item.json.forecast.probafrost

                    --Probabilité de gel entre 0 et 100%
                    local probabrouill  = item.json.forecast.probafog

                    --Probabilité de vent
                    local probaventsup70  = item.json.forecast.probawind70
                    local probaventsup100  = item.json.forecast.probawind100
                    
                 --Rafale de vent potentielle sous orage ou grain en km/h   
                    local probaventsouspluie  = item.json.forecast.gustx
                    

					-- update some device in Domoticz
					domoticz.devices('Prévision temp mini pour demain').updateTemperature(tempmini)
					domoticz.devices('Prévision vent pour demain').updateWind(dirvent,'',vitventms,vitrafalems)
					domoticz.devices('Prévision cumul pluie pour demain').updateRain(cumulmm,cumulmaxi)
					
					
				end
			else
				domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
				domoticz.log(item, domoticz.LOG_ERROR)
			end

		end

	end
}

Il marche bien sur mon Domoticz d'essais à la dernier version mais( y'a toujours un mais :evil: )
sur ma version V3.815 (DZ vent 2.2.0) celui que j'exploite j'ai un log d'erreur qui empêche le script de tourner

Code : Tout sélectionner

2023-01-22 10:59:54.310 Error: EventSystem: in C:\Program Files\Domoticz\scripts\dzVents\runtime\dzVents.lua: ...m Files\Domoticz\scripts\dzVents\runtime/persistence.lua:24: C:\Program Files\Domoticz\scripts\dzVents\/domoticzData.lua: Permission denied
Qu'est que c'est que ce truc :?: :?:

J'ai bien autorisé les script DZ vent dans ls paramètres dans domoticz, est ce qu'il y'a une manip particulière que j'aurais raté pour les autorisation? ( je suis sous w7) :idea:

Merci et bon weekend
Neutrino
Messages : 2662
Inscription : 10 juil. 2015, 15:42
Localisation : Les Herbiers(85)

Re: Meteoconcept

Message par Neutrino »

C'est un problème d'autorisation.
Domoticz n'a pas les droits pour écrire dans un répertoire ou alors c'est un bug de ta version.
Ma maison à plein d'IP ! :mrgreen:
SAV Bonjour. Vous avez vidé le cache ?
will
Messages : 32
Inscription : 01 nov. 2018, 19:26

Re: Meteoconcept

Message par will »

J'ai corrigé le problème en déposant le fichier directement dans le dossier script.
Depuis l'éditeur ça devait posé un problème d'enregistrement...

Par contre nouveaux problème peut être dut a la vielle version de DZ vents que j'utilise , il semble ne pas comprendre ça

Code : Tout sélectionner

2023-01-22 11:28:00.375 Error: dzVents: Error: template: An error occured when calling event handler Prevision meteo demain
2023-01-22 11:28:00.375 Error: dzVents: Error: template: ...oticz\scripts\dzVents\scripts/Prevision meteo demain.lua:16: attempt to index local 'item' (a nil value)
Pourtant ça fonctionne sur la derniére version de domoticz...

Un problème de syntaxe avec la fonction?
Répondre