[LUA] Qualité de l’air en province et à Paris

Vous avez créé un script LUA dont vous êtes fier, un .sh génial, un programme Python hors du commun, un Tuto, c'est ici que vous pouvez les partager.
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

[LUA] Qualité de l’air en province et à Paris

Message par papoo »

basé sur l'article http://easydomoticz.com/domoticz-integr ... -de-paris/ et le commentaire de nam
Ce script a pour but de remonter les informations de pollution du site http://www.lcsqa.org 2 fois par jour à 07H10 et 18H10 (éditable ligne 63)
sur domoticz en LUA et de nous alerter le cas échéant selon le niveau de notification choisi
seules les villes suivantes ont des informations sur la pollution! Certaines n'ont que l'indice de pollution disponible, d'autres
ont toutes ou parties des différents sous indices. Pensez à vérifier sur le site de http://www.lcsqa.org/surveillance/indices/liste/jour les informations disponibles. Ces données ne sont pas disponible 365 jours /an , il se peut que certains jours les données de votre commune ne soient pas présente dans le fichier xml.
Liste des villes (98):
FORT-DE-FRANCE, AIRVAULT, AIX-EN-PROVENCE, AJACCIO, ALBERTVILLE, ALENCON, AMIENS, ANGOULEME, ANNECY, ANNEMASSE, ARMENTIERES, ARRAS, AUBAGNE, AURILLAC, AUXERRE,
AVIGNON, BASTIA, BETHUNE, BOURG-EN-BRESSE, BOURGOIN-JALLIEU, BRIGNOLES, BRIVE-LA-GAILLARDE, CAEN, CALAIS, CANNES, CHALONS-EN-CHAMPAGNE, CHAMBERY,
CHAMONIX-MONT-BLANC, CHARLEVILLE-MEZIERES, CHERBOURG-OCTEVILLE, CLERMONT-FERRAND, COGNAC, COLMAR, CREIL, DIJON, DOUAI, DUNKERQUE, EVREUX, FORBACH, GAP,
GRANDFONTAINE, GRENOBLE, GUERET, HAVRE, HYERES, ISSOIRE, LENS, LILLE, LIMOGES, LISIEUX, LYON, MACON, MARSEILLE, MAUBEUGE, METZ, MONTCEAU-LES-MINES, MONTLUCON,
MOULINS, MULHOUSE, MUNCHHAUSEN, NANCY, NEVERS, NICE, NIORT, PARIS, PASSY, PETITE-PIERRE, POITIERS, PUY-EN-VELAY, REIMS, RIOM, ROANNE, ROCHELLE, ROMANS-SUR-ISERE,
ROUEN, SAINT-DENIS, SAINT-DIZIER, SAINT-ETIENNE, SAINT-JUNIEN, SAINT-OMER, SAINT-PAUL, SAINT-PIERRE, SAINT-QUENTIN, SENS, STRASBOURG, THIONVILLE, TOULON, TROYES,
TULLE, VALENCE, VALENCIENNES, VENACO, VIENNE, VILLAGE-NEUF, BOULOGNE-SUR-MER, CHALON-SUR-SAONE, SAINT-JEAN-DE-MAURIENNE, SAINT-LO

Code : Tout sélectionner

--[[
name : script_time_pollution.lua
auteur : papoo
version : 1.14
Création : 17/05/2016
Mise à jour : 22/11/2017
basé sur l'article http://easydomoticz.com/domoticz-integrer-les-donnees-qualite-de-lair-en-dehors-de-paris/ et le commentaire de nam
 Ce script a pour but de remonter les informations de pollution du site http://www.lcsqa.org 2 fois par jour à 07H10 et 18H10 (éditable ligne 72)
 sur domoticz et de nous alerter le cas écheant selon le niveau de notification choisi
 L'indice de pollution remonte sur un widget Alert
 version 1.13 suite à l'indisponibilité des données du jour, explotation des données de la veille et suppression de la récuperation des commentaires (indisponible)
 Présentation de ce script : http://pon.fr/qualite-de-lair-en-province/
]]--
--------------------------------------------
------------ Variables à éditer ------------
-------------------------------------------- 

local debugging = false  	-- true pour voir les logs dans la console log Dz ou false pour ne pas les voir
local ville='LIMOGES'  --[[  seules les villes suivantes ont des informations sur la pollution! Certaines n'ont que l'indice de pollution disponible, d'autres 
ont toutes ou parties des différents sous indices. Pensez à verifier sur le site de http://www.lcsqa.org/surveillance/indices/liste/jour les informations disponibles.
Liste des villes (98): 
FORT-DE-FRANCE, AIRVAULT, AIX-EN-PROVENCE, AJACCIO, ALBERTVILLE, ALENCON, AMIENS, ANGOULEME, ANNECY, ANNEMASSE, ARMENTIERES, ARRAS, AUBAGNE, AURILLAC, AUXERRE,
AVIGNON, BASTIA, BETHUNE, BOURG-EN-BRESSE, BOURGOIN-JALLIEU, BRIGNOLES, BRIVE-LA-GAILLARDE, CAEN, CALAIS, CANNES, CHALONS-EN-CHAMPAGNE, CHAMBERY, 
CHAMONIX-MONT-BLANC, CHARLEVILLE-MEZIERES, CHERBOURG-OCTEVILLE, CLERMONT-FERRAND, COGNAC, COLMAR, CREIL, DIJON, DOUAI, DUNKERQUE, EVREUX, FORBACH, GAP, 
GRANDFONTAINE, GRENOBLE, GUERET, HAVRE, HYERES, ISSOIRE, LENS, LILLE, LIMOGES, LISIEUX, LYON, MACON, MARSEILLE, MAUBEUGE, METZ, MONTCEAU-LES-MINES, MONTLUCON, 
MOULINS, MULHOUSE, MUNCHHAUSEN, NANCY, NEVERS, NICE, NIORT, PARIS, PASSY, PETITE-PIERRE, POITIERS, PUY-EN-VELAY, REIMS, RIOM, ROANNE, ROCHELLE, ROMANS-SUR-ISERE, 
ROUEN, SAINT-DENIS, SAINT-DIZIER, SAINT-ETIENNE, SAINT-JUNIEN, SAINT-OMER, SAINT-PAUL, SAINT-PIERRE, SAINT-QUENTIN, SENS, STRASBOURG, THIONVILLE, TOULON, TROYES, 
TULLE, VALENCE, VALENCIENNES, VENACO, VIENNE, VILLAGE-NEUF, BOULOGNE-SUR-MER, CHALON-SUR-SAONE, SAINT-JEAN-DE-MAURIENNE, SAINT-LO
]]--

local dz_indice_alert = 723	-- renseigner l'idx du device alert pollution associé si souhaité, sinon nil (dummy - alert)
local dz_indice_log = 724	-- renseigner l'idx du device indice de pollution associé si souhaité, sinon nil (pour le log des données avec graphique)
local dz_o3 = nil			-- renseigner l'idx du device Ozone associé si souhaité, sinon nil
local dz_no2 = nil			-- renseigner l'idx du device dioxyde d'azote associé si souhaité, sinon nil
local dz_PM10 = nil			-- renseigner l'idx du device taux de particules associé si souhaité, sinon nil
local dz_so2 = nil			-- renseigner l'idx du device dioxyde de soufre associé si souhaité, sinon nil
local dz_com = nil			-- renseigner l'idx du device texte commentaire associé si souhaité, sinon nil
local dz_source = nil 		-- renseigner l'idx du device texte lien vers la source des mesures associé si souhaité, sinon nil
local send_notification = 3 -- 0: aucune notification, 1: toutes, 2: (2> Pollution <4), 3: (4> Pollution <6), 4: (6> Pollution <8), 5: (Pollution >8)

--------------------------------------------
----------- Fin variables à éditer ---------
--------------------------------------------
local dateIndice= nil
local CodeInsee= nil
local valeurIndice= nil
local SousIndiceO3= nil 
local SousIndiceNO2= nil
local SousIndicePM10= nil
local SousIndiceSO2= nil
local Commentaire= nil
local sourceAASQA= nil
	
--------------------------------------------
---------------- Fonctions -----------------
-------------------------------------------- 
function voir_les_logs (s, debugging)
    if (debugging) then 
		if s ~= nil then
        print ("<font color='#f3031d'>".. s .."</font>")
		else
		print ("<font color='#f3031d'>aucune valeur affichable</font>")
		end
    end
end	
--------------------------------------------
function TronquerTexte(texte, nb)  -- texte à tronquer, Nb maximum de caractère 
local sep ="[;!?.]"
local DernierIndex = nil
texte = string.sub(texte, 1, nb)
local p = string.find(texte, sep, 1)
DernierIndex = p
while p do
    p = string.find(texte, sep, p + 1)
    if p then
        DernierIndex = p
    end
end
return(string.sub(texte, 1, DernierIndex))
end
--------------------------------------------
-------------- Fin Fonctions ---------------
--------------------------------------------
commandArray = {}
time=os.date("*t")
--if (time.min == 10 and ((time.hour == 8) or (time.hour == 15) or (time.hour == 20))) then -- 3 éxecutions du script par jour à 8H10, 15h10 et 20H10
if (time.min == 10 and time.hour == 20) then -- 1 éxecution du script par jour à 21H10
--if time.min % 2 == 0 then  -- execution toutes les 2 minutes
voir_les_logs("script_time_pollution.lua",debugging)


-- deux methodes pour récuperer les informations xml,  WGET ou CURL si vous décommentez la methode curl pensez à commenter la methode wget
		-- début methode wget
		local fname ="/media/Freebox/Trend/pollution_air.xml"
--		local fname ="pollution_air.xml"		
--		os.execute("wget -q -O " .. fname .. " http://www.lcsqa.org/surveillance/indices/prevus/jour/xml") 
		os.execute("wget -q -O " .. fname .. " http://www.lcsqa.org/indices-qualite-air/xml/")		
		-- fin methode wget
		
		-- début methode curl
		 --local fname ="/tmp/pollution_air.xml"
		 --os.execute("curl http://www.lcsqa.org/surveillance/indices/prevus/jour/xml > ".. fname .." && chmod 777 " .. fname)
		-- fin methode curl
		
		
		 voir_les_logs("Fichier local : " ..fname,debugging)
		local f = io.open(fname, "r")

			 if f == nil then
			 print("Error opening file '" .. fname .. "'.")
			 os.exit(1)
			 end
 
		local xml = f:read("*all")
					f:close()

	
	for instance in xml:gmatch("<node>(.-)</node>") do 
	agglomeration=instance:match('<agglomeration>(.-)</agglomeration>')
			if agglomeration == ville then
	 dateIndice=instance:match('<dateIndice>(.-)</dateIndice>')
	CodeInsee=instance:match('<agglomerationCodeInsee>(.-)</agglomerationCodeInsee>')
	valeurIndice=instance:match('<valeurIndice>(.-)</valeurIndice>')
	SousIndiceO3=instance:match('<SousIndiceO3>(.-)</SousIndiceO3>')
	SousIndiceNO2=instance:match('<SousIndiceNO2>(.-)</SousIndiceNO2>')
	SousIndicePM10=instance:match('<SousIndicePM10>(.-)</SousIndicePM10>')
	SousIndiceSO2=instance:match('<SousIndiceSO2>(.-)</SousIndiceSO2>')
	Commentaire=instance:match('<Commentaire>(.-)</Commentaire>')
	sourceAASQA=instance:match('<sourceAASQA>(.-)</sourceAASQA>')
			end
	end

		 
		 
		if valeurIndice == nil and dz_indice_alert ~= nil then
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_indice_alert..'|0|Aucune donn&eacute;e disponible'}
			voir_les_logs("--- --- --- Aucune donn&eacute;e disponible pour la ville : ".. ville,debugging) 
			 
		end	


	if valeurIndice	~= nil then	
		voir_les_logs("--- --- --- dateIndice : ".. dateIndice,debugging)
		voir_les_logs("--- --- --- CodeInsee : ".. CodeInsee,debugging)
		voir_les_logs("--- --- --- Agglomeration : ".. ville,debugging)
		voir_les_logs("--- --- --- valeurIndice : ".. valeurIndice,debugging)
		voir_les_logs("--- --- --- SousIndiceO3 : ".. SousIndiceO3,debugging)
		voir_les_logs("--- --- --- SousIndiceNO2 : ".. SousIndiceNO2,debugging)
		voir_les_logs("--- --- --- SousIndicePM10 : ".. SousIndicePM10,debugging)
		voir_les_logs("--- --- --- SousIndiceSO2 : ".. SousIndiceSO2,debugging)
    voir_les_logs("--- --- --- Commentaire : ".. Commentaire,debugging)
		voir_les_logs("--- --- --- sourceAASQA : ".. sourceAASQA,debugging)

		 

	   if tonumber(valeurIndice) <= 4   then -- niveau 2
		  if dz_indice_alert ~= nil then
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_indice_alert..'|1|Pas de Pollution'}
			 
		  end
		  if send_notification > 0 and send_notification < 2 then
			 commandArray[#commandArray+1] = {['SendNotification'] = 'Alerte Pollution#Pas de Pollution!'}
			 
		  end
		  voir_les_logs("--- --- --- Pas de pollution --- --- ---",debugging)

		  
	   elseif tonumber(valeurIndice) <= 6   then -- niveau 3
		  if dz_indice_alert ~= nil then
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_indice_alert..'|2|Polution Faible'}
			 
		  end
		  if send_notification > 0 and send_notification < 3 then
			 commandArray[#commandArray+1] = {['SendNotification'] = 'Alerte Pollution#Pollution Faible!'}
			 
		  end
		  voir_les_logs("--- --- --- Pollution Faible --- --- ---",debugging)   


	   elseif tonumber(valeurIndice) <= 8   then -- niveau 4
		  if dz_indice_alert ~= nil then
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_indice_alert..'|3|Pollution Forte'}
			 
		  end
		  if send_notification > 0 and send_notification < 4 then
			 commandArray[#commandArray+1] = {['SendNotification'] = 'Alerte Pollution#Pollution Forte!'}
			 
		  end
		  voir_les_logs("--- --- --- Pollution Forte --- --- ---",debugging)      


	   elseif tonumber(valeurIndice) > 8  then -- niveau 5
		  if dz_indice_alert ~= nil then
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_indice_alert..'|4|Pollution tr&eacute;s forte'}
			 
		  end
		  if send_notification > 0 and send_notification < 5 then
			 commandArray[#commandArray+1] = {['SendNotification'] = 'Alerte Pollution#Pollution tr&eacute;s forte!'}
			 
		  end
		  voir_les_logs("--- --- --- Pollution très forte --- --- ---",debugging)

	   else
		  print("niveau non defini")
	   end		
			
		  if dz_indice_log ~= nil then -- Mise à jour du devise O3 si il existe
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_indice_log..'|0|'.. tostring(valeurIndice)}
			 
		  end	
		  if dz_no2 ~= nil then -- Mise à jour du devise NO3 si il existe
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_no2..'|0|'.. tostring(SousIndiceNO2)}
			 
		  end	
		  if dz_PM10 ~= nil then -- Mise à jour du devise PM10 si il existe
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_PM10..'|0|'.. tostring(SousIndicePM10)}
			 
		  end
		  if dz_so2 ~= nil then -- Mise à jour du devise SO2 si il existe
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_so2..'|0|'.. tostring(SousIndiceSO2)}
			 
		  end
		  if dz_com ~= nil then -- Mise à jour du devise Commentaire si il existe
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_com..'|0|'.. tostring(TronquerTexte(Commentaire,240))}
			 
		  end
		  if dz_source ~= nil then -- Mise à jour du devise Source si il existe
			sourceAASQAhtml = '<a href="'.. sourceAASQA ..'">'.. sourceAASQA ..'</a>'
			 commandArray[#commandArray+1] = {['UpdateDevice'] = dz_source..'|0|'.. tostring(sourceAASQAhtml)}
			 
		  end	  
	end		

end
return commandArray
Dernière modification par papoo le 22 nov. 2017, 22:25, modifié 1 fois.
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
jmv75013
Messages : 146
Inscription : 03 janv. 2017, 16:20

Re: LUA : Qualité de l’air en province et à Paris

Message par jmv75013 »

Bonjour,

J'ai intégré le script mais il ne se passe rien. Le lien indiqué en début de post : http://www.lcsqa.org/surveillance/indices/liste/jour renvoie sur une page pas introuvable. Quelqu'un a une idée du lien où ont peu trouver les infos maintenant.

Merci
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: LUA : Qualité de l’air en province et à Paris

Message par papoo »

Les données du jour ne sont plus disponible sur le site
je viens de modifier mon script pour exploiter les données consolidées de la veille

Code : Tout sélectionner

--[[
name : script_time_pollution.lua
auteur : papoo
version : 1.13
Création : 17/05/2016
Mise à jour : 12/01/2017
basé sur l'article http://easydomoticz.com/domoticz-integrer-les-donnees-qualite-de-lair-en-dehors-de-paris/ et le commentaire de nam
 Ce script a pour but de remonter les informations de pollution du site http://www.lcsqa.org 2 fois par jour à 07H10 et 18H10 (éditable ligne 57)
 sur domoticz et de nous alerter le cas écheant selon le niveau de notification choisi
 L'indice de pollution remonte sur un widget Alert
 version 1.13 suite à l'indisponibilité des données du jour, exploitation des données de la veille et suppression de la récuperation des commentaires (indisponible)
]]--
--------------------------------------------
------------ Variables à éditer ------------
-------------------------------------------- 

local debugging = true  	-- true pour voir les logs dans la console log Dz ou false pour ne pas les voir
local ville='LIMOGES'  --[[  seules les villes suivantes ont des informations sur la pollution! Certaines n'ont que l'indice de pollution disponible, d'autres 
ont toutes ou parties des différents sous indices. Pensez à verifier sur le site de http://www.lcsqa.org/surveillance/indices/liste/jour les informations disponibles.
Liste des villes (98): 
FORT-DE-FRANCE, AIRVAULT, AIX-EN-PROVENCE, AJACCIO, ALBERTVILLE, ALENCON, AMIENS, ANGOULEME, ANNECY, ANNEMASSE, ARMENTIERES, ARRAS, AUBAGNE, AURILLAC, AUXERRE,
AVIGNON, BASTIA, BETHUNE, BOURG-EN-BRESSE, BOURGOIN-JALLIEU, BRIGNOLES, BRIVE-LA-GAILLARDE, CAEN, CALAIS, CANNES, CHALONS-EN-CHAMPAGNE, CHAMBERY, 
CHAMONIX-MONT-BLANC, CHARLEVILLE-MEZIERES, CHERBOURG-OCTEVILLE, CLERMONT-FERRAND, COGNAC, COLMAR, CREIL, DIJON, DOUAI, DUNKERQUE, EVREUX, FORBACH, GAP, 
GRANDFONTAINE, GRENOBLE, GUERET, HAVRE, HYERES, ISSOIRE, LENS, LILLE, LIMOGES, LISIEUX, LYON, MACON, MARSEILLE, MAUBEUGE, METZ, MONTCEAU-LES-MINES, MONTLUCON, 
MOULINS, MULHOUSE, MUNCHHAUSEN, NANCY, NEVERS, NICE, NIORT, PARIS, PASSY, PETITE-PIERRE, POITIERS, PUY-EN-VELAY, REIMS, RIOM, ROANNE, ROCHELLE, ROMANS-SUR-ISERE, 
ROUEN, SAINT-DENIS, SAINT-DIZIER, SAINT-ETIENNE, SAINT-JUNIEN, SAINT-OMER, SAINT-PAUL, SAINT-PIERRE, SAINT-QUENTIN, SENS, STRASBOURG, THIONVILLE, TOULON, TROYES, 
TULLE, VALENCE, VALENCIENNES, VENACO, VIENNE, VILLAGE-NEUF, BOULOGNE-SUR-MER, CHALON-SUR-SAONE, SAINT-JEAN-DE-MAURIENNE, SAINT-LO
]]--

local dz_indice_alert = 723	-- renseigner l'id du device alert pollution associé si souhaité, sinon nil (dummy - alert)
local dz_indice_log = 724	-- renseigner l'id du device indice de pollution associé si souhaité, sinon nil (pour le log des données avec graphique)
local dz_o3 = nil			-- renseigner l'id du device Ozone associé si souhaité, sinon nil
local dz_no2 = nil			-- renseigner l'id du device dioxyde d'azote associé si souhaité, sinon nil
local dz_PM10 = nil			-- renseigner l'id du device taux de particules associé si souhaité, sinon nil
local dz_so2 = nil			-- renseigner l'id du device dioxyde de soufre associé si souhaité, sinon nil
--local dz_com = nil			-- renseigner l'id du device texte commentaire associé si souhaité, sinon nil
local dz_source = nil 		-- renseigner l'id du device texte lien vers la source des mesures associé si souhaité, sinon nil
local send_notification = 3 -- 0: aucune notification, 1: toutes, 2: (2> Pollution <4), 3: (4> Pollution <6), 4: (6> Pollution <8), 5: (Pollution >8)

--------------------------------------------
----------- Fin variables à éditer ---------
--------------------------------------------
local dateIndice= nil
local CodeInsee= nil
local valeurIndice= nil
local SousIndiceO3= nil 
local SousIndiceNO2= nil
local SousIndicePM10= nil
local SousIndiceSO2= nil
local Commentaire= nil
local sourceAASQA= nil
local indexArray=0	
--------------------------------------------
---------------- Fonctions -----------------
-------------------------------------------- 
function voir_les_logs (s, debugging)
    if (debugging) then 
		if s ~= nil then
        print ("<font color='#f3031d'>".. s .."</font>")
		else
		print ("<font color='#f3031d'>aucune valeur affichable</font>")
		end
    end
end	
--------------------------------------------
-------------- Fin Fonctions ---------------
--------------------------------------------
commandArray = {}
now=os.date("*t")
--if (now.min == 10 and ((now.hour == 8) or (now.hour == 15) or (now.hour == 20))) then -- 3 éxecutions du script par jour à 8H10, 15h10 et 20H10
if (now.min == 10 and now.hour == 20) then -- 1 éxecution du script par jour à 21H10
--if now.min % 2 == 0 then  -- execution toutes les 2 minutes
voir_les_logs("script_time_pollution.lua",debugging)


-- deux methodes pour récuperer les informations xml,  WGET ou CURL si vous décommentez la methode curl pensez à commenter la methode wget
		-- début methode wget
		local fname ="/media/Freebox/Trend/pollution_air.xml"
--		local fname ="pollution_air.xml"		
--		os.execute("wget -q -O " .. fname .. " http://www.lcsqa.org/surveillance/indices/prevus/jour/xml") 
		os.execute("wget -q -O " .. fname .. " http://www.lcsqa.org/indices-qualite-air/xml/")		
		-- fin methode wget
		
		-- début methode curl
		 --local fname ="/tmp/pollution_air.xml"
		 --os.execute("curl http://www.lcsqa.org/surveillance/indices/prevus/jour/xml > ".. fname .." && chmod 777 " .. fname)
		-- fin methode curl
		
		
		 voir_les_logs("Fichier local : " ..fname,debugging)
		local f = io.open(fname, "r")

			 if f == nil then
			 print("Error opening file '" .. fname .. "'.")
			 os.exit(1)
			 end
 
		local xml = f:read("*all")
					f:close()

	
	for instance in xml:gmatch("<node>(.-)</node>") do 
	agglomeration=instance:match('<agglomeration>(.-)</agglomeration>')
			if agglomeration == ville then
	 dateIndice=instance:match('<dateIndice>(.-)</dateIndice>')
	CodeInsee=instance:match('<agglomerationCodeInsee>(.-)</agglomerationCodeInsee>')
	valeurIndice=instance:match('<valeurIndice>(.-)</valeurIndice>')
	SousIndiceO3=instance:match('<SousIndiceO3>(.-)</SousIndiceO3>')
	SousIndiceNO2=instance:match('<SousIndiceNO2>(.-)</SousIndiceNO2>')
	SousIndicePM10=instance:match('<SousIndicePM10>(.-)</SousIndicePM10>')
	SousIndiceSO2=instance:match('<SousIndiceSO2>(.-)</SousIndiceSO2>')
	--Commentaire=instance:match('<Commentaire>(.-)</Commentaire>')
	sourceAASQA=instance:match('<sourceAASQA>(.-)</sourceAASQA>')
			end
	end

		 
		 
		if valeurIndice == nil and dz_indice_alert ~= nil then
			 commandArray[indexArray] = {['UpdateDevice'] = dz_indice_alert..'|0|Aucune donn&eacute;e disponible'}
			voir_les_logs("--- --- --- Aucune donn&eacute;e disponible pour la ville : ".. ville,debugging) 
			 indexArray=indexArray+1
		end	


	if valeurIndice	~= nil then	
		voir_les_logs("--- --- --- dateIndice : ".. dateIndice,debugging)
		voir_les_logs("--- --- --- CodeInsee : ".. CodeInsee,debugging)
		voir_les_logs("--- --- --- Agglomeration : ".. ville,debugging)
		voir_les_logs("--- --- --- valeurIndice : ".. valeurIndice,debugging)
		voir_les_logs("--- --- --- SousIndiceO3 : ".. SousIndiceO3,debugging)
		voir_les_logs("--- --- --- SousIndiceNO2 : ".. SousIndiceNO2,debugging)
		voir_les_logs("--- --- --- SousIndicePM10 : ".. SousIndicePM10,debugging)
		voir_les_logs("--- --- --- SousIndiceSO2 : ".. SousIndiceSO2,debugging)
		--voir_les_logs("--- --- --- Commentaire : ".. Commentaire,debugging)
		voir_les_logs("--- --- --- sourceAASQA : ".. sourceAASQA,debugging)

		 

	   if tonumber(valeurIndice) <= 4   then -- niveau 2
		  if dz_indice_alert ~= nil then
			 commandArray[indexArray] = {['UpdateDevice'] = dz_indice_alert..'|1|Pas de Pollution'}
			 indexArray=indexArray+1
		  end
		  if send_notification > 0 and send_notification < 2 then
			 commandArray[indexArray] = {['SendNotification'] = 'Alerte Pollution#Pas de Pollution!'}
			 indexArray=indexArray+1
		  end
		  voir_les_logs("--- --- --- Pas de pollution --- --- ---",debugging)

		  
	   elseif tonumber(valeurIndice) <= 6   then -- niveau 3
		  if dz_indice_alert ~= nil then
			 commandArray[indexArray] = {['UpdateDevice'] = dz_indice_alert..'|2|Polution Faible'}
			 indexArray=indexArray+1
		  end
		  if send_notification > 0 and send_notification < 3 then
			 commandArray[indexArray] = {['SendNotification'] = 'Alerte Pollution#Pollution Faible!'}
			 indexArray=indexArray+1
		  end
		  voir_les_logs("--- --- --- Pollution Faible --- --- ---",debugging)   


	   elseif tonumber(valeurIndice) <= 8   then -- niveau 4
		  if dz_indice_alert ~= nil then
			 commandArray[indexArray] = {['UpdateDevice'] = dz_indice_alert..'|3|Pollution Forte'}
			 indexArray=indexArray+1
		  end
		  if send_notification > 0 and send_notification < 4 then
			 commandArray[indexArray] = {['SendNotification'] = 'Alerte Pollution#Pollution Forte!'}
			 indexArray=indexArray+1
		  end
		  voir_les_logs("--- --- --- Pollution Forte --- --- ---",debugging)      


	   elseif tonumber(valeurIndice) > 8  then -- niveau 5
		  if dz_indice_alert ~= nil then
			 commandArray[indexArray] = {['UpdateDevice'] = dz_indice_alert..'|4|Pollution tr&eacute;s forte'}
			 indexArray=indexArray+1
		  end
		  if send_notification > 0 and send_notification < 5 then
			 commandArray[indexArray] = {['SendNotification'] = 'Alerte Pollution#Pollution tr&eacute;s forte!'}
			 indexArray=indexArray+1
		  end
		  voir_les_logs("--- --- --- Pollution très forte --- --- ---",debugging)

	   else
		  print("niveau non defini")
	   end		
			
		  if dz_indice_log ~= nil then -- Mise à jour du devise O3 si il existe
			 commandArray[indexArray] = {['UpdateDevice'] = dz_indice_log..'|0|'.. tostring(valeurIndice)}
			 indexArray=indexArray+1
		  end	
		  if dz_no2 ~= nil then -- Mise à jour du devise NO3 si il existe
			 commandArray[indexArray] = {['UpdateDevice'] = dz_no2..'|0|'.. tostring(SousIndiceNO2)}
			 indexArray=indexArray+1
		  end	
		  if dz_PM10 ~= nil then -- Mise à jour du devise PM10 si il existe
			 commandArray[indexArray] = {['UpdateDevice'] = dz_PM10..'|0|'.. tostring(SousIndicePM10)}
			 indexArray=indexArray+1
		  end
		  if dz_so2 ~= nil then -- Mise à jour du devise SO2 si il existe
			 commandArray[indexArray] = {['UpdateDevice'] = dz_so2..'|0|'.. tostring(SousIndiceSO2)}
			 indexArray=indexArray+1
		  end
		  -- if dz_com ~= nil then -- Mise à jour du devise Commentaire si il existe
			 -- commandArray[indexArray] = {['UpdateDevice'] = dz_com..'|0|'.. tostring(Commentaire)}
			 -- indexArray=indexArray+1
		  -- end
		  if dz_source ~= nil then -- Mise à jour du devise Source si il existe
			sourceAASQAhtml = '<a href="'.. sourceAASQA ..'">'.. sourceAASQA ..'</a>'
			 commandArray[indexArray] = {['UpdateDevice'] = dz_source..'|0|'.. tostring(sourceAASQAhtml)}
			 indexArray=indexArray+1
		  end	  
	end		

end
return commandArray
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
DumpDos
Messages : 75
Inscription : 01 juin 2016, 20:09
Localisation : Grenoble (38)

Re: LUA : Qualité de l’air en province et à Paris

Message par DumpDos »

Merci pour cette nouvelle édition de script papoo. :)

Par contre pensez bien à modifier cette ligne dans le script :

Code : Tout sélectionner

local fname ="/media/Freebox/Trend/pollution_air.xml"
En le testant pour la première fois ça ma foutu Domoticz de travers, impossible de redémarrer, j'aurai du y faire attention. :?

Code : Tout sélectionner

2017-01-13 00:36:00.209  LUA: Error opening file '/media/Freebox/Trend/pollution_air.xml'.
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
  what():  boost: mutex lock failed in pthread_mutex_lock: Invalid argument
Abandon
Après suppression et édition du nouveau fichier tout est rentré dans l'ordre.
Raspberry Pi 2 - Domoticz bêta- Custom Page - RfxTrx433E - MySensors - Z-Stick Gen 5
6 x DIO 54795 - 4 x DIO 54781 - 2 x Home Confort ECR-100 - 4 X THGR122NX - 1 X OWL Micro+
2 X RGB - 3D - 2 X Switch - 1 X Ir Rx-Tx
1 X Fibaro FGMS-001
jmv75013
Messages : 146
Inscription : 03 janv. 2017, 16:20

Re: LUA : Qualité de l’air en province et à Paris

Message par jmv75013 »

Bonjour,

Merci pour ta réactivité Papoo. Dommage que l'on n'ai plus les données du jour, celles de la veille c'est moins intéressant. J'espère qu'elles reviendront.
Arno-Strasbourg
Messages : 46
Inscription : 11 oct. 2016, 23:30

Re: LUA : Qualité de l’air en province et à Paris

Message par Arno-Strasbourg »

Bonjour,

Je viens d'implémenter ce script dans mon Domoticz sur Raspberry Pi. Ca fonctionne plutôt bien, à part le capteur de texte avec le commentaire qui ne se met pas du tout à jour.
C'est un Dummy Texte, activé et dont l'id est bien renseigné dans le script.
Le commentaire s'affiche correctement dans la console en mode debug.
Domoticz - Google Chrome.jpg
Domoticz - Google Chrome.jpg (9.58 Kio) Consulté 8517 fois
Ai-je choisi le bon dummy ?

bizarrement, il s'est mis à jour au bout d'un moment (quelques minutes) et affiche "undefined".

Voici le log :
Domoticz - Google Chrome1.jpg
Domoticz - Google Chrome1.jpg (140.68 Kio) Consulté 8516 fois
Quelqu'un aurait une idée du type de problème ?

Merci d'avance.

Edit: Je viens de regarder dans la base de donnée de Domoticz avec sqlmanager et le device est bien renseigné avec le commentaire correspondant.
Malgré cela, il ne s'affiche pas dans domoticz. Trop long ? Pas le bon dummy ?...
@rn0.

DMZ + Xibo sur Raspberry Pi pour le bureau
DMZ + Custom Page sur W7 pour la maison récemment transféré sur
DS216se Synology - DSM 6.1.1-15101 Update 1 / Domoticz 3.0.7376-7 / Mosquitto 1.4.9-5
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: LUA : Qualité de l’air en province et à Paris

Message par papoo »

possible en effet que les infos soient trop longues.
le device text accepte 240 caractères max
j'ai une petite fonction pour corriger ça
juste avant

Code : Tout sélectionner

--------------------------------------------
-------------- Fin Fonctions ---------------
--------------------------------------------
ajoute

Code : Tout sélectionner

--------------------------------------------
function TronquerTexte(texte, nb)  -- texte à tronquer, Nb maximum de caractère 
local sep ="[;!?.]"
local DernierIndex = nil
texte = string.sub(texte, 1, nb)
local p = string.find(texte, sep, 1)
DernierIndex = p
while p do
    p = string.find(texte, sep, p + 1)
    if p then
        DernierIndex = p
    end
end
return(string.sub(texte, 1, DernierIndex))
end
ensuite remplace la ligne

Code : Tout sélectionner

commandArray[#commandArray+1] = {['UpdateDevice'] = dz_com..'|0|'.. tostring(Commentaire)}
par

Code : Tout sélectionner

commandArray[#commandArray+1] = {['UpdateDevice'] = dz_com..'|0|'.. tostring(TronquerTexte(Commentaire,240))}
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
Arno-Strasbourg
Messages : 46
Inscription : 11 oct. 2016, 23:30

Re: LUA : Qualité de l’air en province et à Paris

Message par Arno-Strasbourg »

Yes, ça marche très bien !! Merci.

C'est très bizarre. J'avais crée 3 capteurs car ils disparaissaient au bout d'un moment. En les remplissant, ils sont réapparu. J'ai pu les effacer.

Merci encore.
@rn0.

DMZ + Xibo sur Raspberry Pi pour le bureau
DMZ + Custom Page sur W7 pour la maison récemment transféré sur
DS216se Synology - DSM 6.1.1-15101 Update 1 / Domoticz 3.0.7376-7 / Mosquitto 1.4.9-5
Répondre