[DzVents] Tempo - récupérer le nombre de jours restant

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.
Datawolf
Messages : 273
Inscription : 03 avr. 2018, 13:51

[DzVents] Tempo - récupérer le nombre de jours restant

Message par Datawolf »

Salut,

Après avoir récupéré la couleur quoi de plus légitime que de vouloir connaitre le nombre de jours rouge restant.

Code : Tout sélectionner

--[[

Tous les matins, 

Récupère le nombre de jours bleu, blanc et rouge, et envoie un mail 
- quand les blanc et rouge s'activent
ou
- quand les blanc et rouge finissent

--]]

return {
	on = { timer = { 'at 06:10' }
	     },
	 
	execute = function(domoticz, timer)

      ancienBleu  = domoticz.devices(412).counter
      ancienBlanc = domoticz.devices(413).counter
      ancienRouge = domoticz.devices(414).counter
  
--    import des fontions pour lire le JSON
      json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()

--    specify the user Agent to avoid the "Access Denied" issue
      command = "curl -A 'Wget/1.20.3 (linux-gnu)' " .. '"' .. "https://particulier.edf.fr/bin/edf_rc/servlets/ejptempodaysnew?TypeAlerte=TEMPO" .. '"'
      
      config=assert(io.popen(command))
      blocjson = config:read('*all')
      config:close()
      jsonValeur = json:decode(blocjson)

      bleu  = jsonValeur.PARAM_NB_J_BLEU
      blanc = jsonValeur.PARAM_NB_J_BLANC
      rouge = jsonValeur.PARAM_NB_J_ROUGE
      
      if ( ancienBlanc == 0 and blanc > 0)
      or ( ancienRouge == 0 and rouge > 0)
      then
          domoticz.email('Notif Domoticz', 'Début Tempo !', 'youraddress@yourserver.com')                
      elseif ( (ancienBlanc > 0 or ancienRouge > 0 ) and blanc == 0 and rouge == 0)
      then
          domoticz.email('Notif Domoticz', 'Fin Tempo !', 'youraddress@yourserver.com')                
      end
      
      domoticz.devices(412).updateCounter(bleu)      
      domoticz.devices(413).updateCounter(blanc)
      domoticz.devices(414).updateCounter(rouge)      
      

	end -- execute function
}

@+
The Datawolf
Datawolf
Messages : 273
Inscription : 03 avr. 2018, 13:51

Re: [DzVents] Tempo - récupérer le nombre de jours restant

Message par Datawolf »

Hello,

Nouvelle version, suite à changements d'EDF (en juin, je crois):

Code : Tout sélectionner

--[[

Tous les matins, 

Récupère le nombre de jours bleu, blanc et rouge, et envoie un mail 
- quand les blanc et rouge s'activent
ou
- quand les blanc et rouge finissent

--]]

return {
	on = { timer = { 'at 06:10' }
	     },
	 
	execute = function(domoticz, timer)

      ancienBleu  = domoticz.devices(412).counter
      ancienBlanc = domoticz.devices(413).counter
      ancienRouge = domoticz.devices(414).counter
  
--    import des fontions pour lire le JSON
      json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()

--    specify the user Agent to avoid the "Access Denied" issue
      command = "curl -A 'Wget/1.20.3 (linux-gnu)' " .. '"' .. "https://particulier.edf.fr/services/rest/referentiel/getNbTempoDays?TypeAlerte=TEMPO" .. '"'
      
      config=assert(io.popen(command))
      blocjson = config:read('*all')
      config:close()
      jsonValeur = json:decode(blocjson)

      bleu  = jsonValeur.PARAM_NB_J_BLEU
      blanc = jsonValeur.PARAM_NB_J_BLANC
      rouge = jsonValeur.PARAM_NB_J_ROUGE
      
      if ( ancienBlanc == 0 and blanc > 0)
      or ( ancienRouge == 0 and rouge > 0)
      then
          domoticz.email('Notif Domoticz', 'Début Tempo !', 'youraddress@yourserver.com')                
      elseif ( (ancienBlanc > 0 or ancienRouge > 0 ) and blanc == 0 and rouge == 0)
      then
          domoticz.email('Notif Domoticz', 'Fin Tempo !', 'youraddress@yourserver.com')                
      end
      
      domoticz.devices(412).updateCounter(bleu)      
      domoticz.devices(413).updateCounter(blanc)
      domoticz.devices(414).updateCounter(rouge)      
      

	end -- execute function
}
@+
The Datawolf
Répondre