This is an old revision of the document!


3- Liste des scripts LUA


1- Modifier la couleur d’une lumière Led en fonction de la température de la pièce

By captainigloo

But : Script permettant de modifier la couleur d’une led RGB en fonction de la température de la pièce

-- Title: Set RGB light output depending on Temperature
-- 
-- Description :
-- Set white color if temp is < 10°C
-- Set light blue color if temps is between 10 and 15
-- Set dark blue color if temp is between 15 and 19
-- Set green color if temp is between 19 and 22
-- Set Yellow color ir temp is between 22 and 25
-- Set Orange color if temp is between 25 and 28
-- Set Red color if temp is greater than 28
--
-- Inputs 
--   * input_4 : N° entrée Temperature
-- Output
--   * output_6 : N° Sortie RGB light
-- Events
-- This script may be launched on input_4 changes

local temp = calaos:getInputValue("input_4")
if temp < 10.0 then
    --blanc
    str = "set 0x60FFFF"
elseif temp >= 10.0 and temp < 15.0 then
    --bleu clair
    str = "set 0x28FFFF"
elseif temp >= 15.0 and temp < 19.0 then
    --bleu foncé
    str = "set 0x0060FF"
elseif temp >= 19.0 and temp < 22.0 then
    -- vert
    str = "set 0x28FF28"
elseif temp >= 22.0 and temp < 25.0 then
    -- Jaune
    str = "set 0x7AFF00"
elseif temp >= 25.0 and temp < 28.0 then
    -- Orange
    str = "set 0xFFFF00"
elseif temp > 28.0 then
    -- Rouge
    str = "set 0xFF3D00"
end
calaos:setOutputValue("output_6", str)
return true


2- Envoyer un SMS via Free suivant un évènement donné

By captainigloo

But : Script permettant d’envoyer un message par SMS en fonction d’une condition. Attention ne fonctionne qu’avec free. Voir le tuto complet ici : Utilisation du systeme de notifications par sms de free

function urlencode(str)
   if (str) then
      str = string.gsub (str, "\n", "\r\n")
      str = string.gsub (str, "([^%w ])",
         function (c) return string.format ("%%%02X", string.byte(c)) end)
      str = string.gsub (str, " ", "%%20")
   end
   return str    
end

local user = "username"
local pass = "password"
local msg = "le message à envoyer en fonction de la règle"

calaos:requestUrl("https://smsapi.free-mobile.fr/sendmsg?user="..user.."&pass="..pass.."&msg="..urlencode(msg))

return true


3- Gestion d'un chauffage

By Raoulh

But : Script permettant de gérer le chauffage en fonction de la température des panneaux solaires du ballon EC et du plancher.

print("script chauffage start")
 local temp_panneaux = calaos:getInputValue("input_temp_3")
 local temp_ballonh = calaos:getInputValue("input_temp_0")
 local temp_plancher = calaos:getInputValue("input_temp_2")
 local consigne = calaos:getInputValue("intern_10")
 local consigne_ballon = calaos:getInputValue("intern_1")
 local consigne_plancher = calaos:getInputValue("intern_0")

 if temp_panneaux >= (temp_ballonh + consigne) then
     -- active pompe solaire si < max
     if temp_ballonh < 70 then
         calaos:setOutputValue("output_chauff_2", true)
     else
         calaos:setOutputValue("output_chauff_2", false)
     end

     -- force stop elect resistance
     calaos:setOutputValue("output_chauff_1", false)

     active_elec = false
 end

 -- Arret de la pompe solaire si temperature panneau insuffisante
 if temp_panneaux <= temp_ballonh then
     -- stop pompe solaire
     calaos:setOutputValue("output_chauff_2", false)

     active_elec = true
 end

 -- start/stop elec si consigne et active elec
 if active_elec then
     if temp_ballonh <= consigne_ballon then
         calaos:setOutputValue("output_chauff_1", true)
     end
     if temp_ballonh > (consigne_ballon + 1) then
         calaos:setOutputValue("output_chauff_1", false)
     end
 end

 -- start/stop plancher pompe si consigne
 if temp_plancher <= consigne_plancher then
     calaos:setOutputValue("output_chauff_0", true)
 end
 if temp_plancher > (consigne_plancher + 1) then
     calaos:setOutputValue("output_chauff_0", false)
 end

 -- pas besoin d'action, toujours retourner false
 return false