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

if you mix sensor and lights in a room in HomeTable, can you anyway use deviceID:on and it will skip sensor or will scene stop with error?

Link to comment
Share on other sites

  • Topic Author
  • 37 minutes ago, jompa68 said:

    if you mix sensor and lights in a room in HomeTable, can you anyway use deviceID:on and it will skip sensor or will scene stop with error?

    room:on will not work if there are other devices, like sensors, that can’t be switched on. That’s why some kind of filter  would be needed to make it really practical. 

    In theory one could filter on what 'actions' the device support but I think user-defined filters are better as not everything that can be turned on/off should always be included...  A real simple approach would be to have just a sensors, lights, and switches filter functions 

    Please login or register to see this code.

    just need a simple heuristics to decide what's a sensor and a light and a switch. One way is to let user's define it themselves (that's easy). Otherwise try to have knowledge of all kind of devices or try to use deviceKind, or category etc... which is harder...

     

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • Ok, pushed a version with an experimental filter function.

    Please login or register to see this code.

    'type' can be any string.  <table>/<string> will return a new table with only the devices defined as type <string> with Util.deftype.

    Note that you need to enclose the filter with parenthesis as ':' has higher priority than '/', i.e (<table>/<string>):<prop>

    One could also write a function that inspects all devices and makes a Util.deftype calls to automatically classify them... 

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • Ok, I pushed another version - a bit more advanced filter model. Now the type filter allows matching and is applied recursively on the table argument

    Please login or register to see this code.

    So, here we assign devices the type <path>/<type>. So, 88 becomes "floor1/kitchen/lamp/light". We use the function Util.reverseVar that is used by the log function to log the name of a variable instead of the integer ID. It returns "floor1.kitchen.lamp" and we substitute '.' with "/" and add "/"<type> at the end. Of course, one can choose other schema  for types for IDs.

    The filter function <table>/<string> will do a Lua match of the type of the device and the string filter. And it will do it recursively if the table is a table of tables - like HomeTables typically are. The result of the filter will be a flat table with all deviceIDs matching the filter - that we then can apply a ':<prop>' operation on.

    The filter operations is a little bit expensive - not terribly, but if it is done often it can be best to assign a variable the pre-filtered group before the rule using it.

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • I played around with Node-red a little, trying to integrate it with the EventRunner event model.

    Please login or register to see this image.

    /monthly_2019_01/node2.png.16d1f80008ab79911591543db5f51a23.png" />

    The first "sub-flow" sends an event to an EventRunner scene. The second receives an event from an EventRunner scene - in this case a {type='speek'', data='Hello'} and switches on the 'type' and forwards the data to a sound node. It's quite straightforward, only trick is how to encode the event to make it compatible with the EventRunner format.

    Flow:

    Please login or register to see this code.

    From EventRunner the post function looks like

    Please login or register to see this code.

    ...and could probably be merged with Event.postRemote. 

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

    the url to NR server, should that be like this?

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 4 minutes ago, jompa68 said:

    the url to NR server, should that be like this?

     

    Please login or register to see this code.

     

    Please login or register to see this code.

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    is this the right format to add time to an event from a variable?

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • Just now, jompa68 said:

    Thanks Jan for quick answer

    If you wrap it in a Util.printRule(Rule.eval(“@....”)) you will see what time it will trigger

    Link to comment
    Share on other sites

    ah, ofcourse. I now you showed me that before.
    So many options with ER so it is hard to remember them all, in a good way :D

    Link to comment
    Share on other sites

    Really surprised how fast it is to send a string from EventRunner --> Node Red --> Sonos 

     

    Installed sonospolytts to node-red
    requires

    Please login or register to see this link.


     

    Please login or register to see this code.

    Please login or register to see this image.

    /monthly_2019_01/476253896_Skrmavbild2019-01-02kl_17_45_45.png.f43b306a5ffd78592c3cf981760aa2c0.png" alt="476253896_Skrmavbild2019-01-02kl_17_45_45.png.f43b306a5ffd78592c3cf981760aa2c0.png" />

    Link to comment
    Share on other sites

    @jgab 

    when testing my code in ZBS i notice that data is sent with + sign between words.

     

    Please login or register to see this code.

    Please login or register to see this code.

    Works without + signs in EventRunner scene

    Edited by jompa68
    Link to comment
    Share on other sites

    trying to change Event.event

    Please login or register to see this code.

    to this (reading wiki)

    Please login or register to see this code.

    but without success. Have this changed or do i understand it wrong?
     

    Link to comment
    Share on other sites

  • Topic Author
  • 11 hours ago, jompa68 said:

    @jgab 

    when testing my code in ZBS i notice that data is sent with + sign between words.

     

    Please login or register to see this code.

    Please login or register to see this code.

    Works without + signs in EventRunner scene

    I had a bug in urlencode in EventRunnerDebug.lua.

    I have fixed that and pushed a new version of EventRunner.lua and EventRunnerDebug.lua.

    In EventRunner.lua I have merged post2NodeRed with Event.postRemote. 

    postRemote used to take an ID that was the scene to send the event to. Now it can also take an URL to a node-red server

    Event.postRemote("http://192.168.1.104:1880/eventrunner",{type='speek',data="Posten har varit här.!"}) 

    10 hours ago, jompa68 said:

    trying to change Event.event

    Please login or register to see this code.

    to this (reading wiki)

    Please login or register to see this code.

    but without success. Have this changed or do i understand it wrong?
     

     

    It should be like this (I assume that define is an alias for Util.defvar)

    Please login or register to see this code.

    However, if test is just a normal lua function. If you declare test() global, i.e not declaring test() local, you can use test directly in an eventscript

    Please login or register to see this code.

    The advantage with define is of course that you get an eventscript "local" function and don't pollute the global namespace.

     

     

    12 hours ago, jompa68 said:

    Really surprised how fast it is to send a string from EventRunner --> Node Red --> Sonos 

     

    Installed sonospolytts to node-red
    requires

    Please login or register to see this link.


     

    Please login or register to see this code.

    Please login or register to see this link.

    Cool, need to try that!

    Edited by jgab
    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    It should be like this (I assume that define is an alias for Util.defvar)

    Yes, thanks Jan. Working now.

    Link to comment
    Share on other sites

  • Topic Author
  • Played a bit more with node-red - have a new flow and pushed new versions of EventRunner.lua

     

     

    Please login or register to see this spoiler.

     

    Now you post to a node-red server this way

    Please login or register to see this code.

    'remote' just calls Event.postRemote, but is more convenient to use from EventScript.

    If posted from ZBS, the ._from field in the event is set to '-1'. (Normally that field is set to the sending scene's ID)

    When an event is received in node-red, the ._from field is copied to msg.ESceneID.

    In the bottom flow when we send an event from node-red to EventRunner, we first switch on the msg.ESceneID. If it's -1 we send it to ZBS, if it's >0 we send it to that scene on HC2. This means that different scenes on the HC2 can post events to node-red and get the responses back to the scenes that posted the event.

    The 'test' inject node that sends an event. sends it through an 'Address' node that add the msg.ESceneID before sending it on so as to know where to send the event.

     

    Anyway, all this means that we can send an event from EventRunner to node-red, and node-red can respond back to EventRunner.

    The 'echo' event is an example. It echos back the event it gets in the data field of the response.

    Please login or register to see this code.

    Running from ZBS we get

    Please login or register to see this code.

    The 'Posting' debug line is the internal re-posting of the event received from node-red. 

    This is interesting. It means that we can do request/response flows.  

    There is a flow that triggers on {type='https', url=<url>} that runs a https request and returns the result:

    Please login or register to see this code.

    and it returns

    Please login or register to see this code.

    So, this is a way to do https from HC2 when the proper support is lacking.

     

    It's easy to extend the flow, switching  on additional event types and carry out additional node-red actions.

     

    To make this work the HC2 node needs to be configured with your HC2 credentials (basic authentication), the ZBS node needs to be configured with IP address and port number of the PC/Mac running ZeroBrane studio. The 'sonospollytts' node needs to be configured with your aws credentials. The sonospollytts node can also be removed and replaced with the 'talk' node to just talk to the PC speaker. On ZBS, the '_EVENTSERVER'  variable needs to be set to true. This is to be able to receive events from node-red and re-post them in the framework (for the HC2, node-red uses the proper startScene api)

    Please login or register to see this attachment.

    Edited by jgab
    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...