I have used a LUA script which is triggered by pushing the switch 2 on a Fibaro switch. Depending on whether the key is pushed once, twice or held, I control another device (a light) according to set rules. How the key is pushed, is found by the variable pressSource = fibaro:getSourceTrigger().event.data. This solution has been used previously by several contributors on the forum.
My current code looks like this (only first part shown):
--[[
%% properties
%% events
394 CentralSceneEvent
%% globals
--]]
-- Uses first slave for "CentralSceneEvent" ID (not master, not switch itself). Here 394
local trigger = fibaro:getSourceTrigger()
if (trigger.type == "other") then
fibaro:debug("Scene started by clicking 'start' button")
else
local pressSource = fibaro:getSourceTrigger().event.data
fibaro:debug("New: CentralSceneEvent received from key: " .. pressSource.keyId)
if (pressSource.keyId == 2) then
local ledId = "306"
local ledValue = fibaro:getValue(ledId, "value")
if pressSource.keyAttribute == "Pressed" then
fibaro:debug("Pressed")
if ledValue == "0" then
fibaro:call(ledId, "turnOn")
else
fibaro:call(ledId, "turnOff")
end
elseif pressSource.keyAttribute == "Pressed2" then
fibaro:debug("Pressed 2 times")
fibaro:call(ledId, "setValue", "100")
elseif pressSource.keyAttribute == "HeldDown" then
-- etc. (complete code not shown)
I now want to add a second trigger, i.e. another Fibaro switch being pushed. Depending on which switch is used, I want different lights to be adjusted. Below is my first edit (still incomplete). In line 5, the new trigger 494 is added. How do I know if the scene was triggered by 394 or 494? The answer is probably in fibaro:getSourceTrigger(), but I cannot find the complete specification for this function documented anywhere. Specifically:
- How do I find whether 394 or 494 was the trigger? The syntax trigger.event.id in line 14 is my guest guess. What is correct?
- Once I have the right triggerID, I can easily make the variable ledID dependent on triggerID, by having two related lists (arrays): {394, 494} for the triggers and {306, 406} for the corresponding LED lights. This needs to be implemented in line 18.
Can anyone please provide a more complete specification for the data returned by fibaro:getSourceTrigger in HC2, and show me how I can use it to implement double triggers? Or are you all too busy converting to HC3?
PS: I have simplified this to TWO triggers. In reality I want to have several more. But if I can do two, I can do any number.
--[[
%% properties
%% events
394 CentralSceneEvent
494 CentralSceneEvent -- <<--- NEW TRIGGER
%% globals
--]]
-- Uses first slave for "CentralSceneEvent" ID (not master, not switch itself). Here 394 and 494 respectively.
local trigger = fibaro:getSourceTrigger()
if (trigger.type == "other") then
fibaro:debug("Scene started by clicking 'start' button")
else
local triggerID = trigger.event.id -- <<--- WHAT IS CORRECT SYNTAX??
local pressSource = fibaro:getSourceTrigger().event.data
fibaro:debug("New: CentralSceneEvent received from key: " .. pressSource.keyId)
if (pressSource.keyId == 2) then
local ledId = "306" -- <<<< NEEDS TO BE CHANGED TO CORRESPOND TO triggerID
local ledValue = fibaro:getValue(ledId, "value")
if pressSource.keyAttribute == "Pressed" then
fibaro:debug("Pressed")
if ledValue == "0" then
fibaro:call(ledId, "turnOn")
else
fibaro:call(ledId, "turnOff")
end
elseif pressSource.keyAttribute == "Pressed2" then
fibaro:debug("Pressed 2 times")
fibaro:call(ledId, "setValue", "100")
elseif pressSource.keyAttribute == "HeldDown" then
fibaro:debug("HeldDown")
-- etc. (complete code not shown)