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 [2016/10/14 11:47] mifrey Ajout du simulateur de présence |
fr:liste_script [2016/11/11 00:25] (current) mifrey Correction script panique |
||
---|---|---|---|
Line 225: | Line 225: | ||
**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' | **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 :__ | __A créer dans CALAOS INSTALLER :__ | ||
Line 235: | Line 255: | ||
<code lua> | <code lua> | ||
-- Detect a panic situation in which switches are pressed several times within a short time. | -- Detect a panic situation in which switches are pressed several times within a short time. | ||
- | -- The script | + | -- The script |
+ | |||
--if true then return false end -- Uncomment to disable the script | --if true then return false end -- Uncomment to disable the script | ||
+ | |||
-- Script start | -- Script start | ||
local script_name = " | local script_name = " | ||
- | print(script_name .. ": | + | print(script_name .. ": |
- | + | ||
- | -- IO id | + | -- IOs id |
local timer_id = " | local timer_id = " | ||
local counter_id = " | local counter_id = " | ||
+ | |||
-- Other variables to define | -- 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 | 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 timer and counter value at script start | + | print(script_name .. ": timer = " .. tostring(timer)) |
- | print(script_name .. ": timer = " .. tostring(calaos: | + | print(script_name .. ": counter = " .. tostring(counter)) |
- | print(script_name .. ": counter = " .. tostring(calaos: | + | |
- | -- Get timer status: Timer is false when timer starts | + | |
- | local timer = calaos: | + | -- Max time exceeded |
- | + | if timer == " | |
- | -- Timer is done, reset timer and counter. | + | print(script_name .. ": |
- | if timer == " | + | -- Restart timer |
- | print(script_name .. ": | + | timer = " |
- | | + | calaos: |
- | calaos: | + | print(script_name .. ": |
- | print(script_name .. ": timer = " .. tostring(calaos: | + | -- First count |
- | print(script_name .. ": counter = " .. tostring(calaos: | + | counter = 1; |
- | print(script_name .. ": | + | |
+ | print(script_name .. ": | ||
+ | print(script_name .. ": | ||
return false | return false | ||
- | end | + | -- Max time not exceeded |
- | + | ||
- | -- Increment the counter | + | |
- | local counter = calaos: | + | |
- | calaos: | + | |
- | + | ||
- | -- Timer is not done and counts not reached, continues to count. | + | |
- | if counter < panic_count then | + | |
- | print(script_name .. ": Timer is not done and counts not reached, continue." | + | |
- | print(script_name .. ": timer = " .. tostring(calaos: | + | |
- | print(script_name .. ": counter = " .. tostring(calaos: | + | |
- | print(script_name .. ": end" | + | |
- | return false | + | |
- | -- Timer is not done and counts reached, panic mode. | + | |
else | else | ||
- | | + | -- Count up |
- | print(script_name .. ": timer = " | + | counter = counter + 1 |
- | print(script_name .. ": | + | calaos: |
- | calaos: | + | print(script_name .. ": |
- | | + | |
- | print(script_name .. ": end" | + | -- Counts |
- | return true | + | 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 .. ": | ||
+ | -- Stop timer | ||
+ | timer = "stop" | ||
+ | calaos:setOutputValue(timer_id, timer) | ||
+ | print(script_name .. ": | ||
+ | -- Reset counter | ||
+ | counter = 0; | ||
+ | calaos: | ||
+ | print(script_name .. ": Set counter = " .. tostring(counter)) | ||
+ | print(script_name .. ": end" | ||
+ | return true | ||
+ | end | ||
end | end | ||
+ | |||
print(script_name .. ": Oups, should never be there..." | print(script_name .. ": Oups, should never be there..." | ||
Line 299: | Line 329: | ||
//By mifrey// | //By mifrey// | ||
- | **But :** Script permettant de simuler une présence en allumant/ | + | **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 " | **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' | + | **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: | ||
+ | ... | ||
+ | </ | ||
- | script_test_enable | ||
__A créer dans CALAOS INSTALLER :__ | __A créer dans CALAOS INSTALLER :__ |