Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scenario panique
#19
Ca marche Raoul c'est bien un string !  Big Grin

Ce qui m'a induit en erreur et me faisait croire que c'etait un boolean c'est l'editeur de script de Calaos Installer qui indiquait l'erreur "Error Runtime error : [string "CalaosScript"]:18: attempt to concatenate a boolean value" avec le code suivant :


Code:
print(script_name .. ": timer = " .. calaos:getInputValue(timer_id))

J'ai donc du ajouter un tostring() pour que Calaos Installer accepte le script.

Pour finir, voici le script complet qui fonctionne pour ceux que ca interesse. Le script doit etre mis dans les conditions de la regle et etre declenche par tous les poussoirs voulus (je les ai mis tous chez moi).  Il retourne true en cas de situation panique.  Dans l'exemple, il retourne true si les poussoirs sont presses 6 fois (12 changement d'etats) dans les 2 secondes (le timer est a definir dans Calaos Installer). A mettre sur https://www.calaos.fr/wiki/fr/liste_script ?


Code:
-- 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 = "SCRIPT_CONDITIONS_PANIC"
print(script_name .. ": Start")

-- IOs id
local timer_id = "input_58" -- InputTimer type
local counter_id = "intern_0" -- InternalInt type

-- 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:getInputValue(timer_id) -- ATTENTION: getInputValue(InputTimer type) returns a string type.  Timer is false when timer starts or stops, true when timer is done.
local counter = calaos:getInputValue(counter_id)

print(script_name .. ": timer = " .. tostring(timer))
print(script_name .. ": counter = " .. tostring(counter))


-- Max time exceeded or first count
if timer == "true" or counter == 0 then
    print(script_name .. ": Max time exceeded, restart timer and counter.")
    -- Restart timer
    timer = "start"
    calaos:setOutputValue(timer_id, timer)
    print(script_name .. ": Set timer = " .. tostring(timer))
    -- First count
    counter = 1;
    calaos:setOutputValue(counter_id, counter)
    print(script_name .. ": Set counter = " .. tostring(counter))
    print(script_name .. ": End")
    return false
-- Max time not exceeded
else
    -- Count up
    counter = counter + 1
    calaos:setOutputValue(counter_id, counter)
    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 = "stop"
        calaos:setOutputValue(timer_id, timer)
        print(script_name .. ": Set timer = " .. tostring(timer))
        -- Reset counter
        counter = 0;
        calaos:setOutputValue(counter_id, counter)
        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
  calaos-os-raspberrypi2-v3.0-alpha6-14-g341535a-2021-01-17 on Raspberry Pi 2 ▶ Wago_2.2/wago_881.pro on Wago 750-881 ▶ DS18B20 sensors on Pi GPIO ▶ Node-RED









Reply


Messages In This Thread
Scenario panique - by mifrey - 02-16-2016, 03:29 PM
RE: Scenario panique - by Arnaud - 02-17-2016, 09:03 AM
RE: Scenario panique - by mifrey - 02-18-2016, 01:44 PM
RE: Scenario panique - by mifrey - 02-22-2016, 01:42 PM
RE: Scenario panique - by diouk - 02-22-2016, 04:15 PM
RE: Scenario panique - by Arnaud - 02-23-2016, 09:10 AM
RE: Scenario panique - by raoulh - 02-23-2016, 10:15 AM
RE: Scenario panique - by mifrey - 02-27-2016, 01:33 PM
RE: Scenario panique - by raoulh - 02-28-2016, 10:20 AM
RE: Scenario panique - by diouk - 02-28-2016, 12:40 PM
RE: Scenario panique - by mifrey - 02-28-2016, 01:38 PM
RE: Scenario panique - by raoulh - 02-29-2016, 09:33 AM
RE: Scenario panique - by mifrey - 07-24-2016, 11:52 PM
RE: Scenario panique - by raoulh - 07-25-2016, 08:47 AM
RE: Scenario panique - by mifrey - 07-25-2016, 12:39 PM
RE: Scenario panique - by raoulh - 07-25-2016, 01:28 PM
RE: Scenario panique - by mifrey - 07-25-2016, 03:01 PM
RE: Scenario panique - by raoulh - 07-25-2016, 03:17 PM
RE: Scenario panique - by mifrey - 07-26-2016, 11:21 AM
RE: Scenario panique - by mifrey - 07-28-2016, 02:15 PM
RE: Scenario panique - by raoulh - 07-26-2016, 11:58 AM
RE: Scenario panique - by mifrey - 07-27-2016, 12:48 PM
RE: Scenario panique - by raoulh - 07-28-2016, 04:18 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)