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


Recommended Posts

  • Topic Author
  • Ok, that's the problem.

    That means that you can do 596:on and 596:off. However, to toggle you need to know if it is playing or not - how do you do read the status?

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 43 minutes ago, jompa68 said:

    Possible to do thia

    Please login or register to see this code.

     

    Ok, a bit more elaborate

    Please login or register to see this code.

    I assume they return 'on' and 'off' as state. Otherwise change to whatever value represents that.

     

    I'm not a fan that Fibaro "reuses" commands like "turnOn" this way. Many devices you want to toggle and one usually implements that with getValue to get the current value. Now you need to treat different devices specially. . An alternative would be if they implemented a "toggle" command, and that all devices that accepts "turnOn" and "turnOff" also accepted "toggle".

    Edited by jgab
    Link to comment
    Share on other sites

    jgab, Working through all examples in your previous conversations in my effort to change most of my scenes to your EventRunner model. Succeeded so far with all my light scenes, even 'Närvarosimulering'. Stumbled on  this code in your alarm example:

     

    Quote

     

    -- If safe for 20min during night, consider quietAtNight -- used for enabling ring
      rule("for(00:20,dwSensors:safe & pirSensors:safe & 22:30..05:00 ) => post(#quietAtNight); repeat()")
    -- If safe for 10min, consider quiet, used for turning off running alarm
      rule("for(00:20,dwSensors:safe & pirSensors:safe & 22:30..05:30 ) => post(#quiet)")


     

    Shouldn't it the second rule read ?
     

    Quote

     

    rule("for(00:10,dwSensors:safe & pirSensors:safe & 22:30..05:30 ) => post(#quiet)")


     

    And one more question. How can I get e message which dwSensor was breached?

     

    Quote


     

    Please login or register to see this code.

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 17 minutes ago, FrankT said:

    jgab, Working through all examples in your previous conversations in my effort to change most of my scenes to your EventRunner model. Succeeded so far with all my light scenes, even 'Närvarosimulering'. Stumbled on  this code in your alarm example:

     

    Shouldn't it the second rule read ?
     

    And one more question. How can I get e message which dwSensor was breached?

     

    Yes, the second rule should be 00:10 if you want 10min. I seem to have copied the previous rule and forgot to change the time value.

     

    When a rule trigger, the triggering event is available in the variable 'env.event'. Because it's a door/window sensor the event looks like

    Please login or register to see this code.

    The last 'value' field is filled in by the framework. Anyway that means that the device id is available in env.event.deviceID

    Please login or register to see this code.

    Because you have done Util.reverseMapDef with you "hometable" you can get the name of the device with Util.reverseVar(<id>)

    Please login or register to see this code.

    log(<text>) logs the message to the console but also returns the string. That can be used to send it as a message. <phoneID>:msg=<message> sends a message to a phone with <phoneID>. <phoneID> could be a table  with many phoneIDs or a variable...

    Please login or register to see this code.

    Let me know if you have other rules that you would like help with

    /J

     

    Btw, in the next release of the framework, Util.reverseVar will be a builtin eventscript function named 'idname(<id>)'

    Link to comment
    Share on other sites

    Hi Jan,

     

    got an error when running my above mentioned AlarmEventRunner scene (ID# 313)on the HC2:

     

    DEBUG] 08:29:45: Posting {"type":"pirBreached"} at Fri Jan 11 08:29:45

    [DEBUG] 10:52:16: Posting {"type":"dwBreached"} at Fri Jan 11 10:52:16

    [DEBUG] 10:52:16: Error in 'dwSensors:breached => post(#dwBreached); log(dwSensors:breached)': /opt/fibaro/scenes/313.lua:1048: /opt/fibaro/scenes/313.lua:200: bad argument #1 to '_format' (string expected, got boolean)

    [DEBUG] 10:55:38: Posting {"type":"pirBreached"} at Fri Jan 11 10:55:38

    [DEBUG] 10:55:56: Posting {"type":"pirBreached"} at Fri Jan 11 10:55:56
     

    /F

     

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, FrankT said:

    Hi Jan,

     

    got an error when running my above mentioned AlarmEventRunner scene (ID# 313)on the HC2:

     

    DEBUG] 08:29:45: Posting {"type":"pirBreached"} at Fri Jan 11 08:29:45

    [DEBUG] 10:52:16: Posting {"type":"dwBreached"} at Fri Jan 11 10:52:16

    [DEBUG] 10:52:16: Error in 'dwSensors:breached => post(#dwBreached); log(dwSensors:breached)': /opt/fibaro/scenes/313.lua:1048: /opt/fibaro/scenes/313.lua:200: bad argument #1 to '_format' (string expected, got boolean)

    [DEBUG] 10:55:38: Posting {"type":"pirBreached"} at Fri Jan 11 10:55:38

    [DEBUG] 10:55:56: Posting {"type":"pirBreached"} at Fri Jan 11 10:55:56
     

    /F

     

    Yes, the 'log' function expects a format string before the arguments - it's more or less an alias for Lua's '

    Please login or register to see this link.

    .

     log(dwSensors:breached) is the same as log(true) if a sensor was breached and that doesn't work. The solutions is log('%s',dwSensors:breached), 

    To be clear, the first argument can be a string without formatting directives, but then it's the only argument. Type log("Hello").

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • New version, v1.9. Download EventRunner.lua, EventRunnerDebug.lua, globals.data

    Not a lot of new features but some changes in scene setup.

     

    -Lots of restructuring in EventRunnerDebug.lua (preparing for coming features...)

     

    -Fixed timeout parameter in offline emulation of net.HTTPClient(). 

     

    -Some changes in configuration variables. This is now how it looks in the beginning of a EventRunner scene:

    Please login or register to see this code.

    Running _GUI *and* _SPEEDTIME at the same time is not recommended (It slows down speedtime significantly. Trying to find a remedy for that for a future release.

     

    HueIP and _HueUserName have got an underscore in front of the names - trying to be consistent in naming.

    To receive events when running offline set _EVENTSERVER to true. Both for node-red events and when sending events back from a HC2.

    _deviceTable has no real significance as globals are read in by _System.readGlobalsFromFile, but it's always good practice to use a constant for the HomeTable global name anyway.

    Likewise, the _myNodeRed declaration in the example above has no real significance either. It's just for remembering the address to the node-red server. To receive incoming node-red events set _EVENTSERVER to true.

     

    To debug incoming events to the event server port (Hue events etc), set _debugFlags.eventserver=true

    To debug interaction with the Hue node, set _debugFlags.hue=true

     

    I will start to update documentation as the setup procedure has changed with the new way of handling globals offline.

     

    -When running offline, if _System.readGlobalsFromFile() has not been called before the first fibaro:getGlobal/fibaro:setGlobal is called, _System.readGlobalsFromFile() will be called to setup globals from "globals.data" per default. That means no need to call  _System.readGlobalsFromFile() if "globals.data" is setup. However you can call ex. _System.readGlobalsFromFile("myOtherGlobals.data") to setup another set of globals. It is also possible to change the _GLOBALS_FILE variable to another default than "globals.data"

     

    -function 'idname(<deviceID>)' available in eventscripts.

    Please login or register to see this code.

    ...will log "Sensor bed.sensor breached" or "Sensor kitchen.sensor breached"

     

    -sunset and sunrise is now calculated when running offline.

    Need to set _LATITUDE and _LONGITUDE of your HC2 in the beginning of EventRunnerDebug.lua file.

    This makes fibaro:getValue(1,"sunsetHour") return "real" values.

    Is updated at 00:00 every night in simulated time, just like on the HC2. 

    • Thanks 1
    Link to comment
    Share on other sites

    thanks for new version!

     

    Can I use more hue bridges? It means ie. _HueIP = {“192.168.1.10”,”192.168.1.11”} and same for _HueUserName

     

    Link to comment
    Share on other sites

  • Topic Author
  • Just now, petrkl12 said:

    thanks for new version!

     

    Can I use more hue bridges? It means ie. _HueIP = {“192.168.1.10”,”192.168.1.11”} and same for _HueUserName

     

    Not yet. It's doable and on my todo list.

    Link to comment
    Share on other sites

    Need some more help. The alarm scene I have been using is a modified scene from Bastian (mkshb.de) and I use Fibaros UBS scenActivation.

    I've tried to use EventRunner but failed so far because I don't know how i can get the scenID.

    rule("sceneID = ???????).

     

    --[[
    %% properties
    228 sceneActivation
    %% globals
    --]]
     local rfidreader = 228
    local checkWindows = true   -- true 
    local sceneId = tonumber(fibaro:getValue(rfidreader, "sceneActivation"))
    local sirene = 198
    local reddiod = 257
    local greendiod = 258

     

    if sceneId == 21 then
      if globalalarm == "armed" then
        unarmAllSensors()
        debug("green","unarmed")
      elseif globalalarm == "unarmed" then
        if checkWindows then
          checkWinAndDoors()
          sendPopUp(openwindows)
        end
        armAllSensors()
        debug("red","armed")
      end
    end

    /F

    Link to comment
    Share on other sites

  • Topic Author
  • A rule that should trigger on device 228’s sceneActivation and test on scene 21 would look like 

    rule(“228:scene==21 => ...”)

    I could help you give an example of how to translate the rest of the code tomorrow morning when I’m back home.

    /J

    Link to comment
    Share on other sites

    @jgab

    in last version I have this error:

    Error loading rules:EventRunnerDebug.lua:185: attempt to index field '_globals' (a nil value)

    in row:

      for _,v in ipairs(vars) do
        fibaro._globals[v.name] = {tostring(v.value),osTime()}
      end

     

    It looks that fibaro._globals is nil and I think it should be  fibaro._globals = { }

     

    I migrated from version 1.7 to 1.9. and I tried to create the globals via those two rows:

      _System.copyGlobalsFromHC2()   -- copy globals from HC2 to ZBS
      _System.writeGlobalsToFile()   -- write globals from ZBS to file, default 'globals.data'

     

    Edited by petrkl12
    Link to comment
    Share on other sites

    Quote

     

    A rule that should trigger on device 228’s sceneActivation and test on scene 21 would look like 

    rule(“228:scene==21 => ...”)

    I could help you give an example of how to translate the rest of the code tomorrow morning when I’m back home.

    /J

     

    Thank you, that would be nice.

    Link to comment
    Share on other sites

  • Topic Author
  • 53 minutes ago, petrkl12 said:

    @jgab

    in last version I have this error:

    Error loading rules:EventRunnerDebug.lua:185: attempt to index field '_globals' (a nil value)

    in row:

      for _,v in ipairs(vars) do
        fibaro._globals[v.name] = {tostring(v.value),osTime()}
      end

     

    It looks that fibaro._globals is nil and I think it should be  fibaro._globals = { }

     

    I migrated from version 1.7 to 1.9. and I tried to create the globals via those two rows:

      _System.copyGlobalsFromHC2()   -- copy globals from HC2 to ZBS
      _System.writeGlobalsToFile()   -- write globals from ZBS to file, default 'globals.data'

     

    You do it inside main()? 

    Link to comment
    Share on other sites

    yes, of course

     

    Please login or register to see this code.

     

    oh 

    I have _REMOTE = true

     

    Link to comment
    Share on other sites

  • Topic Author
  • 17 minutes ago, petrkl12 said:

    yes, of course

     

    Please login or register to see this code.

     

    I’m sorry I need to test it when I’m back home - you have a fix early tomorrow morning. /J

    Link to comment
    Share on other sites

    Join the conversation

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

    Guest
    Reply to this topic...

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