Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Trigger of a Scene x actions?


Question

Posted

Hi,
I need a scene in Lua (HC3) where 10 door/window sensors would be the triggers to activate the buttons in a "QA".
Doubt: In the ACTIONS part, could someone give an example of the best way to make the code for:
1. When trigger is triggered by sensor 1 (sensor violated/window open), "QA" button 1 is pressed.
2. when the trigger is triggered by sensor 2 ( sensor violated / door open), "QA" button 2 is pressed and so on ....

Thank you for any help.

6 answers to this question

Recommended Posts

  • 0
Posted (edited)

This proof of concept works on my HC3

To make this POC work on its own, do the following:

  • Create a Quick App
    • Add 10 buttons through the UI named buttons named button101 through button110
    • Set the function for the button through the ui and name them button101_onReleased though button110_onReleased
    • Create a label named "label"
    • Replace all the code with Quick App code that is listed below
  • Create a LUA Scene
    • Add the scene conditions code listed below
    • Add the scene actions listed below
    • replace my hard coded device id with the actual device id of your quick app: local _id = 363:
  • Run the scene manually or press a quick app button and then observe the label.

 

 

To make this work with your actual devices:

  • remove the randomizer line: _argumentX = math.random(101110)
  • Change the scene condition device ids
  • Change the quick app device id decision tree

 



SCENE CODE - CONDITIONS:

 
 
{
  conditions =
  {
        {id=101,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=102,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=103,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=104,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=105,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=106,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=107,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=108,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=109,isTrigger=true,operator="==",property="value",type="device",value=true},
        {id=110,isTrigger=true,operator="==",property="value",type="device",value=true}
   },
  operator = "any"
}
 
 
 

SCENE CODE - ACTIONS:

 

 

 

local sceneName = api.get("/scenes/"..sceneId).name
 
print("--==================================================")
print("BEGIN SCENE: "..sceneName)
print("--==================================================")
 
-- the target quickApp device.id
local _id = 363
 
-- the target quickApp function you make to handle this call
local _function = "breachHandler"
 
-- send the sourceTrigger.id to the Quick App function if you want.
local _argumentX = sourceTrigger.id
 
--Note: running the scene manually shows an id of 2 for me, obviously not the device id for any sensor.
-- i will override this to usd a random device number between 101 and 110
_argumentX = math.random(101110)
 
-- my quick app function has been made with two arguments FYI
local _argumentY = sceneName
 
-- debug and execute
print("executing the fibaro.call command...")
print("_id:"..tostring(_id))
print("_function:"..tostring(_function))
print("_argumentX:"..tostring(_argumentX))
print("_argumentY:"..tostring(_argumentY))
 
fibaro.call(_id, _function, _argumentX, _argumentY)             
 
print("--==================================================")
print("END SCENE: "..sceneName)

print("--==================================================")

 


QUICK APP CODE:

 
 
 
function QuickApp:onInit()
    self:debug("onInit")
end
 
function QuickApp:breachHandler(deviceId, sceneName)
    self:debug("breachHandler")
    self:debug("deviceId:"..tostring(deviceId))
    self:debug("sceneName:"..tostring(sceneName))
 
    -- simulate the button press
    -- create an event object
    -- send it to the handler
 
    local event = {
            elementName = sceneName,
            deviceId = deviceId,
            eventType = "breachHandler",
            values = nil
        }
 
    if      deviceId == 101 then
        self:button101_onReleased(event)
    elseif  deviceId == 102 then
        self:button102_onReleased(event)
    elseif  deviceId == 103 then
        self:button103_onReleased(event)
    elseif  deviceId == 104 then
        self:button104_onReleased(event)
    elseif  deviceId == 105 then
        self:button105_onReleased(event)
    elseif  deviceId == 106 then
        self:button106_onReleased(event)
    elseif  deviceId == 107 then
        self:button107_onReleased(event)
    elseif  deviceId == 108 then
        self:button108_onReleased(event)
    elseif  deviceId == 109 then
        self:button109_onReleased(event)
    elseif  deviceId == 110 then
        self:button110_onReleased(event)
    end
 
    self:debug("END QUICK APP FUNCTION:".."QuickApp:breachHandler")
end
 
function QuickApp:button101_onReleased(event)
    self:debug("button101_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button102_onReleased(event)
    self:debug("button102_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button103_onReleased(event)
    self:debug("button103_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button104_onReleased(event)
    self:debug("button104_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button105_onReleased(event)
    self:debug("button105_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button106_onReleased(event)
    self:debug("button106_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button107_onReleased(event)
    self:debug("button107_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button108_onReleased(event)
    self:debug("button108_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button109_onReleased(event)
    self:debug("button109_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:button110_onReleased(event)
    self:debug("button110_onReleased")
    self:updateMyLabel(event)
end
 
function QuickApp:updateMyLabel(event)
    self:debug("updateMyLabel")
    self:updateView("label""text""it looks like deviceId:"..event.deviceId.." pressed button "..event.elementName.."during event type:"..event.eventType)
end

 

 
Edited by RedRocketFire
  • 0
  • Inquirer
  • Posted

     

    Please login or register to see this link.

    Please login or register to see this link.

    Wow!!!
    thank you very much for the wealth of details in the explanations and the complete codes .....

    I will make the adaptations and test ..... thank you very much for the help.

    Best Regards,

    Jorge

    • Thanks 1
    • 0
    Posted (edited)

    You can do this with less code.

     

    1. Create a QA with the buttons;

    2. Create a Lua scene with the conditions:

     

    Please login or register to see this code.

     

    3. Now use the variable sourceTrigger to detect which door/window sensor triggered the scene and press the button of the QA:

     

    Please login or register to see this code.

     

    Edited by Joep
    fix error in if
    • 0
  • Inquirer
  • Posted (edited)
    8 hours ago, Joep said:

    You can do this with less code.

     

    1. Create a QA with the buttons;

    2. Create a Lua scene with the conditions:

     

    Please login or register to see this code.

     

    3. Now use the variable sourceTrigger to detect which door/window sensor triggered the scene and press the button of the QA:

     

    Please login or register to see this code.

     

    Hello joep....
    thanks again for your time to help me.....
    I tested the code here....it gave the following error....

     

    Edit....

    Joep, I think I figured it out... If sourceTrigger.id == 101 then

    Thanks

     

    Please login or register to see this image.

    /monthly_2023_04/image.png.a7a2dc6f32b491258bd6ec5e3cba0ee5.png" />

    Edited by jorge rintaro
    • 0
    Posted
    2 hours ago, jorge rintaro said:

    Hello joep....
    thanks again for your time to help me.....
    I tested the code here....it gave the following error....

     

    Edit....

    Joep, I think I figured it out... If sourceTrigger.id == 101 then

    Thanks

     

    Please login or register to see this link.

    My fault. You are correct. I made a typo. I’ll change the original post.

    • 0
  • Inquirer
  • Posted
    27 minutes ago, Joep said:

    Minha culpa. Você está certo. Eu cometi um erro de digitação. Vou mudar o post original.

    Joep,
    trial and error on my part.....luck.
    thank you, everything works perfect.

    • Like 1

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...