Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
fr:liste_script [2015/12/23 18:39] eric64 |
fr:liste_script [2016/11/11 00:25] (current) mifrey Correction script panique |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== Liste des scripts LUA ====== |
\\ === 1- Modifier la couleur d’une lumière Led en fonction de la température de la pièce === | \\ === 1- Modifier la couleur d’une lumière Led en fonction de la température de la pièce === | ||
Line 6: | Line 6: | ||
**But :** Script permettant de modifier la couleur d’une led RGB en fonction de la température de la pièce | **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 | -- Title: Set RGB light output depending on Temperature | ||
-- | -- | ||
Line 60: | Line 60: | ||
- | < | + | < |
function urlencode(str) | function urlencode(str) | ||
if (str) then | if (str) then | ||
Line 88: | Line 88: | ||
**But :** Script permettant de gérer le chauffage en fonction de la température des panneaux solaires du ballon EC et du plancher. | **But :** Script permettant de gérer le chauffage en fonction de la température des panneaux solaires du ballon EC et du plancher. | ||
- | < | + | < |
print(" | print(" | ||
local temp_panneaux = calaos: | local temp_panneaux = calaos: | ||
Line 172: | Line 172: | ||
__Script :__ | __Script :__ | ||
- | < | + | < |
local RGBplafond = calaos: | local RGBplafond = calaos: | ||
local Wplafond = calaos: | local Wplafond = calaos: | ||
Line 197: | Line 197: | ||
//By eric64// | //By eric64// | ||
- | **But :** Script permettant de donner une valeur True ou False à une variable lors de l' | + | **But :** Script permettant de donner une valeur True ou False à une variable lors de l' |
- | < | + | < |
- | -- 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: | + | |
- | 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: | + | |
- | return true | + | |
- | + | ||
- | ****** | + | |
local Variable_Activation_Inter = calaos: | local Variable_Activation_Inter = calaos: | ||
Line 261: | Line 216: | ||
return true | return true | ||
</ | </ | ||
+ | |||
+ | \\ === 6- Détection d'une situation " | ||
+ | //By mifrey// | ||
+ | |||
+ | **But :** Script permettant de détecter une situation " | ||
+ | |||
+ | |||
+ | **Précisions :** Le script doit être mis dans les conditions d'une règle et être déclenché par tous les poussoirs voulus (je les ai mis tous chez moi). Il retourne true en cas de situation panique. Dans l' | ||
+ | |||
+ | Afin de d' | ||
+ | < | ||
+ | root@raspberrypi: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:34 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:35 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | Nov 11 00:16:46 ... LuaPrint: SCRIPT_CONDITIONS_PANIC: | ||
+ | |||
+ | ... | ||
+ | </ | ||
+ | |||
+ | __A créer dans CALAOS INSTALLER :__ | ||
+ | < | ||
+ | - Un timer (type InputTimer) : Pour mesurer le temps depuis la première pression sur le poussoir. Le timer est à régler sur quelques secondes. | ||
+ | - Un compteur (type InternalInt) : Pour compter le nombre de fois qu'un poussoir est actionné. | ||
+ | </ | ||
+ | |||
+ | __Script :__ | ||
+ | <code lua> | ||
+ | -- Detect a panic situation in which switches are pressed several times within a short time. | ||
+ | -- The script shall be called each time the state of a switch changes. | ||
+ | |||
+ | --if true then return false end -- Uncomment to disable the script | ||
+ | |||
+ | -- Script start | ||
+ | local script_name = " | ||
+ | print(script_name .. ": Start" | ||
+ | |||
+ | -- IOs id | ||
+ | local timer_id = " | ||
+ | local counter_id = " | ||
+ | |||
+ | -- Other variables to define | ||
+ | local panic_count = 12 -- Number of times the state of a switch must change within a specific time (typically 2 seconds) to trigger a panic situation | ||
+ | |||
+ | -- Read IOs | ||
+ | local timer = calaos: | ||
+ | local counter = calaos: | ||
+ | |||
+ | print(script_name .. ": timer = " .. tostring(timer)) | ||
+ | print(script_name .. ": counter = " .. tostring(counter)) | ||
+ | |||
+ | |||
+ | -- Max time exceeded or first count | ||
+ | if timer == " | ||
+ | print(script_name .. ": Max time exceeded, restart timer and counter." | ||
+ | -- Restart timer | ||
+ | timer = " | ||
+ | calaos: | ||
+ | print(script_name .. ": Set timer = " .. tostring(timer)) | ||
+ | -- First count | ||
+ | counter = 1; | ||
+ | calaos: | ||
+ | print(script_name .. ": Set counter = " .. tostring(counter)) | ||
+ | print(script_name .. ": End") | ||
+ | return false | ||
+ | -- Max time not exceeded | ||
+ | else | ||
+ | -- Count up | ||
+ | counter = counter + 1 | ||
+ | calaos: | ||
+ | print(script_name .. ": Max time not exceeded, count up. Set counter = " .. tostring(counter)) | ||
+ | |||
+ | -- Counts not reached, wait for the next count. | ||
+ | if counter < panic_count then | ||
+ | print(script_name .. ": Counts not reached, wait for the next count." | ||
+ | print(script_name .. ": end") | ||
+ | return false | ||
+ | -- Counts reached, panic mode. | ||
+ | else | ||
+ | print(script_name .. ": Counts reached, panic mode." | ||
+ | -- Stop timer | ||
+ | timer = " | ||
+ | calaos: | ||
+ | print(script_name .. ": Set timer = " .. tostring(timer)) | ||
+ | -- Reset counter | ||
+ | counter = 0; | ||
+ | calaos: | ||
+ | print(script_name .. ": Set counter = " .. tostring(counter)) | ||
+ | print(script_name .. ": end") | ||
+ | return true | ||
+ | end | ||
+ | end | ||
+ | |||
+ | |||
+ | print(script_name .. ": Oups, should never be there..." | ||
+ | return false | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | \\ === 7- Simulateur de présence | ||
+ | //By mifrey// | ||
+ | |||
+ | **But :** Script permettant de simuler une présence en allumant/ | ||
+ | |||
+ | **Règle :** Le script doit être mis dans les conditions d'une règle et être déclenché par le changement des IOs " | ||
+ | |||
+ | **Précisions :** Le script correspond à la machine d' | ||
+ | |||
+ | Pour adapter le script à votre situation, il faut modifier les variables définissant les adresses de vos lampes puis modifier la machine d' | ||
+ | |||
+ | Pour tester la séquence sans devoir attendre le couché du soleil, il faut mettre la variable %%" | ||
+ | |||
+ | Afin de d' | ||
+ | < | ||
+ | root@raspberrypi: | ||
+ | Oct 14 12:01:59 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:01:59 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:01:59 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:02 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:02 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:02 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:02 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:07 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:07 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:07 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:07 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:12 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:12 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:12 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | Oct 14 12:02:12 ... LuaPrint: SCRIPT_CONDITIONS_PRESENCE_SIMULATOR: | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | |||
+ | __A créer dans CALAOS INSTALLER :__ | ||
+ | < | ||
+ | - Une variable interne booléenne (type InternalBool) " | ||
+ | - Une plage horaire (type InPlageHoraire) " | ||
+ | - Un timer (type InputTimer) " | ||
+ | - Une variable interne entière (type InternalInt) " | ||
+ | </ | ||
+ | |||
+ | __Script :__ | ||
+ | <code lua> | ||
+ | -- Presence simulator | ||
+ | -- | ||
+ | -- Rule conditions: | ||
+ | -- This script | ||
+ | -- | ||
+ | -- Script triggers: | ||
+ | -- enable_id | ||
+ | -- evening_time_range_id | ||
+ | -- timer_id | ||
+ | -- | ||
+ | -- Rule actions: | ||
+ | -- None | ||
+ | |||
+ | --if true then return false end -- Uncomment to disable the script | ||
+ | |||
+ | -- Script start | ||
+ | local script_name = " | ||
+ | print(script_name .. ": Start" | ||
+ | |||
+ | -- IOs defined in Calaos Installer | ||
+ | local enable_id = " | ||
+ | local evening_time_range_id = " | ||
+ | local timer_id = " | ||
+ | local state_id = " | ||
+ | |||
+ | local HJ_BAL_id = " | ||
+ | local SAL_L1_id = " | ||
+ | local HJ_L1L2_id = " | ||
+ | local HN_L1_id = " | ||
+ | local SDB_L1_id = " | ||
+ | local DR_L1_id = " | ||
+ | local CH1_L1_id = " | ||
+ | |||
+ | -- Other variables | ||
+ | local script_test_enable = false -- Set to true to test the script with a short time between each state change, e.g., 5 seconds | ||
+ | local script_test_timer_duration = " | ||
+ | |||
+ | |||
+ | -------------------------------------------------------------------------------- | ||
+ | -- Functions | ||
+ | -------------------------------------------------------------------------------- | ||
+ | |||
+ | -- Split a string (from http:// | ||
+ | function string: | ||
+ | assert(sSeparator ~= '' | ||
+ | assert(nMax == nil or nMax >= 1) | ||
+ | |||
+ | local aRecord = {} | ||
+ | |||
+ | if self:len() > 0 then | ||
+ | local bPlain = not bRegexp | ||
+ | nMax = nMax or -1 | ||
+ | |||
+ | local nField, nStart = 1, 1 | ||
+ | local nFirst, | ||
+ | while nFirst and nMax ~= 0 do | ||
+ | aRecord[nField] = self: | ||
+ | nField = nField+1 | ||
+ | nStart = nLast+1 | ||
+ | nFirst, | ||
+ | nMax = nMax-1 | ||
+ | end | ||
+ | aRecord[nField] = self: | ||
+ | end | ||
+ | |||
+ | return aRecord | ||
+ | end | ||
+ | |||
+ | -- Convert a time (format " | ||
+ | function time_to_ms (t) | ||
+ | local ms = 0 | ||
+ | for k,x in next, string.split(t, | ||
+ | if k == 1 then | ||
+ | ms = ms + x*60*60*1000 | ||
+ | elseif k == 2 then | ||
+ | ms = ms + x*60*1000 | ||
+ | elseif k == 3 then | ||
+ | ms = ms + x*1000 | ||
+ | elseif k == 4 then | ||
+ | ms = ms + x | ||
+ | end | ||
+ | end | ||
+ | return ms | ||
+ | end | ||
+ | |||
+ | -- Convert ms to a time (format " | ||
+ | function ms_to_time (ms) | ||
+ | local mi = math.floor(ms % 1000); | ||
+ | local s = math.floor((ms/ | ||
+ | local m = math.floor((ms/ | ||
+ | local h = math.floor((ms/ | ||
+ | return (h .. ":" | ||
+ | end | ||
+ | |||
+ | -- Set the new state number. | ||
+ | function state_change (st) | ||
+ | state = st | ||
+ | calaos: | ||
+ | print(script_name .. ": State=" | ||
+ | end | ||
+ | |||
+ | -- Set the timer for the next state change. | ||
+ | function timer_set (low, high) | ||
+ | -- Generate a random time | ||
+ | local ms_low = time_to_ms(low) | ||
+ | local ms_high = time_to_ms(high) | ||
+ | math.randomseed(os.time()) | ||
+ | local ms = math.random(ms_low, | ||
+ | local t = ms_to_time(ms) | ||
+ | -- Set and start the timer for the next state | ||
+ | print(script_name .. ": Set timer = " .. t) | ||
+ | calaos: | ||
+ | calaos: | ||
+ | -- Script test | ||
+ | if script_test_enable == true then | ||
+ | calaos: | ||
+ | end | ||
+ | print(script_name .. ": End") | ||
+ | end | ||
+ | |||
+ | |||
+ | -------------------------------------------------------------------------------- | ||
+ | -- State machine | ||
+ | -------------------------------------------------------------------------------- | ||
+ | |||
+ | -- Get initial values | ||
+ | local timer = calaos: | ||
+ | local evening = calaos: | ||
+ | local enable = calaos: | ||
+ | local state = calaos: | ||
+ | |||
+ | -- Overwrite values if testing the script | ||
+ | if script_test_enable == true then | ||
+ | if state < 4 then | ||
+ | evening = true | ||
+ | else | ||
+ | evening = false | ||
+ | end | ||
+ | end | ||
+ | |||
+ | -- Simulator reset | ||
+ | if state == 14 or enable == false then | ||
+ | state_change (0) | ||
+ | -- Timer reset | ||
+ | calaos: | ||
+ | print(script_name .. ": End") | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Staircase: switch on | ||
+ | if state == 0 and evening == true then | ||
+ | state_change (1) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Living room: switch on | ||
+ | if state == 1 and timer == " | ||
+ | state_change (2) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Hall 1: switch on | ||
+ | if state == 2 and timer == " | ||
+ | state_change (3) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Hall 1: switch off | ||
+ | if state == 3 and timer == " | ||
+ | state_change (4) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Living room: switch off | ||
+ | if state == 4 and timer == " | ||
+ | state_change (5) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Hall 2: switch on | ||
+ | if state == 5 and timer == " | ||
+ | state_change (6) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Straircase: switch off | ||
+ | if state == 6 and timer == " | ||
+ | state_change (7) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Bathroom: switch on | ||
+ | if state == 7 and timer == " | ||
+ | state_change (8) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Bathroom: switch off | ||
+ | if state == 8 and timer == " | ||
+ | state_change (9) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Hall 2: switch off | ||
+ | if state == 9 and timer == " | ||
+ | state_change (10) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Dressing: switch on | ||
+ | if state == 10 and timer == " | ||
+ | state_change (11) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Dressing: switch off | ||
+ | if state == 11 and timer == " | ||
+ | state_change (12) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Bedroom 1: switch on | ||
+ | if state == 12 and timer == " | ||
+ | state_change (13) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | -- Bedroom 1: switch off | ||
+ | if state == 13 and timer == " | ||
+ | state_change (14) | ||
+ | calaos: | ||
+ | timer_set(" | ||
+ | return false | ||
+ | end | ||
+ | |||
+ | |||
+ | print(script_name .. ": Did nothing" | ||
+ | return false | ||
+ | </ | ||
+ |