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 (edited)

@jgab

How to connect 2 strings in rule?

This doesn't work: s1..s2 or s1+s2

 

solved: table.concat({s1,s2})

 

Edited by petrkl12
  • Like 1
  • Topic Author
  • Posted
    16 hours ago, petrkl12 said:

    @jgab

    How to connect 2 strings in rule?

    This doesn't work: s1..s2 or s1+s2

     

    solved: table.concat({s1,s2})

     

    Yes, because ER is "loosely typed", we can add 6 + "6" so I can't use + for concatenation. , .. is used for time intervals.

    table.concat is a solution. 

    fmt('%s%s',s1,s2) is another.

    Maybe I will add ++ as the string concatenator in the next version.

  • Topic Author
  • Posted
    On 1/19/2021 at 8:40 PM, ChristianSogaard said:

    Hi @jgab i started using this Local HT in my rules.

    Is there a way to import the named already configured in the system?

    An example here is the Garage.g:Scene = 413

    Or is there a way to export the names and deviceIDs, to re-use in EV4. To avoid mistakes when "cloning" more that 100 device names into EV4?.  

     

    Please login or register to see this code.

     

     

    Yes, the normal way is to store the HT in a fibaro global variable and read it in the scenes and QAs that need it.

    There are various philosophies how to create HTs. Some like to scan all devices and automatically create HTs using the names and rooms they are in. Others like to create them manually (I belong to the latter category).

    One can also do something in-between, scan for devices and add other data manually.

    To store the table.

    fibaro.setGlobalVariable("HT",json.encode(HT))

    To retrieve it

    HT = json.decode((fibaro.getGlobalVariable("HT")))

    works both in scenes and QAs. 

    It could be a good idea to have a Scene where you define the HT and store it and that can be easily run to re-generate the table.

     

    In ER when you read in the HT, you also define it to be usable as variables within ER rules

    Please login or register to see this code.

     

    The problem is that if your HT is redefined, you should also restart the ER QA so it will read in the new HT table and define ER variables with the new values.

    One way to achieve that automatically is to create a rule like this

    Please login or register to see this code.

    because it will trigger when the fibaro global named 'HT' change value.

    • Thanks 1
  • Topic Author
  • Posted

    New version fix45.

    ++ can be used to concatenate string (instead of Lua's .. that is used for time intervals in  ER)

    rule("log('A'++'B')"

    === can be used. for string match

    rule("str==='b'")

    is the same as

    rule("str:match(b)")

     

    There are some new tags in log strings

    rule("log('#T:MyTag#This is a log statement using the tag MyTag')")

    rule("log('#C:red#This is a log statement using the color red')")

    • Thanks 1
    Posted
    1 hour ago, jgab said:

     

    Yes, the normal way is to store the HT in a fibaro global variable and read it in the scenes and QAs that need it.

    There are various philosophies how to create HTs. Some like to scan all devices and automatically create HTs using the names and rooms they are in. Others like to create them manually (I belong to the latter category).

    One can also do something in-between, scan for devices and add other data manually.

    To store the table.

    fibaro.setGlobalVariable("HT",json.encode(HT))

    To retrieve it

    HT = json.decode((fibaro.getGlobalVariable("HT")))

    works both in scenes and QAs. 

    It could be a good idea to have a Scene where you define the HT and store it and that can be easily run to re-generate the table.

     

    In ER when you read in the HT, you also define it to be usable as variables within ER rules

    Please login or register to see this code.

     

    The problem is that if your HT is redefined, you should also restart the ER QA so it will read in the new HT table and define ER variables with the new values.

    One way to achieve that automatically is to create a rule like this

    Please login or register to see this code.

    because it will trigger when the fibaro global named 'HT' change value.

    Thank you for explaining this ?

    Posted
    2 hours ago, jgab said:

    New version fix45.

    ++ can be used to concatenate string (instead of Lua's .. that is used for time intervals in  ER)

    rule("log('A'++'B')"

    === can be used. for string match

    rule("str==='b'")

    is the same as

    rule("str:match(b)")

     

    There are some new tags in log strings

    rule("log('#T:MyTag#This is a log statement using the tag MyTag')")

    rule("log('#C:red#This is a log statement using the color red')")

     


    Can you see an example of using the above function?

    Posted

    Jan,

    In HC2 I start my home stereo by starting a scene with :

    local http = net.HTTPClient()

    function call(url)
      http:request(url, {
          options = { method = 'GET' },
          success =function() fibaro:debug(url.." ,done.") end,
          error = function(errorcode) fibaro:debug("error=" .. errorcode)end
        })
    end 

    -- start Denon
      call("http://192.168.1.74/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON")
     --volume hard stand 750
     call("http://192.168.1.74/MainZone/index.put.asp?cmd0=PutMasterVolumeSet/-18.0")
      end

    What I try in HC3 it will give an error or its not switching my home stereo on.

     

    Please advice,

    //Sjakie

  • Topic Author
  • Posted

    One error is that you need to change the fibaro:debug to fibaro.debug(tag, ...) 

    which causes an error when trying to log the result

    ...however the command should work anyway.

    Posted

    Jan,

    Thanks, error in scene is gone now.

    In debug its writng:

    [24.01.2021] [07:00:19] [DEBUG] [SCENE301]: http://192.168.1.24/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON ,done.

    But the Denon doest start!

    If paste in browser:

    192.168.1.24/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON

    it will start.

    So i tried without http:// no luck.

    What to do?

    //Sjakie

  • Topic Author
  • Posted

    Try https

    https://192.168.1.24/MainZone/index.put.asp?cmd0=PutZone_OnOff%2FON

     

    Posted

    Jan,

    error

    [24.01.2021] [09:38:37] [DEBUG] [SCENE301]: error=certificate verify failed

    Fibaro ca.cer is added

    //Sjakie

    Posted (edited)
    On 1/21/2021 at 6:44 AM, jgab said:

     

     

    Please login or register to see this code.

     

    @jgab

    Are you sure that plugin.restart() is working correctly? Because after using this rule and restarting ER4 it looks that rules are doubled ...

    Only HC3 restart help me ...

     

    Edited by petrkl12
  • Topic Author
  • Posted
    9 hours ago, petrkl12 said:

    @jgab

    Are you sure that plugin.restart() is working correctly? Because after using this rule and restarting ER4 it looks that rules are doubled ...

    Only HC3 restart help me ...

     

    I think you have experienced the "ghost QA" phenomenon. Sometimes my QAs seems to run double. Like the old version is not removed or killed. I have sen it in other QAs than ER and some months ago on ER. I think that removing the QA and reinstalling it worked for me, but restarting the HC3 may work too.

    I don't believe it's plugin.restarts() fault as I didn't use it at the times.

    I believe this is a QA/HC3 bug and I haven't found the reason for it yet.

    Will it always run double when you restart it with plugin.restart() from ER?

    (for me it works without problem)

  • Topic Author
  • Posted
    21 hours ago, Sjakie said:

    Jan,

    error

    [24.01.2021] [09:38:37] [DEBUG] [SCENE301]: error=certificate verify failed

    Fibaro ca.cer is added

    //Sjakie

    Try

    options = { method = 'GET', checkCertificate = false },

    Posted
    11 hours ago, jgab said:

     

    I think you have experienced the "ghost QA" phenomenon. Sometimes my QAs seems to run double. Like the old version is not removed or killed. I have sen it in other QAs than ER and some months ago on ER. I think that removing the QA and reinstalling it worked for me, but restarting the HC3 may work too.

    I don't believe it's plugin.restarts() fault as I didn't use it at the times.

    I believe this is a QA/HC3 bug and I haven't found the reason for it yet.

    Will it always run double when you restart it with plugin.restart() from ER?

    (for me it works without problem)

    Thanks. I have deleted that rule because I'm currently in "production" with HC3. During weekend I will test it.

     

  • Topic Author
  • Posted

    It can be useful to enable/disable ER rules

    Assume that we have a rule that we want to run every minute between 15:00 and 16:00.

    One approach is to have a rule that fires every minute and then check if we are within the interval.

    Please login or register to see this code.

    That is an ok rule but it runs every minute 24x7 just for the 1 hour interval.

    Another approach is to have additional rules that enable/disable the ping rule

    Please login or register to see this code.

    Now we have 3 rules. The first is our pinger and the other 2 enables and disables the pinger rule at 15.00 and 16:00.

    This is much more efficient as @rules are scheduled with setTimeout and will effectively sleep until they are activated.

    Note here that when we define the ping rule we call .disable() on the rule so that it is disabled from start.

     

    This way to enable sets of rules is useful. 

    One could have a set of rules running weekdays and another set for weekends. Different sets of rules for Winter, Springs Summer and Fall.

     

    ER has the concept of rule sections that makes it easy to group rules. A feature that has been available in ER for a long time.

    Please login or register to see this code.

     

    In ER rules we can use disable(<section>) to disable all rules tagged with a section.

    Even better is that if we do enable(<section>,true) it will enable the section and disable all other sections (tagged rules). This works well if all sections are mutually exclusive. Otherwise one can choose what sections to angle and disable explicitly.

     

    The last 2 rules are not tagged with a section, otherwise they would too get disabled. These rules select the section to enable depending on the month is called with .start() so the rule will run when the QA starts up so that the  right set of rules are enabled even if it's not midnight...

    • Thanks 1
    Posted

     

    Please login or register to see this code.


    Do all the rules under the above command have a winter tag?


    In other words, will all rules have winter tags until the next same tag instruction is executed?
     

  • Topic Author
  • Posted
    3 minutes ago, Earybeongbeong7 said:

     

    Please login or register to see this code.


    Do all the rules under the above command have a winter tag?


    In other words, will all rules have winter tags until the next same tag instruction is executed?
     

    Yes,

    and if. you set it to nil the next rules will not be tagged.

    Posted (edited)
    On 1/26/2021 at 8:11 PM, jgab said:

    This way to enable sets of rules is useful. 

    One could have a set of rules running weekdays and another set for weekends. Different sets of rules for Winter, Springs Summer and Fall.

     

    ER has the concept of rule sections that makes it easy to group rules. A feature that has been available in ER for a long time.

    Please login or register to see this code.

     

    In ER rules we can use disable(<section>) to disable all rules tagged with a section.

    Even better is that if we do enable(<section>,true) it will enable the section and disable all other sections (tagged rules). This works well if all sections are mutually exclusive. Otherwise one can choose what sections to angle and disable explicitly.

     

    The last 2 rules are not tagged with a section, otherwise they would too get disabled. These rules select the section to enable depending on the month is called with .start() so the rule will run when the QA starts up so that the  right set of rules are enabled even if it's not midnight...

     

    And in the example rule above, if the command below is true, does the winter tag's rule ignore .disable() and work immediately?

    Edited by Earybeongbeong7
  • Topic Author
  • Posted
    3 minutes ago, Earybeongbeong7 said:

     

    And in the example rule above, if the command below is true, does the winter tag's rule ignore .disable() and work immediately?

    A rule is always disabled until it gets enabled (by another rule) and vice versa.

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