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

[Help Needed] Lua code to get the device which triggered alarm


Question

Posted

Hi,

 

Does anyone has a smart idea/code to get the device ID/Name of the device which triggered the alarm?

 

Preferable a solution with flexible device detection, meaning, without the need to store the ID's in static tables in code.

 

Thank you in advance!

12 answers to this question

Recommended Posts

  • 1
Posted

@Lambik

hi

try this:

 

local trigger = fibaro:getSourceTrigger()
local device = fibaro:getName(trigger['deviceID'])

 

no need for tables etc, i use this for my alarm trigger detection

  • 0
Posted

The topic has been moved from "

Please login or register to see this link.

" to "

Please login or register to see this link.

".

 

Temat został przeniesiony z "

Please login or register to see this link.

" do "

Please login or register to see this link.

".

  • 0
Posted

@Lambik

Did you try push button "Configuration" in Alarm Panel, advanced options ?

  • 0
Posted

Hi,

 

I have this code for each device (probably I could have only one, but I don't know to do it... if some one want upgrade it...) 

It send me a push message, and there I identificate the device. After the alarm is triggered, turns on the siren and turns off 1 minute later.

It works for me :)

 

22 is ID of my PIR

11 is my ID of my phone

233 is ID of a sirene

 

--[[
%% properties
22 value
22 armed
%% weather
%% events
%% globals
--]]

 

-- Scene                : Send Push Message
-- Version              : 1.0
-- Date Created    : 15 Dezember 2017
-- Last Changed  : 15 Dezember 2017
-- HC Version       : Home Center 2 v4.152 Beta
-- Created By        : Alex Vidigal
-- Purpose            : Identify alarm trigger

 

local startSource = fibaro:getSourceTrigger();
if (
 ( (tonumber(fibaro:getValue(22, "value")) > 0 and tonumber(fibaro:getValue(22, "armed")) > 0) )
or
startSource["type"] == "other"
)

 

then
    fibaro:call(11, "sendPush", "Alarm from My Room");

fibaro:call(233, "turnOn");
    fibaro:sleep(60*1000);
    fibaro:call(233, "turnOff"); 

 

end

 

I Hope it helps 

 

Alex

  • 0
  • Inquirer
  • Posted

    Thank you guys for responding!

     

    6 hours ago, Jacek Stark said:

    @Lambik

    Did you try push button "Configuration" in Alarm Panel, advanced options ?

    As far as I known this is not possible in a direct way. I use a scene, added to actions, which activates a virtual device button.

    With this button I send a command to a Raspberry Pi (Node-Red) which send an alarm message with camera snapshots to my Telegram-bot. The only thing needed is the name of the sensor which triggered the alarm to complete the Telegram message.

     

    5 hours ago, morpheus75 said:

    @Lambik

    hi

    try this:

     

    local trigger = fibaro:getSourceTrigger()
    local device = fibaro:getName(trigger['deviceID'])

     

    no need for tables etc, i use this for my alarm trigger detection

    Is fibaro:getSourceTrigger() getting me the right ID of the alarm which triggered the alarm? What about ['deviceID']? Is a table with ID's returned by the getSourceTrigger()?

    Please explain?

     

    2 hours ago, AlexVidigal said:

    Hi,

     

    I have this code for each device (probably I could have only one, but I don't know to do it... if some one want upgrade it...) 

    It send me a push message, and there I identificate the device. After the alarm is triggered, turns on the siren and turns off 1 minute later.

    It works for me :)

     

    .......

     

    I Hope it helps 

     

    Alex

    Thank you Alex, but with your solution you need to get all sensors ID's into the code. When a sensor is added, changed or removed, you have change the code.

    Is was searching for a solution where I get the ID of the device responsible for triggering the alarm.

    • 0
    Posted
    4 minutes ago, Lambik said:

    Thank you guys for responding!

    ....

    Thank you Alex, but with your solution you need to get all sensors ID's into the code. When a sensor is added, changed or removed, you have change the code.

    Is was searching for a solution where I get the ID of the device responsible for triggering the alarm.

     

    Yes it's true, but you are not adding security devices all the time... You only have work the first time.

    The code is always the same, only changes the device ID and name. If you add more devices, copy the scene and change the ID and name again.
    But I believe that what you want can be done. 

    I don't know if I can help you because I don't know enough LUA code ... I'll try :)  

     

    Alex

    • 0
  • Inquirer
  • Posted (edited)

    Thank you @AlexVidigal, it's appreciated!

     

    We just see what solutions @morpheus75 and @Jacek Stark have to offer... ;)

    Edited by Lambik
    Editted @users
    • 0
    Posted

    Hi Lambik,

     

    The code from your [VD] Presence Detector don't give you what you need?


    Alex

    • 0
    Posted

    @Lambik

     

    local trigger = fibaro:getSourceTrigger()
    this gets the ID of the device that triggered the scene. so just a standard command

     

    local device = fibaro:getName(trigger['deviceID'])

    this part checks its own api to get the name of the device from the ID. it will return the name of the device based on what you have named it

     

    hope this helps

    • 0
  • Inquirer
  • Posted
    1 minute ago, morpheus75 said:

    @Lambik

     

    local trigger = fibaro:getSourceTrigger()
    this gets the ID of the device that triggered the scene. so just a standard command

     

    local device = fibaro:getName(trigger['deviceID'])

    this part checks its own api to get the name of the device from the ID. it will return the name of the device based on what you have named it

     

    hope this helps

    Clear explanation, thank you @morpheus75

     

    But.... ;)

    When the 'Fibaro Alarm' is triggered by a breach from a armed device, the 'Alarm Panel --> Advanced --> Add Action --> <Scene to trigger>' will trigger the scene.

     

    Doesn't this mean the alarm panel is the source of the trigger, not the device which breached the alarm?

    • 0
    Posted

    To be honest I don't know as I don't use the alarm panel and I have written my own scenes.

    These 2 lines I use to send me a push notification to my phone and an email and a telegram bot message.

    • 0
  • Inquirer
  • Posted (edited)
    10 hours ago, AlexVidigal said:

    The code from your [VD] Presence Detector don't give you what you need?

    Good point, well observed @AlexVidigal!!

    I considered that also, but I wanted to see if there's a more simple way to implement.

     

    8 minutes ago, morpheus75 said:

    To be honest I don't know as I don't use the alarm panel and I have written my own scenes.

    These 2 lines I use to send me a push notification to my phone and an email and a telegram bot message.

    Thank you @morpheus75. I need to do some tests. If it's not working I have to go with @AlexVidigal suggestion.

     

    FYI.

     

    Did some tests. The scene, triggered by the alarm panel, reports the source of the trigger as type 'other'. No device ID.

     

    Have to do some serious coding, I'm afraid of. Keep you informed.

    Edited by Lambik

    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...