[Bash] Vigilance météo

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.
vr6man
Messages : 627
Inscription : 18 juil. 2017, 12:15

Re: Vigilance météo

Message par vr6man »

Bonjour

Je viens vers vous, j'ai mis le script suivant en place

Code : Tout sélectionner

-- Meteo France vigilance from domogeek API
-- domoticz/scripts/lua/script_time_vigilance.lua
-- Information from Meteo France is updated everyday at 6AM and 5PM
-- This script will check at 6.10AM and 5.10PM

function os.capture(cmd, raw)
  local f = assert(io.popen(cmd, 'r'))
  local s = assert(f:read('*a'))
  f:close()
  if raw then return s end
  s = string.gsub(s, '^%s+', '')
  s = string.gsub(s, '%s+$', '')
  s = string.gsub(s, '[\n\r]+', ' ')
  return s
end

commandArray = {}
time = os.date("*t")

-- Trigger at 6:10 and 17:10
if (time.min == 10 and ((time.hour == 6) or (time.hour == 17))) then

  -- Path to curl
  local curl = '/usr/bin/curl'

  -- Device ID (Type Alert on virtual hardware)
  local idx = '394'
  -- Department (France)
  local dept = '72'
  
  local cmd = 'curl http://domogeek.entropialux.com/vigilance/' .. dept..'/all'
  local vigilance = os.capture(cmd, true)
  local fill1 = nil
  local fill2 = nil
  local fill3 = nil
  local flood = nil
  local color = nil
  local risk = nil
  fill1, flood, fill2, color, fill3, risk = string.match(vigilance,"{\"(.-)\": \"(.-)\", \"(.-)\": \"(.-)\", \"(.-)\": \"(.-)\"}$")
  
  print('Vigilance: ' .. cmd .. ': ' .. color .. ' / ' .. risk)
  
  local sValue = 'Risque : ' .. risk
  local nValue = 0
  
  if     color == "vert"   then nValue = 1
    elseif color == "jaune"  then nValue = 2
    elseif color == "orange" then nValue = 3
    elseif color == "rouge"  then nValue = 4
    else nValue = 0
  end

  -- Update device idx with nValue and sValue
  commandArray['UpdateDevice'] = idx .. '|' .. nValue .. '|' .. sValue
end

return commandArray
Avant j'ai créé le capteur virtule de type text

Faut il faire autre chose car le capteur ne se met pas a jour ?

merci de votre aide
papoo
Messages : 2029
Inscription : 10 janv. 2016, 11:29
Localisation : Limoges (87)
Contact :

Re: Vigilance météo

Message par papoo »

les données sont rafraichies deux fois par jour

Code : Tout sélectionner

if (time.min == 10 and ((time.hour == 6) or (time.hour == 17))) then
A 6h10 et 17h10
domoticz beta/RaspBerry PI3 stretch
https://pon.fr github
vr6man
Messages : 627
Inscription : 18 juil. 2017, 12:15

Re: Vigilance météo

Message par vr6man »

ah ok j'avais cru entre 06h10 et 17h10

je modifie l'heure pour voir si cela fonctionne
vr6man
Messages : 627
Inscription : 18 juil. 2017, 12:15

Re: Vigilance météo

Message par vr6man »

Effectivement cela fonctionne

Par contre du coup quel valeur faut il mettre dans le champs notification afin de recevoir des alertes ?

Vent, pluie, etc ...

je sais pas trop quoi mettre

merci
Répondre