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

Posted
10 minutes ago, jgab said:

 

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

Thank you, working now. I think you are fantastic!

  • Topic Author
  • Posted (edited)

    New version of HC2.lua - "0.8","fix18".

    Feature - trigger proxy.

    In your scene, if you have triggers declared in the header. Ex.

    Please login or register to see this code.

    and then in your scene do

    Please login or register to see this code.

    You mark the resources as 'remote', and then call _System.installProxy(). The last call will install a scene on the HC2 that forwards the triggers they generate on the HC2 to the emulator.

    The scene on the HC2 will be named "_EMULATOR_PROXY" and looks like (but is hidden)

    Please login or register to see this code.

    Where the IP adress will be the adress of the machine the emulator runs on. Only resources (devices, globals) that has been set 'remote' will be included in the scene.

    There is also a _System.removeProxy() that removes the scene.

    For many scenes it can be better to install the proxy and set the remote resources in the HC2.lua file, especially if it's scenes that should start up on triggers.

    In HC2.lua the function is called Proxy.installProxy() and Proxy.removeProxy(), see example in HC2.lua.

     

    The deviceID 5 in the example is my key fob and it allows me to get keypresses to my emulated scenes etc. Very useful.

    Edited by jgab
    • 4 weeks later...
    Posted
    On 4/28/2019 at 5:22 PM, jgab said:

    New version of HC2.lua - "0.8","fix18".

    Feature - trigger proxy.

    In your scene, if you have triggers declared in the header. Ex.

    Can this also handle variable? How to define that in _setRemote?

    Really like this feature, so easy to debug in ZBS :)

  • Topic Author
  • Posted
    4 minutes ago, jompa68 said:

    Can this also handle variable? How to define that in _setRemote?

    Really like this feature, so easy to debug in ZBS :)

    They just need to be set remote

    In ER, ex.

    Please login or register to see this code.

    Yes, it's quite convenient.

  • Topic Author
  • Posted

    Oops, there was a bug introduced in the log of fibaro functions (complains that reverseVar doesn't exist)

    Pushed a new version of HC2.lua with a fix ("0.10","fix3" -- May 26, 2019)

    • 1 month later...
    Posted

    If an variable have an underline in the name, the webpage cut the string so it is not possible to test it that way.

     

    Please login or register to see this image.

    /monthly_2019_07/1628618345_Skrmavbild2019-07-07kl_15_06_24.png.027ecddf1c8de711e557d172b7c65a83.png" />

    • 5 weeks later...
    Posted

    Just wanted to say thanks for your work on this!

    I have only just started with the HC2 and i can see that this would be a great tool to test with.

     

    Thanks.

     

  • Topic Author
  • Posted
    20 minutes ago, Fodder1 said:

    Just wanted to say thanks for your work on this!

    I have only just started with the HC2 and i can see that this would be a great tool to test with.

     

    Thanks.

     

    You're welcome! Please ask questions if there is something you wonder - there are a ton of features well hidden in this emulator :-)

    Posted

    I will probably take you up on that.

    Probably lots of dumb questions!

     

    Thanks for your onging time and brain power!

     

    • 1 month later...
    Posted

    I join the congratulations of the other users, thank you very much for sharing your HC2 emulator, I will try to read it and understand it, since my English is not very good.

    Thanks you are a machine! ?

  • Topic Author
  • Posted

    Welcome. Please ask questions if there is something you wonder about.

    /J

  • Topic Author
  • Posted

    New version v0.11, fix11 pushed.

    Minor fixes and

    _System.post and _System.loadScene

    will make another post with debugging guidelines...

     

  • Topic Author
  • Posted (edited)

    ..

    Edited by jgab
  • Topic Author
  • Posted (edited)

    Debugging scenes in the HC2 emulator can be done in different ways. The video instruction uploaded uses the WebGUI to let us start triggers and speed up the scene.
    However, to streamline the debugging process the WebGUI is not the preferred way to do it (for creating a new device database from the HC2 the WebGUI is still the easiest way).

    Instead, we can control the HC2 emulator from within our scene.

    When a scene is run by the emulator, the symbol '_EMULATED' is defined. We use that in the first line in the scene where we bring in the HC2 emulator.

    Please login or register to see this code.


    The fact that it is not defined yet makes us define it and load "HC2.lua". We also define _EMULATED to a table with values that HC2.lua will use.
    First we can give a name to our scene ("sceneTest") and a preferred Scene ID (42), and a max time that the emulator should run (24 hours).

    When the emulator starts up it will send a system trigger {type='autostart'}, and scenes registered with the emulator will be started up - similar to when you save a scene on the HC2.
    However, if you haven't declared '%% autostart' your scene will not start. You can then use the WebGUI to trigger a device that your scene has declared a '%% property' header for and in that way start the scene - however, that is a bit tedious when working with a scene.

     

    Instead we can use the fact that the scene running in the emulator has access to a set of _System.* functions that can be used to interact with the emulator.As an example, take the scene used in the video instruction - there we used the WebGUI to breach a sensor and then make it safe so our scene turned on and then off a lamp.
    If we change the scene slightly to this - the whole flow with triggers will be "automated".

    Please login or register to see this spoiler.

    First we make the scene '%% autostart' so that the scene starts direct when we run it.
    Then within _EMULATED we setup what we want to happen.
    First, at startup ('autostart') we fake a breach of the sensor by doing a fibaro:call setting its value to '1'.
    and then the next time it gets called we set a timer to reset the sensor to '0' making it safe. We also set seedtime to true so that we run faster than real-time.
    This allows us to run the scene and get the triggers that we expect at the times we want and see if our scene behaves the way we expected.
    When we run the scene we can set breakpoints in our code and step through what happens. It can be a little bit difficult to emit the right triggers from the same scene that is going to react on them (have to be careful we donate send the same triggers many times if the scene is restarted etc)

    Edited by jgab
    Posted

    TBH it was a little daunting to get your setup working. A few new concepts to get my head around and I''m sure there is a lot more to learn, however I already found my first bug in some code I was writing which would have taken me walking around the house and back to my pc to test, so it's already paid dividends. 

     

    Seriously, keep up the great work and keep sharing!

  • Topic Author
  • Posted (edited)

    So, it can be a little bit difficult to emit the right triggers from the same scene that is going to react on them (have to be careful we donate send the same triggers many times if the scene is restarted etc)
    Another approach is to have a separate "scene" that loads our real scene and also sets up all the triggers.

    Please login or register to see this spoiler.

    Here we don't emit fake triggers.
    Instead we declare our sensor and lamp as remote devices, meaning the emulator will use the real devices by making calls to the HC2.
    We also install a proxy scene on the HC2 that sends triggers back to our emulator. That means that when the sensor is breached our MyTestScene will be called.
    We can now start our runner scene, and breach the live sensor and get breakpoints in MyTestScene. 

    Edited by jgab
    Posted

    i have a IKEA tradfri color bulb that gives error in HC2 emulator when i turnOff and On

    Please login or register to see this code.

     

  • Topic Author
  • Posted
    4 hours ago, jompa68 said:

    i have a IKEA tradfri color bulb that gives error in HC2 emulator when i turnOff and On

    Please login or register to see this code.

     

     

    How does the rule/code look like that turn on/off the light?

    Is it only trådfri? not ordinary Hues?

    Posted
    8 hours ago, jgab said:

    How does the rule/code look like that turn on/off the light?

    Is it only trådfri? not ordinary Hues?

    I don't have any rule in my scene for that tradfri, only a monitor rule. i only see the error message when i set debug flag hue=true

    Please login or register to see this code.

    Yes its seems to be only the tradfri color bulb, not the other tradfri plugs or real hue lights

  • Topic Author
  • Posted
    42 minutes ago, jompa68 said:

    I don't have any rule in my scene for that tradfri, only a monitor rule. i only see the error message when i set debug flag hue=true

    Please login or register to see this code.

    Yes its seems to be only the tradfri color bulb, not the other tradfri plugs or real hue lights

     

    Thanks, that was a bug - fixed

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