Notification sms incluant la valeur d'une variable ?

Forum dédié aux problématiques concernant les scripts pour DomoticZ.
Entourez votre code et les logs avec les balises nommées code grâce au bouton <\>.
Biocef
Messages : 39
Inscription : 13 déc. 2014, 14:59

Re: Notification sms incluant la valeur d'une variable ?

Message par Biocef »

Ca marche nickel avec la notif, merci !

J'ai adapté à mes besoins, n'y connaissant rien ça m'a pris pal mal d'heures mais ça marche !
Je pense que c'est très optimisable, si jamais vous avez le temps d'y jeter un oeil ce serait sympa ;)

Mon besoin était en fait d'avoir la lumière qui s'allume pour me réveiller plus tôt en cas de gel pour avoir le temps de gratter la voiture :D

Code : Tout sélectionner

	local sonde = 'Temperature exterieure'
	local chambre = 'Lumiere de la grande chambre'
	local chevet = 'Lampe de chevet'

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

--------------------------------------------------------------------------------------
-- Stocke la température la plus basse entre 3h et 5h59 du matin si réveil activé --
--------------------------------------------------------------------------------------
if (otherdevices['Reveil']=='On') then
    if (devicechanged[sonde])
        then
            if (uservariables['T_mini'] > otherdevices_temperature[sonde]) and time.hour >= 3 and time.hour < 6
              then
                uservariables['T_mini'] = otherdevices_temperature[sonde]
                commandArray['Variable:T_mini']= tostring(uservariables["T_mini"])
            end
    end


--------------------------------------------------------
-- Envoi la température la plus basse par prowl à 06h --
--------------------------------------------------------
        if time.hour == 6 and time.min == 00 and uservariables['Notif'] == 1
               then
                  commandArray['SendNotification']='Cette nuit il a fait #'..(string.format("%g",tostring(uservariables['T_mini'])))..'°C'
                  commandArray['Variable:Notif']= "0"                  
                  commandArray['Variable:T_mini']= tostring(uservariables["T_mini"])
         end


---------------------------------------------------------------------------------
-- Si la température est descendue sous les 1°c alors démarre le réveil à 6h00 --
---------------------------------------------------------------------------------

        if time.hour == 6 and time.min == 00 and time.sec == 00 and (uservariables['T_mini'] <= 1)
             then commandArray[chambre] = 'Set Level 15'
        end

          if time.hour == 6 and time.min == 01 and time.sec == 00 and (uservariables['T_mini'] <= 1)
                      then commandArray[chambre] = 'Set Level 25'
          end

           if time.hour == 6 and time.min == 02 and time.sec == 00 and (uservariables['T_mini'] <= 1)
                        then commandArray[chambre] = 'Set Level 35'
           end

             if time.hour == 6 and time.min == 03 and time.sec == 00 and (uservariables['T_mini'] <= 1)
                          then commandArray[chevet] = 'On'
             end


--------------------------------------------------------------------------------------
-- Si la température n'est pas descendue sous les 1° alors démarre le réveil à 6h15 --
--------------------------------------------------------------------------------------
        if time.hour == 6 and time.min == 15 and time.sec == 00 and (uservariables['T_mini'] > 1)
               then commandArray[chambre] = 'Set Level 15'
        end

          if time.hour == 6 and time.min == 16 and time.sec == 00 and (uservariables['T_mini'] > 1)
                     then commandArray[chambre] = 'Set Level 25'
          end

            if time.hour == 6 and time.min == 17 and time.sec == 00 and (uservariables['T_mini'] > 1)
                        then commandArray[chambre] = 'Set Level 35'
            end

              if time.hour == 6 and time.min == 18 and time.sec == 00 and (uservariables['T_mini'] > 1)
                          then commandArray[chevet] = 'On'
              end


--------------------------------------------
-- réinitialisation des variables à 12h00 --
--------------------------------------------
         if time.hour == 12 and time.min == 00
           then
                commandArray['Variable:T_mini']= "100"
                commandArray['Variable:Notif']= "1"
         end

end
return commandArray
J'ai créé un interrupteur virtuel "Reveil" qui active ou désactive l'ensemble. Quand je suis en congés peu m'importe finalement qu'il ait gelé.

Pour l'allumage de la lampe j'ai été obligé de rajouter des "time.sec == 00" sinon la commande se lançait toutes les secondes de la minute... :|

Je me pencherai sur la notif sms plus tard, je bloque sur la récupération de la variable dans le script sh, je ne vois pas comment faire.
Jihem
Messages : 337
Inscription : 19 sept. 2014, 13:04
Localisation : Finistère Sud

Re: Notification sms incluant la valeur d'une variable ?

Message par Jihem »

Bonsoir
Pas mal ton idée de réveil plus tôt pour gratter ;)
Pou éviter de mettre la seconde dans toutes les lignes:

Code : Tout sélectionner

if time.hour == 6 and time.min == 01 and time.sec == 00
tu peux mettre un flag qui arrête la commande quand elle a été envoyé; comme pour la notification.
tu crées une uservariable " Notif1" dans Domoticz que tu mets à zéro quand la commande est partie

Code : Tout sélectionner

if time.hour == 6  and uservariables['Notif1'] == 1 then
  commandArray['Variable:Notif']= "0"          
            end
Cela t'évitera que la commande ne parte pas si le script n'est pas lancé dans la seconde.
Et tu réinitialise à midi
Hard:Raspberry Pi4 + SSD Arduino Tablette murale Archos
Soft: Domoticz WireGuard vpn Homebridge Tradfri Ikea
Devices:[/colore]Rfxtrx433 DI-O Chacon Sonoff touch Anémomètre, pluviometre, sondes Orégon, capteurs humidité Miflora, téléinfo
Biocef
Messages : 39
Inscription : 13 déc. 2014, 14:59

Re: Notification sms incluant la valeur d'une variable ?

Message par Biocef »

Génial, ça marche impec, merci beaucoup pour votre aide !!!

Vous savez comment je peux récupérer la valeur d'une variable pour l'envoyer par sms via un script sh ?
Si je met juste le nom de la variable dans le script il ne fera pas le lien avec celle qui existe dans domoticz si ?
patrice
Messages : 1720
Inscription : 22 sept. 2014, 21:51

Re: Notification sms incluant la valeur d'une variable ?

Message par patrice »

Bonjour

J'avais fait un script python pour cela que je viens de poster dans le forum
viewtopic.php?f=17&t=166

Il est spécifique à free mais modifiable facilement si besoin et j'espère
clair
Raspberry pi 3, Dongle RfxCom et Zigate +, plugin de pipiche, Volets Roulants profalux, contrôle d'éclairage, détecteurs de présence, alarme incendie, pilotage livebox ...
Objectif : WAF > 1
Répondre