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

    Here is a simple introduction into EventRunner4. I will add to the post over the days that come.

     

    The important function in ER4 is QuickApp:main() where you setup your rules.

    Please login or register to see this code.

    • We make a shortcut function for defining rules named 'rule'. The longer version is self:evalScript()...
    • We enable the types of trigger we are going to handle, here type='device', type='global-variable'
    • We define a "HomeTable" named HT. We could also read it in from a global variable
    • We call Util.defvars and Util.reverseMapDef to make the home table accessible from within our rules.
    • ...and we define a rule hat alternates between logging "Tick" and "Tock" every 5 second.

    So rules are strings that describe what we want to do in a made-up language that I call EventScript. It's designed to be simple and brief and still use programming concept. Don't let people trick you with script languages they say is not programming - if it's about expressing cause and effect it's programming. However, we try to make it as easy as possible.

     

    A rule is defined as a test and arrow "=>" and some statements that should run if the test is true.

    Please login or register to see this code.

    The variables 'motion' and 'lamp' comes from the Util.defvars(HT) we did in the beginning. It will declare all the symbols in HT as variables accessible from rules.

    'lamp' is defined as 25 that is the deviceId of the lamp.  25:on will apply the command 'on' on device 25 which will result that the lamp is turned on (a fibaro.call(25,"turnOn" under the surface)

    In the same way, motion:isOn returns true if the motion sensors with id 21 is breached. When the test is true the action on the other side of the arrow "=>" will be executed, and the lamp turned on.

    The test can be more complex than just a single test. Logical operators AND,OR,NOT written as '&' ,'|' , '!' is also allowed

    Please login or register to see this code.

    This adds the extra condition that the time needs to be between sunset-30min and sunrise for the test to be true.

    Please login or register to see this code.

    ...or a fibaro global variable named "DayTime" needs have the value "Night" for this rule to be true. A fibaro global is written with a '$' sign infront of the name.

    We can set up rules to set our variable automatically depending on time of day.

    Please login or register to see this code.

    The '@' command defines a rule that is scheduled at the time specified. Here we also add extra conditions for different weekdays. The general idea here is that on weekdays we follow strict times and on weekends we follow the sun more... We can of course add more conditions to capture the way we want to change the DayNight variable during the day  - check if it's vacation, set 'Morning' when someone moves into the kitchen on the morning etc.

     

    Assume you want to turn on a light when a sensor is breached and turn it off when the sensor been safe for 5min

    Please login or register to see this code.

    The first rule turns on the lamp, like in the example before.

    The 'trueFor' command takes a time and an expression and returns true when the expression been true for the time specified, here 5min.

     

    The ':' commands we used for checking breached and turning on lamps can be applied to an array of devices.

    Please login or register to see this code.

    Here we see that rules can also use Lua global variables directly. No need to do Util.defvars. However, it's a little bit more efficient to declare them, and we don't pollute the Lua variable name space. Anyway. we see we can use the same rules to check a room with multiple motion sensors and turning on multiple lamps.

     

    There is a lot of commands and variations that allows for very complex rules to be written if needed. However, often simple rules if designed correctly is enough.

    There is a || <test> >> <actions> syntax for actions that is a type of if-then-else but gives a nice syntax for different choices.

    Please login or register to see this code.

    Here we assume that the lamp is a dimmer so that we can set the (dim) value of the lamp.

    We could have made 4 rules, each testing the breached and time of day and set the dimmer correctly, but this makes it a bit shorter to type...

     

    We can setup a keyfob that allow us to change the DayTime global with different keypresses. This allows us to override the time schedule setup earlier that sets DayTime to 'Evening' at 17:00 and set it to 'Evening' immediatly when we press 5 on our keyfob.

    Please login or register to see this code.

    When DayTime is changed we can call actions, like turning on or off lamps

    Please login or register to see this code.

    More examples to come...

    Edited by jgab
    • Like 1
    • Thanks 1
    Posted

    Hi j

    remotec zxt-600

    Is there an instruction?

    I couldn't find it in this post

    Are there any example rules for air conditioning ir controllers?

     

     

     

    Please login or register to see this attachment.

  • Topic Author
  • Posted
    19 minutes ago, minsad79 said:

    Hi j

    remotec zxt-600

    Is there an instruction?

    I couldn't find it in this post

    Are there any example rules for air conditioning ir controllers?

    Please login or register to see this attachment.

     

    No, and I don't have any to test against.

    In general, this is what to do when you have a new type of device there is no support for in ER4

    We assume that it's a device that send device triggers.

    Define a rule and a Lua command and run it

    Please login or register to see this code.

    The rule will log triggers when you interact with the device (manually or with fibaro.cal)

    The second command logs all actions defined for the device (sometimes there are more actions). Try those actions.

    So, assume that fibaro.call(88,"setPoint",50) generates the trigger

    Please login or register to see this code.

    Then you can use the :value property in your rules, ex.

    Please login or register to see this code.

    However, if it's a new property it reports, like

    Please login or register to see this code.

    We don't have support for the 'point' attribute, we we can still write a rule by triggering on the event

    Please login or register to see this code.

    and we can use fibaro.calls in the rule to call actions

    Please login or register to see this code.

    So, if you make this work - and you discover some properties that are not supported and some actions that you would like to call with ID:<action> syntax, post a description of the triggers/properties and actions and I will see how we can integrate it.

    There are some commands left in HC3 that was in HC2 for thermostats:

    Please login or register to see this code.

    but I'm unsure if they are valid for the HC3 and the fibaro.com.hvacSystem

    Posted

    Hi Jan,

     

    I'm still on HC2. After Updating to 4.6 I got an error in all my ER3-scenes, reversed to 4.58 and got the same error. See attached file.

     

     

     

    Please login or register to see this attachment.

    Posted

    Hello @FrankT,

    Sometimes I had this error after modifying a scene and I have till today no clue what caused that error.

    Reverting scene back to older version and restart HC2 was my solution.

    I hope this will work for you too!

    //Sjakie

  • Topic Author
  • Posted
    38 minutes ago, FrankT said:

    Hi Jan,

    I'm still on HC2. After Updating to 4.6 I got an error in all my ER3-scenes, reversed to 4.58 and got the same error. See attached file.

    Please login or register to see this attachment.

     

    So, it's an internal json.decode error. However, it is most likely due to that some bad string is fed to json.decode. 

    It can be a call to an external service, like Nodered or other web service. You do something like that in the beginning of main() ?

    You had a similar problem last year. A corrupt hometable you are json decoding in the beginning of main()?

    I've upgraded to 4.6 without a problem so it's probably not ER3 as such, but the interaction with something that introduces a bad json string.

    Posted

    After som try and error I found that the following change in my ER3-scenes made my scenes running again. Will look at what happened this later this week, but for now it's ok.

     

    local _version,_fix = "3.0","B89"  -- Mar 25, 2020 

    local _sceneName   = "NodeRedER3"                                 -- Set to scene/script name

    local _homeTable   = "HomeTable"

    function main()

       local HT = type(_homeTable)=='number' and api.get("/scenes/".._homeTable).lua or fibaro:getGlobalValue(_homeTable)

     

    changed to

     

    local _version,_fix = "3.0","B89"  -- Mar 25, 2020 

    local _sceneName   = "NodeRedER3"                                 -- Set to scene/script name

    local _homeTable   = "HomeTable"

    function main()

       local HT = fibaro:getGlobalValue(_homeTable)

  • Topic Author
  • Posted

    Here is a new test version of ER4 using the latest firmware 5.040.37.

    It's no real change to the code but it's divided up in two files. 'main' is just the main() function where rules are added. This way we don't need to see the rest of the code  and it feels quicker to save the QA if only the main has been changed.

    Please login or register to see this attachment.

    • Like 1
    Posted

    Jan, thanks.

    Just to be sure this EventRunner4.fqa is only the executed scene.

    So on my old file I have removed the "scene"part.

    I lost my two test devices both broken, pity.

    To convert step by step into HC3 I have some troubles.

    Please login or register to see this attachment.

    Please advice

    //Sjakie

     

  • Topic Author
  • Posted
    1 hour ago, Sjakie said:

    Jan, thanks.

    Just to be sure this EventRunner4.fqa is only the executed scene.

    So on my old file I have removed the "scene"part.

    I lost my two test devices both broken, pity.

    To convert step by step into HC3 I have some troubles.

    //Sjakie

    I've just uploaded a new version. You should only add your rules to the 'main' file of the QA.

    Btw, your picture doesn't show any real errors (the "Unhandled event" message is just a log - and that event is taken care of in the new version)

    Posted

    Jan, sorry to be a bit dumb.

    Please login or register to see this attachment.

    If I install  in devices, other, upload file I see only?

    _debugFlags = {  fcall=true, triggers=true, post = true, rule=true  } 
     
    function QuickApp:main()    -- EventScript version
      local rule = function(...) return self:evalScript(...) end          -- old rule function
      self:enableTriggerType({"device","global-variable","custom-event"}) -- types of events we want
     
      HT = { 
        keyfob = 26
        motion= 21,
        temp = 22
        lux = 23,
      }
     
      Util.defvars(HT)
      Util.reverseMapDef(HT)
      
      rule("@@00:00:05 => log(now % 2 == 1 & 'Tick' | 'Tock')")
    end
     
    No main at all or where to look?
    Please advice,
    //Sjakie
  • Topic Author
  • Posted (edited)
    15 minutes ago, Sjakie said:

    No main at all or where to look?

    please advice,

    //Sjakie

    Yep, have you updated to the latest firmware 5.040.37?

    A QA now consist of several "files", up in the left hand corner of the editor there is a "document icon" that you can click on and reveal the different files.

    Most of the EventRunner code is put in the "EventRunner" and "Toolbox" files. However, you only add your rules to the 'main' file inside the main() function as usual.

    Edited by jgab
    Posted

    Jan, hehe sorry now I see main too.

    I am updated to the latest version and downloaded again the latest ER

    Same error pops up>>report

    Q:

    Please login or register to see this image.

    /monthly_2020_07/image.png.1fcbe3ef4fb5d9a366df0c094a8a0de1.png" /> 


    Does this works in ER4?

    Please advice

    //Sjakie

     

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

    Jan, hehe sorry now I see main too.

    I am updated to the latest version and downloaded again the latest ER

    Same error pops up>>report

    Q:

    Please login or register to see this link.

     


    Does this works in ER4?

    Please advice

    //Sjakie

     

    Sorry, I don’t see an error message. Just a rule. If you post, in text form,  the rule that gives an error I can copy it and try it.

    • 2 weeks later...
    Posted

    Hi j

    ER4

    To use

    Is there a nodered flow?

    Posted

    Hello Jan,

    This rule gives an error:

    Util.defTriggerVar("openVanBuitenDeurToilet",false)

     rule("toilet.Door:breached => || toilet.pir:safe >> openVanBuitenDeurToilet=true || toilet.pir:breached >> openVanBuitenDeurToilet=false")

        rule("openVanBuitenDeurToilet==true => log2('orange','deftrigger openVanBuitenDeurToilet true')")
        rule("openVanBuitenDeurToilet==false => log2('orange','deftrigger openVanBuitenDeurToilet false')")

        rule("openVanBuitenDeurToilet==true => hal.relaisTest1:on; log1('violet','#toiletBezet1 - post')")
        rule("openVanBuitenDeurToilet==false => hal.relaisTest1:off; log1('violet','#toiletVrij2 - post')")

    Please login or register to see this attachment.

    Please advice.

    //Sjakie

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

    Hello Jan,

    This rule gives an error:

    Util.defTriggerVar("openVanBuitenDeurToilet",false)

     rule("toilet.Door:breached => || toilet.pir:safe >> openVanBuitenDeurToilet=true || toilet.pir:breached >> openVanBuitenDeurToilet=false")

        rule("openVanBuitenDeurToilet==true => log2('orange','deftrigger openVanBuitenDeurToilet true')")
        rule("openVanBuitenDeurToilet==false => log2('orange','deftrigger openVanBuitenDeurToilet false')")

        rule("openVanBuitenDeurToilet==true => hal.relaisTest1:on; log1('violet','#toiletBezet1 - post')")
        rule("openVanBuitenDeurToilet==false => hal.relaisTest1:off; log1('violet','#toiletVrij2 - post')")

    Please login or register to see this attachment.

    Please advice.

    //Sjakie

     

    When it complains "no trigger found in header" for a rule it means that it couldn't deduce any deviceId from the expression on the header. In your case "toilet.Door:breached", which means that toilet.Door is most likely nil. Wring spelling or HT issue?

  • Topic Author
  • Posted (edited)
    16 hours ago, minsad79 said:

    Hi j

    ER4

    To use

    Is there a nodered flow?

    I have the test flow below with ER4

    You can use rules like

    Please login or register to see this code.

    There are 4 pre-defined messages, echo1,echo2,echo3,echo4

    echo1 and echo2 are asynchronous. Meaning that NR gets the message and answers with a separate post back to HC3.

    echo3 and echo4 flow, NR will return the result in the response to the request that the HC3 sends.

    This is purely how you want to structure things on the NR side - it doesn't affect ER4/HC3. ER4 handles both in the "same" way. Ex. if you want NR to send messages to ER4 without ER4 asking for them you need the "asynchronous flow".

     

    So, independently of if the NR handles to asynchronous or synchronous, the second argument to Nodered.post is a boolean if ER4 should handle the request as synchronous or not  for the ER4 rules.

    Synchronous means that the Nodered.post returns the NR result directly. Asynchronous you need to define a rule that picks up the answer. (it can still be either synchronous or asynchronous on the NR side)

    You need to manually setup _HC3IPADDRESS = "192.168.1.57". It is included in the messages to NR so NR knows where to send back (asynchronous) replies. In the next version I will have a fix for this so ER4 can figure out the address itself.

     

    Please login or register to see this spoiler.

     

    Edited by jgab
    Posted

    Sorry Jan, I should have seen it by myself.

    How can I:

    - get more color in Debug as in ER3?

    Rule.eval("log3('lightgreen','OPSTAAN EN BEDTIJD')")

    - not to get in debug:

    [false]>>'Rule:13[toilet.door:breached => log('door toilet - geopend')]'

    Thanks in advance,

    //Sjakie

    Posted
    18 hours ago, jgab said:

    I have the test flow below with ER4

    You can use rules like

    Please login or register to see this code.

    There are 4 pre-defined messages, echo1,echo2,echo3,echo4

    echo1 and echo2 are asynchronous. Meaning that NR gets the message and answers with a separate post back to HC3.

    echo3 and echo4 flow, NR will return the result in the response to the request that the HC3 sends.

    This is purely how you want to structure things on the NR side - it doesn't affect ER4/HC3. ER4 handles both in the "same" way. Ex. if you want NR to send messages to ER4 without ER4 asking for them you need the "asynchronous flow".

     

    So, independently of if the NR handles to asynchronous or synchronous, the second argument to Nodered.post is a boolean if ER4 should handle the request as synchronous or not  for the ER4 rules.

    Synchronous means that the Nodered.post returns the NR result directly. Asynchronous you need to define a rule that picks up the answer. (it can still be either synchronous or asynchronous on the NR side)

    You need to manually setup _HC3IPADDRESS = "192.168.1.57". It is included in the messages to NR so NR knows where to send back (asynchronous) replies. In the next version I will have a fix for this so ER4 can figure out the address itself.

     

    Please login or register to see this spoiler.

    Hi Jan

    Thanks i will test

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