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


HC2 scene emulator


jgab

Recommended Posts

All my scenes are converted into new version 2 B2 and it works as expected :-)

Thanks

Link to comment
Share on other sites

  • Topic Author
  • 48 minutes ago, petrkl12 said:

    All my scenes are converted into new version 2 B2 and it works as expected :-)

    Thanks

    Great, let me know if there is something that could make it easier to use.

    Link to comment
    Share on other sites

  • Topic Author
  • 22 minutes ago, jompa68 said:

    was it so that pub/sub events only works between scenes in ZBS at the moment?

    Yes, but I’m working on it. A bit trickier than I thought but doable 

    • Like 1
    Link to comment
    Share on other sites

    @jgab taking small steps in converting my scenes from V1.15 to version,_fix = "2.0","B2, but ZBS gives error:

     

    [66:1]19:05:38, Fri Mar 08: HC2 call:PUT:/globalVariables/MAILBOX66_1
    #[66:1]19:05:38, Fri Mar 08: fibaro:setGlobal("MAILBOX66_1","")
    [66:1][DEBUG] 19:05:38: Fri Mar 08: Hue system inited (experimental)
    [66:1][DEBUG] 19:05:38: Fri Mar 08: 
    [66:1][DEBUG] 19:05:38: Fri Mar 08: Loading rules
    [66:1][DEBUG] 19:05:38: Fri Mar 08: Error loading rules:Err:fibaro:getGlobalValue("<ID>"), Err:fibaro:getGlobal("<ID>"), HC2.lua:1267: Assertion failed: Expectedstring

     

    Where should I search?

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 39 minutes ago, FrankT said:

    @jgab taking small steps in converting my scenes from V1.15 to version,_fix = "2.0","B2, but ZBS gives error:

     

    [66:1]19:05:38, Fri Mar 08: HC2 call:PUT:/globalVariables/MAILBOX66_1
    #[66:1]19:05:38, Fri Mar 08: fibaro:setGlobal("MAILBOX66_1","")
    [66:1][DEBUG] 19:05:38: Fri Mar 08: Hue system inited (experimental)
    [66:1][DEBUG] 19:05:38: Fri Mar 08: 
    [66:1][DEBUG] 19:05:38: Fri Mar 08: Loading rules
    [66:1][DEBUG] 19:05:38: Fri Mar 08: Error loading rules:Err:fibaro:getGlobalValue("<ID>"), Err:fibaro:getGlobal("<ID>"), HC2.lua:1267: Assertion failed: Expectedstring

    Where should I search?

     

    Hi, you are calling fibaro:getGlobalValue with a null argument inside main(). Are you initialising the hometable correct? I have changed the name of the hometable in the example code. 

    However, the error message you get is not very helpful and should be better.

    I have pushed a new version of HC2.lua with some better debug message if a fibaro:* call has an error.

    If I add a fibaro:getGlobalValue(null) to main() I now get this printout at runtime

    Please login or register to see this code.

    Here I can see that it's the implementation of fibaro:getGlobalValue in HC2.lua ar line 1563 that cause the error, and it is called from EventRunner.lua line 51, which is where I have the faulty call. So if you run this you should be able to better pin point what causes it.

    It's a bit tricky to get error handling (and error messages) correct but I will work on it.

     

     

    Link to comment
    Share on other sites

    20 hours ago, jgab said:

    Yes, but I’m working on it. A bit trickier than I thought but doable 

    Seems to work with pub/sub between scene in my HC2....

    Please login or register to see this image.

    /monthly_2019_03/1488632321_Skrmavbild2019-03-09kl_11_48_02.png.74b4948232eef54ef405ee52091bc06e.png" alt="1488632321_Skrmavbild2019-03-09kl_11_48_02.png.74b4948232eef54ef405ee52091bc06e.png" />

    Link to comment
    Share on other sites

  • Topic Author
  • 5 hours ago, jompa68 said:

    Seems to work with pub/sub between scene in my HC2....

     

    Yes, it works between scenes in HC2 or between scenes in  ZBS, but not between them... :-) 

    Link to comment
    Share on other sites

    On 3/3/2019 at 12:50 AM, jgab said:

    To send triggers from the HC2 to the emulator

    I have setup this now and it is working

    Please login or register to see this code.

    in my HC2.lua i load the scene that have the devices above, but how can i test rules?

    Link to comment
    Share on other sites

  • Topic Author
  • 33 minutes ago, jompa68 said:

    I have setup this now and it is working

    Please login or register to see this code.

    in my HC2.lua i load the scene that have the devices above, but how can i test rules?

    Does the scene start and run? 

     

    In the emulator (HC2.lua) you can do 

    Please login or register to see this code.

    to fake turning on/off stuff.

    Inside the EventRunner scene you can still fire off event like before.

    I'm working on a web GUI where triggers should be possible to set off.

    Link to comment
    Share on other sites

  • Topic Author
  • Updated the emulator and the first post in the thread documenting the new features and setup options. A new web GUI to start triggers and scenes etc.

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • Update of the Scene emulator. v0.7 fix4.

    -Restructured logic how resources are handled.

    -New GUI with "main page" that have buttons for speeding the scene or jump 1 or 24 hours. Also scene triggers are available. 

    -

    Please login or register to see this link.

    that opens the Emulator GUI with a keyboard shortcut (Ctrl-Alt-E, or Option-Cmd-E on Mac). Also adds links to EventRunner and Emulator thread on the Fibaro Forum under the Help menu.

    -

    Please login or register to see this link.

    but more will come

    Link to comment
    Share on other sites

  • Topic Author
  • A HC2 scene that we want to run in the emulator need to include HC2.lua in the beginning of the scene (line starting with "if dofile...")

    Please login or register to see this code.

    There are some commands accessible in a scene running on the emulator that can be useful. 

    •   _System.createGlobal(<name>,<value>) creates a local (emulated) fibaro global. Can be good to tell the emulator about global you want to test with. However, default is that the emulator creates an emulated fibaro global if you try to access it with fibaro:getGlobal or fibaro:setGlobal and it doesn't exists already.
    •   _System.createDevice(<deviceID>). Similar as _System.createGlobal. Default is that the emulator creates an emulated fibaro device if you try to access it with fibaro:* command and it doesn't exists already.
    •   _System.setLocal(<resource name>,<id>). Sets a resource local (emulated). All resources (devices, globals etc) starts by default as local.
    •   _System.setRemote(<resource name>,<id>). Sets a resource remote, i.e. it will be accessed on the HC2. To make a device, e.g. deviceID 88, remote do _System.setRemote("devices",88). To make fibaro global variable "Test" remote do _System.setRemote("globalVariables","Test").
    •   _System.monitorDevice(<deviceID>,<property>). <property> defaults to "value". Will start to poll the HC2 for a change in the deviceID's state and if so post a sourceTrigger to the emulator. This way we can get "live" sourceTriggers from real devices like motion sensors to trigger our emulated scenes. _System.monitorDevice(88) will monitor deviceID 88 "value" property on the HC2 and if it changes state post a sourceTrigger back to our scenes...
    •   _System.monitorGlobal(<name>). Same as _System.monitorDevice but for globals.
    •   _System.speed(<time>). This allows us to control the speed that the emulator will run in. _System.speed(true) will speed as fast as possible , default 1 year. Time seen by the scenes are simulated. _System.speed(false) starts to run the emulator i realtime. _System.speed(24) will speed through 24 hours and then go back to realtime

    These _System.* functions are not available when running on the HC2 so it can be good to wrap these commands inside a "if _EMULATED.." statement. _EMULATED is a Lua variable only defined when we run in the emulator and is undefined on the HC2

     

    Please login or register to see this code.

    In this scene we make deviceID 66 and 77 remote so we can run the scene in the emulator but still get sourceTriggers from sensor with deviceID 66 and turn on and off the light with deviceID 77.

    We can now set a breakpoint in the debugger on the line starting with "if trigger.type == 'property' then...", run the scene, and breached the real sensor (id 66) and step through the scene and see what happens. :-) 

    In general when debugging one should step-over fibaro:* calls (Shift-F10), otherwise you end up in the emulator witch is not very informative. However, if that happened just step-out (Cmd-F10) of the function and you are back in the scene again.

     

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • Video introducing how to use the Emulator.

    Make sure you have downloaded and installed ZeroBrane Studio as described in the 

    Please login or register to see this link.

    and download 

    Please login or register to see this link.

    Create a simple scene named Test.lua in ZeroBrane with the code below:

    Please login or register to see this code.

    Here is the video.

     

     

    The video show the line

    Please login or register to see this code.

    but _EMBEDDED is now changed to _EMULATED

    Please login or register to see this code.

     

    Edited by jgab
    • Like 1
    • Thanks 1
    Link to comment
    Share on other sites

    • 2 weeks later...
  • Topic Author
  • Pushed a new version, v0.8 fix12.

    Better resource handling. I would recommend re-generating HC2.data file (even though I tried to make it backward compatible)

    When running with _LOCAL=true,  resources are set local like this

    Please login or register to see this code.

    To enable remote access, do HC2.setRemote(...). The 'true' arguments can be replaced with resource iD or list of resource IDs

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    @jgab I'm trying to run the following test in ZBS:

     

    --[[
    %% properties
    %% autostart
    --]]

    if dofile and not _EMULATED then _EMBEDDED=true dofile("HC2.lua") end

    function logbug(color, message)

      for line in message:gmatch("[^\010\013]+") do
        local txt = line:gsub("([\038\060\062])",
          function(c)
            return "&#"..string.byte(c)..";"
          end)
        fibaro:debug(('<span style="color:%s">%s</span>'):format(color,txt))
      end
    end


    local encodeTTS = function(url)
      return url:gsub(" ", "%%20")
    end

    local mn        = (os.date("%B"))
    local dt         = (os.date("%d"))
    local cStr = "God morgon. Idag är det "..dt.." "..mn.."." 

    logbug(white,cStr)
    cStr = encodeTTS(cStr)
    logbug(white,cStr)
    local http = net.HTTPClient()
    http:request("http://192.168.1.200:5005/Vardagsrum/say/"..cStr.."/sv-se/40")   ----  Node-Sonos-HTTP-API

     

    and get an error message

     

    Debugging session started in 'C:\Users\F\Downloads\EventRunner-master\'.
    Sat/Apr/27,16:05:15:[HC2 ] HC2 SceneRunner v0.8 fix15
    Sat/Apr/27,16:05:15:[HC2 ] Running speedtime
    Sat/Apr/27,16:05:15:[HC2 ] Local mode, will not access resources on HC2
    Sat/Apr/27,16:05:15:[HC2 ] Created Event server at 192.168.1.127:6872
    Sat/Apr/27,16:05:15:[HC2 ] Web GUI at http://192.168.1.127:6872/emu/main
    Sat/Apr/27,16:05:15:[HC2 ] Reading and decoding configuration from HC2.data
    Sat/Apr/27,16:05:15:[HC2 ] Configuration from file, Globals:62, Scenes:52, Device:186, Rooms:24
    Sat/Apr/27,16:05:15:[HC2 ] Loaded scene:Test, id:99, file:'test.lua'
    Sat/Apr/27,16:05:15:[HC2 ] Scene:99 [ Trigger:{"type":"autostart"} ]
    Sat/Apr/27,16:05:15:[HC2 ] System trigger:{"type":"autostart"} at Sat Apr 27 16:05:15
    Sat/Apr/27,16:05:15:[HC2 ] Scene [99:1] started (Test), trigger:{"type":"autostart"} (thread: 0x029856b0)
    Sat/Apr/27,16:05:15:[99:1] God morgon. Idag är det 27 April.
    Sat/Apr/27,16:05:15:[99:1] God%20morgon.%20Idag%20är%20det%2027%20April.
    Sat/Apr/27,16:05:15:[HC2 ] Error in Test "HC2.lua:1986: attempt to index local 'options' (a nil value)"
    stack traceback:
        HC2.lua:1283: in function 'runTimers'
        HC2.lua:217: in function 'startup'
        HC2.lua:3246: in main chunk
        [C]: in function 'dofile'
        test.lua:6: in main chunk
    Sat/Apr/27,16:05:15:[HC2 ] Scene [99:1] terminated (thread: 0x029856b0)
    Sun/Apr/28,00:00:00:[HC2 ] Sunrise:05:28 Sunset:20:12 (local calc)
    Mon/Apr/29,00:00:00:[HC2 ] Sunrise:05:26 Sunset:20:14 (local calc)
    Mon/Apr/29,17:05:15:[HC2 ] 04/29/19 17:05:15, End of time (48 hours) - exiting
    Program completed in 1.26 seconds (pid: 216236).

     

    Works ok when running on HC2.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, FrankT said:

    @jgab I'm trying to run the following test in ZBS:

     

    --[[
    %% properties
    %% autostart
    --]]

    if dofile and not _EMULATED then _EMBEDDED=true dofile("HC2.lua") end

    function logbug(color, message)

      for line in message:gmatch("[^\010\013]+") do
        local txt = line:gsub("([\038\060\062])",
          function(c)
            return "&#"..string.byte(c)..";"
          end)
        fibaro:debug(('<span style="color:%s">%s</span>'):format(color,txt))
      end
    end


    local encodeTTS = function(url)
      return url:gsub(" ", "%%20")
    end

    local mn        = (os.date("%B"))
    local dt         = (os.date("%d"))
    local cStr = "God morgon. Idag är det "..dt.." "..mn.."." 

    logbug(white,cStr)
    cStr = encodeTTS(cStr)
    logbug(white,cStr)
    local http = net.HTTPClient()
    http:request("http://192.168.1.200:5005/Vardagsrum/say/"..cStr.."/sv-se/40")   ----  Node-Sonos-HTTP-API

     

    and get an error message

     

    Works ok when running on HC2.

     

    Ooops, I had missed that one could have no 'options' to http.request. I have pushed a new version of HC2.lua (fix16)

    Link to comment
    Share on other sites

    7 minutes ago, jgab said:

     

    Ooops, I had missed that one could have no 'options' to http.request. I have pushed a new version of HC2.lua (fix16)

    Error still there

     

    Sat/Apr/27,16:35:14:[HC2 ] HC2 SceneRunner v0.8 fix16
    Sat/Apr/27,16:35:14:[HC2 ] Local mode, will not access resources on HC2
    Sat/Apr/27,16:35:14:[HC2 ] Created Event server at 192.168.1.127:6872
    Sat/Apr/27,16:35:14:[HC2 ] Web GUI at http://192.168.1.127:6872/emu/main
    Sat/Apr/27,16:35:14:[HC2 ] Reading and decoding configuration from HC2.data
    Sat/Apr/27,16:35:14:[HC2 ] Configuration from file, Globals:62, Scenes:52, Device:186, Rooms:24
    Sat/Apr/27,16:35:14:[HC2 ] Loaded scene:Test, id:99, file:'test.lua'
    Sat/Apr/27,16:35:14:[HC2 ] Scene:99 [ Trigger:{"type":"autostart"} ]
    Sat/Apr/27,16:35:14:[HC2 ] System trigger:{"type":"autostart"} at Sat Apr 27 16:35:14
    Sat/Apr/27,16:35:14:[HC2 ] Scene [99:1] started (Test), trigger:{"type":"autostart"} (thread: 0x02995720)
    Sat/Apr/27,16:35:14:[99:1] God morgon. Idag är det 27 April.
    Sat/Apr/27,16:35:14:[99:1] God%20morgon.%20Idag%20är%20det%2027%20April.
    Sat/Apr/27,16:35:14:[HC2 ] Error in Test "HC2.lua:1997: attempt to index local 'options' (a nil value)"
    stack traceback:
        HC2.lua:1277: in function 'runTimers'
        HC2.lua:217: in function 'startup'
        HC2.lua:3241: in main chunk
        [C]: in function 'dofile'
        test.lua:6: in main chunk
    Sat/Apr/27,16:35:14:[HC2 ] Scene [99:1] terminated (thread: 0x02995720)
     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 4 minutes ago, FrankT said:

    Error still there

     

    Sat/Apr/27,16:35:14:[HC2 ] HC2 SceneRunner v0.8 fix16
    Sat/Apr/27,16:35:14:[HC2 ] Local mode, will not access resources on HC2
    Sat/Apr/27,16:35:14:[HC2 ] Created Event server at 192.168.1.127:6872
    Sat/Apr/27,16:35:14:[HC2 ] Web GUI at http://192.168.1.127:6872/emu/main
    Sat/Apr/27,16:35:14:[HC2 ] Reading and decoding configuration from HC2.data
    Sat/Apr/27,16:35:14:[HC2 ] Configuration from file, Globals:62, Scenes:52, Device:186, Rooms:24
    Sat/Apr/27,16:35:14:[HC2 ] Loaded scene:Test, id:99, file:'test.lua'
    Sat/Apr/27,16:35:14:[HC2 ] Scene:99 [ Trigger:{"type":"autostart"} ]
    Sat/Apr/27,16:35:14:[HC2 ] System trigger:{"type":"autostart"} at Sat Apr 27 16:35:14
    Sat/Apr/27,16:35:14:[HC2 ] Scene [99:1] started (Test), trigger:{"type":"autostart"} (thread: 0x02995720)
    Sat/Apr/27,16:35:14:[99:1] God morgon. Idag är det 27 April.
    Sat/Apr/27,16:35:14:[99:1] God%20morgon.%20Idag%20är%20det%2027%20April.
    Sat/Apr/27,16:35:14:[HC2 ] Error in Test "HC2.lua:1997: attempt to index local 'options' (a nil value)"
    stack traceback:
        HC2.lua:1277: in function 'runTimers'
        HC2.lua:217: in function 'startup'
        HC2.lua:3241: in main chunk
        [C]: in function 'dofile'
        test.lua:6: in main chunk
    Sat/Apr/27,16:35:14:[HC2 ] Scene [99:1] terminated (thread: 0x02995720)
     

     

     

    Sorry, not very sharp today... fix17 should work better

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