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/11/19 09:53] 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 153: | Line 153: | ||
- | __A créer dans CALAOS_INSTALLER | + | __A créer dans CALAOS INSTALLER |
< | < | ||
- IO inter_booleen. " | - IO inter_booleen. " | ||
Line 159: | Line 159: | ||
</ | </ | ||
- | __Règles à créer pour chaque | + | __Règles à créer pour chaque |
< | < | ||
SI RGBplafond == changed | SI RGBplafond == changed | ||
Line 171: | Line 171: | ||
</ | </ | ||
- | __script__ | + | __Script :__ |
- | < | + | < |
local RGBplafond = calaos: | local RGBplafond = calaos: | ||
local Wplafond = calaos: | local Wplafond = calaos: | ||
Line 190: | Line 190: | ||
end | end | ||
| | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | \\ === 5- Conserver la valeur d'un appui sur un BP dans une variable | ||
+ | //By eric64// | ||
+ | |||
+ | **But :** Script permettant de donner une valeur True ou False à une variable lors de l' | ||
+ | |||
+ | <code lua> | ||
+ | local Variable_Activation_Inter = calaos: | ||
+ | |||
+ | if Variable_Activation_Inter == false then -- si ma variable est fausse (je n'ai donc pas allumé les lumières par BP) | ||
+ | calaos: | ||
+ | calaos: | ||
+ | calaos: | ||
+ | calaos: | ||
+ | | ||
+ | elseif Variable_Activation_Inter == true then -- sinon si ma variable est vrai (j' | ||
+ | calaos: | ||
+ | calaos: | ||
+ | calaos: | ||
+ | calaos: | ||
+ | end | ||
+ | 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 | ||
</ | </ | ||