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

Need some LUA help


Question

Posted

Hi Guys,

Subject:

1)Before arm the house >>>>check doors or windows are safe

2)If not play Sonos and stop scene

3) if all safe than arm the house

What diid I do:

1)Created scene to check sensors>>> ok

2)PlaySonos>>>>>>ok

3)stop scene here I go wrong. In my LUA is lse if ..... but Sonos also play if all sensors are safe

Who can fill in the gap or point me in the right direction

--[[
%% properties
54 value
59 value
172 value
176 value
221 value
77 value
%% weather
%% events
%% globals
--]]

--
function debug(color, message)
     fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
end
--
--------------- Use function----------------------------------------------------
--
debug("red", "Check all door- and window sensors if they are safe then Arm (aanwezig) ");
-- Use colours like "white", "orange", "white, "green", "grey", "red", "blue".
--
--------------------------------------------------------------------------------
debug("orange","scene start")
debug("yellow", "switch Sonos off does not work")


local startSource = fibaro:getSourceTrigger();

--Hal
local    ElrocontactAlarm            =    69
local    DeurHal                        =    59
local    DeurHuis                    =    54
--Hoofdslaapkamer
local    DeurHoofdslaapkamer          =    173
--GastenkamerBoven
local    RaamSensorRechtsGastBoven    =    77
local    RaamSensorLinksGastBoven    =    221
local    DeurGastboven                =    176
--Woonkamer
local    Ipcam                         =    6
local    BewegingsmelderWoonkamer    =    166
local    StekkerStoelSjaak            =    14
local    StekkerStoelArleta            =    18
local    TVStekker                    =    16
--Eetkamer
local    BewegingsmelderEetkamer      =    145
--Keuken
local    VerlichtingLedstripKeuken    =    20
local    StekkerAfzuigpkap            =    214
local    SonosPlayer                    =    212
--Zoldeer
local    ZolderAfzuigunitSnelheid2    =    134
local    ZolderAfzuigunitSnelheid3    =    132

local    VerlichtingSpotKastLinks    =    203
local    VerlichtingHoofdslaapkamer    =    117


local startSource = fibaro:getSourceTrigger();

if (
 ( tonumber(fibaro:getValue(54, "value")) > 0 )
    --;then debug("red","deur open");
   
or
 ( tonumber(fibaro:getValue(59, "value")) > 0 )
or
 ( tonumber(fibaro:getValue(172, "value")) > 0 )
or
 ( tonumber(fibaro:getValue(176, "value")) > 0 )
or
 ( tonumber(fibaro:getValue(221, "value")) > 0 )
or
 ( tonumber(fibaro:getValue(77, "value")) > 0 )
or
startSource["type"] == "other"
)
 

then
    
    fibaro:call(SonosPlayer, "pressButton", "7");
        fibaro:call(SonosPlayer, "setSlider", "15", "60");
    
setTimeout(function()
fibaro:call(SonosPlayer, "setSlider", "15", "25");
end, 3*60*1000)
fibaro:debug("Sonos op lager volume na 3 minuten")
    
 --   setTimeout(function()
--        fibaro:call(SonosPlayer, "turnOff");
--    end, 3*60*1000)
--  fibaro:debug("Sonos uit")
 
 
 elseif
--( tonumber(fibaro:getValue(59, "value")) == 0 )

 
  ( tonumber(fibaro:getValue(54, "value")) == 0 )
    --;then debug("red","deur open");
   
and
 ( tonumber(fibaro:getValue(59, "value"))  == 0 )
and
 ( tonumber(fibaro:getValue(172, "value")) == 0 )
and
 ( tonumber(fibaro:getValue(176, "value")) == 0 )
and
 ( tonumber(fibaro:getValue(221, "value")) == 0 )
and
 ( tonumber(fibaro:getValue(77, "value")) == 0 )
and
startSource["type"] == "other"

 
then

 

--Hal_Overloop
    fibaro:call(DeurHal, "setArmed", "1");
  debug("green","DeurHal Armed");
 
    fibaro:call(ElrocontactAlarm, "setArmed", "1");
  debug("green","ElrocontactAlarm Armed");
 
  setTimeout(function()
        fibaro:call(DeurHuis, "setArmed", "1");
    end, 45000)
  debug("blue","DeurHuis Armed after 45 seconds");


--Hoofdslaapkamer
 
--    fibaro:call(DeurHoofdslaapkamer, "setArmed", "1");
--  debug("green","DeurHoofdslaapkamer Armed");
 
--GastenkamerBoven
 
    fibaro:call(RaamSensorLinksGastBoven, "setArmed", "1");
   debug("green","RaamSensorLinksGastBoven Armed");
    
    fibaro:call(RaamSensorRechtsGastBoven, "setArmed", "1");
  debug("green","RaamSensorRechtsGastBoven Armed");
   
    fibaro:call(DeurGastboven, "setArmed", "1");
  debug("green","DeurGastboven Armed");

  --Woonkamer
 
    fibaro:call(Ipcam, "turnOn");
  debug("green","Ipcam Switched On");
    
    fibaro:call(BewegingsmelderWoonkamer, "setArmed", "1");
  debug("green","BewegingsmelderWoonkamer Armed");
    
    fibaro:call(StekkerStoelSjaak, "TurnOff");
  debug("green","StekkerStoelSjaak Switched Off");

fibaro:call(TVStekker, "TurnOff");
  debug("green","TVStekker  Switched Off");

fibaro:call(StekkerStoelArleta, "TurnOff");
  debug("green","StekkerStoelArleta Switched Off");

--Eetkamer  

    fibaro:call(BewegingsmelderEetkamer, "setArmed", "1");
  debug("green","BewegingsmelderEetkamer Armed");

--Keuken

    fibaro:call(StekkerAfzuigpkap, "turnOff");
  debug("green","StekkerAfzuigpkap Switched Off");

fibaro:call(VerlichtingLedstripKeuken, "turnOff");
  debug("green","VerlichtingLedstripKeuken Switched Off");


--Serre

--Zolder
    fibaro:call(ZolderAfzuigunitSnelheid2, "turnOff");
  debug("green","ZolderAfzuigunitSnelheid2 Switched Off");

    fibaro:call(ZolderAfzuigunitSnelheid3, "turnOff");
  debug("green","ZolderAfzuigunitSnelheid3 Switched Off");

end
debug("orange","scene beeindigt")
fibaro:debug()

 

11 answers to this question

Recommended Posts

  • 0
Posted (edited)

I believe Sonos play also when you execute the scene manually (I mean by pressing start button), right?

Question, why you're using setTimeout() function... what will happen if the scene is triggered again and again by sensors? For example, all sensors safe and you start to count 45 seconds to arm the alarm. Let's say after 10 seconds , one of the sensors is breached... looks like the alarm will be armed anyway. (and I think the function usage is incorrect..)

in addition why you need startSource["type"] == "other"  condition?

 

 

Another concern you're sending turnOn and turnOff commands without validating the device state. It causes unnecessary Z-wave traffic and to create delays in the system

Edited by cag014
  • 0
  • Inquirer
  • Posted

    Hi Cag,

    This scene is partially converted from blockscene because I am new at this. So please bear with me.

    Sonos will play but not stop, this is a kind of anouying but not a big deal at the moment. If I have fix the more important issues I will look into it.

    Set time out is used by one sensor, front door, so I can arm my house inside and having 45 sec to go out. Did I do it wrong? Mmhh perhaps this one is giving me some problems because I i arm the house the Sonos starts to pay because of this?

    Start source other is coming frm the translation, but if  I dont need it I am happy because its always generating some LUA errors

    How to validate a command? You mean send >> off and see if you get off back? How todo?

    Thanks for your constructive comment

    • 0
    Posted
    17 minutes ago, Sjakie said:

    How to validate a command? You mean send >> off and see if you get off back? How todo?

    See below how to validate the state, before sending command.

    if tonumber(fibaro:getValue(ZolderAfzuigunitSnelheid2, "value")) >0 then  fibaro:call(ZolderAfzuigunitSnelheid2, "turnOff") end

    • 0
  • Inquirer
  • Posted

    Perhaps I do not understand properly.

    In my case  I check first if the sensors (doors)  are closed, if not I need to close the door and if yes than at the end after checking all >>>arm

    • 0
    Posted (edited)

    That's correct, but time to time the sensors reports their status (even no changes done) in this case you will send same commands again.

    In addition you have startSource["type"] == "other"  which will run again same commands.

     

    By the way, usually when you convert block scene to LUA (when setTimeout is required) you should have in Lua code

    function tempFunc()

    I believe during your modifications, somehow you have deleted this line.

    Edited by cag014
    • 0
    Posted (edited)
    1 hour ago, Sjakie said:

    Set time out is used by one sensor, front door, so I can arm my house inside and having 45 sec to go out. Did I do it wrong?

    So you execute this scene manually, before leaving home?

    How you disarm the alarm?

    Edited by cag014
    • 0
  • Inquirer
  • Posted

    startSource["type"] == "other" >>>>>>>>>deleted

    Yes I will start manually perhaps later I can use some Wifi or other thinghy to track if I am at home yes or no.

    REMARK: I have a separate alarm system but for me it is to limited.

                     this alarm system is covering all outside openings and warns me by phone and is connected with binairy sensor to HC2

                - HC2 will add a few inside protections and by alarm it will show my house as a kind of flikkering Christmas tree

    • 0
    Posted (edited)

    So, is it works now?

    I would like to suggest you to create virtual device with few buttons to arm alarm when you at home, leaving home and to disarm it. You can set label to see the status of all of the sensors and alarm states.

    Edited by cag014
    • 0
  • Inquirer
  • Posted

    Yes my scene is working, have to extend to all possibilities now, present, away, guest in house, guest outside.

    VD I have seen but till now no clue how to use this or implement. I have a VD to check sensors nice but I need to arm also.

     

    • 0
  • Inquirer
  • Posted

    See below how to validate the state, before sending command.

    if tonumber(fibaro:getValue(ZolderAfzuigunitSnelheid2, "value")) >0 then  fibaro:call(ZolderAfzuigunitSnelheid2, "turnOff") end 

    Ok got the next question(s)

    if the status is on because the scene is made to switch off than in my opinion less traffic for HC2 to send off command

    in yours it will generate more traffic, so I am confused

    I understand if the staus is not known your solution is more acurate.

    Please explain

    • 0
    Posted

    fibaro:getValue() function doesn't generate Ztraffic. The value comes from internal data base  of HC2 and not from the device.

    fibaro:call() finction always sent to device

     

     

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