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



jgab

Recommended Posts

  • Topic Author
  • Functions and properties

     

    There are a lot of built-in functions in EventScript and they come in 3 flavours depending on how they are implemented.

     

    Native builtin functions. These are implemented very efficient in the "virtual machine" that runs EventScript.

    Ex. the log function.

    Please login or register to see this code.

    The can't be redefined as the native function will always be chosen.

     

    Lua functions available in EventScripts.

    Global Lua functions are available in EventScript.

    Ex

    Please login or register to see this code.

    because 'fibaro' is a global variable in QuickApps, we have access to all fibaro.* functions

    We can also define our own Lua function

    Please login or register to see this code.

    We can also set an EventScrip variable to a Lua function

    Please login or register to see this code.

    Please login or register to see this code.

    is the same as 

    Please login or register to see this code.

    and 'var' is a special table containing the variables accessible in EventScript.

     

    Property functions

    A short way to do operations on HC3 resources (devices, etc) is to use the property notion :<property>

    Ex.

    Please login or register to see this code.

    :isOn is a property function that returns true or false depending on if the lamp is on (deviceId 55 in this case), and :on is a property function that turns on the device (deviceId 66 in this case).

    Normally, we don't use the deviceId numbers directly bit have them assigned to variables

    Please login or register to see this code.

     

    Some property function "takes arguments", and we do that by assigning them a value

    Please login or register to see this code.

    Here we set the lamps value property to 50 (e.g. dimming it to 50%). lamp:value=50 is translated by EventScript to fibaro.call(66,"setValue",50)

     

    Another aspect of property functions is that they also work on list of resources.

    Please login or register to see this code.

    For most "action" property functions, the function is just applied to all elements in the list. In this case :on is applied to all devices in the list.

    Please login or register to see this code.

    Here all lamps will be dimmed to 50%

    :value not assigned a value, will just retrieve the value of the device

    Please login or register to see this code.

    If we do :value on a list of devices

    Please login or register to see this code.

    we will get a list back with the values of the lamps. Something like

    Please login or register to see this code.

     

    Some property functions, especially the predicates, when applied to list of resources will do further reductions of the list producing single values.

    Ex.

    Please login or register to see this code.

    :isOn applied to a list of devices will return true if any lamp is on in the list, and return false if all are of.

    The logic is that a room is lit if any lamp in the room is on.

    :isOff is on the other hand true if all are off, otherwise it's false.

    Exactly how property functions behave is dependent on the function in question and is documented below.

     

    List of property functions

    Properties functions are documented when applied to a list of resources if it does anything else than just apply the function to each element in the list

    • <device>:isOn
      Returns true if the device is on. If the value property is a boolean, it returns the value (works with binary sensors/switches). If the value is a numeric value it return false if the value is 0 and true if the value is > 0. (works with multilevel switches/sensors)
    • <list>:isOn
      Returns true if any device in the list is on, otherwise false
       
    • <device>:isOff
      The opposite of :isOn
      Returns true if the device is off. If the value property is a boolean, it returns the value (works with binary sensors/switches). If the value is a numeric value it return false if the value is > 0 and true if the value is 0. (works with multilevel switches/sensors)
    • <list>:isOff
      Returns true if all device in the list is off, otherwise false
       
    • <list>:isAnyOff
      Returns true if any device in the list are off. Applied to a single device is the same as :isOff
       
    • <list>:isAllOn
      Returns true if all devices in the list are off. Applied to a single device is the same as :isOn
       
    • <device>:isDead
      Returns true if the device is reported dead
       
    • <device>:breached
      Returns true if the sensor is breached. Implementation is the same as :isOn, but is better to use for sensors as it documents the intention with the rule better.
    • <list>:breached
      Same as :isOn on lists.
       
    • <device>:safe
      Returns true if the sensor is safe. Implementation is the same as :isOff, but is better to use for sensors as it documents the intention with the rule better.
    • <list>:safe
      Same as :isOff on lists.
       
    • <device>:on
      Turns on a device. Translates to fibaro.call(<device>,"turnOn")
       
    • <device>:off
      Turns off a device. Translates to fibaro.call(<device>,"turnOff")
       
    • <device>:value
      Returns the value property of a device. Note that the values can be of different types depending on the type of device. binary sensor have boolean values. multilevel sensors have numeric values.
    • <device>:value=<value>
      Sets the value of a device.
       
    • <device>:state
      Returns the state property of a devices. a boolean value.
    • <device>:state=<value>
      Sets the state property of a device. a boolean value.
       
    • <device>:last
      Returns the number of seconds since the device last changed state. Not all devices have this property but most sensors and actuators seem to do.
       
    • <device>:temp
      Returns the value property of a temperature sensor. 
       
    • <device>:bat
      Returns the battery property of a battery operated device. Nil if the device is not battery operated.
       
    • <device>:power
      Returns the power property of a device. Nil if the device don't have a power property
       
    • <partition>:arm
      Arms a partition
       
    • <partition>:tryArm
      Tries to arm a partition. If any device is breached in the partition it will post an event with the breached devices
      Ex.
       
    • <partition>:isArmed
      Returns true of partition is armed
    • <list of partitions>:isArmed
      Returns true if any partition is armed
       
    • <list of partitions>:isAllArmed
      Returns true if all partitions in list is armed
       
    • <partition>:isDisarmed
      Returns true if partition is disarmed
    • <list of partitions>:isDisarmed
      Returns true if all partitions are disarmed
       
    • <list of partition>:isAnyDisarmed
      Returns true if any partition in list is disarmed
       
    • <partition>:isAlarmSafe
      Returns ...
       
    • <partition>:isAllAlarmBreached
      Returns ...
       
    • <partition>:isAnyAlarmSafe
      Returns ...
       
    • <device>:name
      Returns the name of the device
       
    • <device>:roomName
      returns the name of the room the device belongs to
       
    • <profile id>:profile
       
    • <device>:scene
       
    • <device>:access
       
    • <device>:central
       
    • <device>:isOpen
       
    • <device>:isClosed
       
    • <device>:lux
       
    • <device>:volume
       
    • <device>:position
       
    • <device>:play
       
    • <device>:pause
       
    • <device>:open
       
    • <device>:close
       
    • <device>:stop
       
    • <device>:secure
       
    • <device>:unsecure
       
    • <device>:isSecure
       
    • <device>:isUnsecure
       
    • <device>:time
       
    • <device>:manual
       
    • <scene id>:start
       
    • <scene id>:kill
       
    • <device>:toggle
       
    • <device>:wake
       
    • <device>:removeSchedule
       
    • <device>:retryScheduleSynchronization
       
    • <device>:setAllSchedules
       
    • <device>:levelIncrease
       
    • <device>:levelDecrease
       
    • <device>:levelStop
       
    • <list>:average
      Returns the average of a list with number. true counts as 1 and false as 0

      Please login or register to see this code.

      This applies :power to a list of lamps, return a list of power consumption. :average applied to that sums up the list for the total consumption.
       
    • <list>:sum

      Returns the sum of a list.

      Please login or register to see this code.

      This applies :power to a list of lamps, return a list of power consumption. :sum applied to that sums up the list for the total consumption.

    • <list>:allFalse
      Returns true if all values in a list is false. 0 counts as false, and numbers > 0 counts as true.
      lamps:allFalse becomes the same as lamps:isOff, but may be better to use on a list of booleans
       
    • <list>:someFalse
      Returns true if the list contains any false value.  0 counts as false, and numbers > 0 counts as true.
       
    • <list>:allTrue
      Returns true if all values in the list is true.  0 counts as false, and numbers > 0 counts as true.
       
    • <list>:someTrue
      Returns true if the list contains any true value.  0 counts as false, and numbers > 0 counts as true.
       
    • <list>:mostlyTrue
      Returns true if more than half of the values are true.  0 counts as false, and numbers > 0 counts as true.
       
    • <list>:mostlyFalse
      Returns true if more than half of the values are false.  0 counts as false, and numbers > 0 counts as true.
       
    • <list>:bin
      Return a list where every true becomes 1 and every false becomes 0.  0 counts as false, and numbers > 0 counts as true.
      <list>:bin:sum will return the number of true values
       
    • <list>:GV
      Given a list of strings will return a list of global variable objects

      Please login or register to see this code.

      will return a list of the values of global variables var1,var2,var3
       
    • <list>:QV
      Given a list of strings will return a list of quickApp variable objects

      Please login or register to see this code.

      will return a list of the values of quickApp variables var1,var2,var3
       
    • <to be continued>

     

    List of functions

    • post(event[,time])
       
    • cancel(ref)
       
    • log(...)
       
    • fmt(...)
       
    • HM(time)
       
    • HMS(time)
       
    • wday(str)
       
    • day(str)
       
    • month(str)
       
    • date(cron_str)
      cron string format: "<min> <hour> <day> <month> <wday> <year>"
      min: 0-59
      hour: 0-23
      day: 1-31
      month: 1-12
      wday: 1-7 1=sunday
      year: YYYY

      Ex:
      "0 * * * * *"               Every hour
      "0/15 * * * * *"          Every 15 minutes
      "0,20 * * * * *"          At even hour and 20min past
      "0 * * 1-3 * *"            Every hour, January to March
      "0 7 lastw-last * 1 *" 7:00, every sunday in the last week of the month
      "sunset -10 lastw-last * 1 *" 10min before sunset every sunday in the last week of the month

      Ex.
      rule("@@00:01 & date('"0/15 1,last * * * *") => log('ping every 15min first and last day of month')")
       
    • sign(number)
       
    • rnd(low, high)
       
    • round(number)
       
    • sum(...)
       
    • average(...)
       
    • size(list)
       
    • min(...)
       
    • max(...)
       
    • sort(...)
       
    • match(str, pattern)
       
    • osdate()
       
    • ostime()
       
    • global(str)
       
    • listglobal()
       
    • deleteglobal(str)
       
    • publish(event)
       
    • subscribe(event)
       
    • remote(id, event)
       
    • adde(element, list)
       
    • remove(...)
       
    • enable(...)
       
    • disable(...)
       
    • wait(time,tag)
       
    • once(expr)
       
    • trueFor(time,expr[,log])
       
    • again(n)

     

     

     

     

    Edited by jgab
    Link to comment
    Share on other sites

    Jan,

    [07.11.2023] [17:40:24] [ERROR] [QUICKAPP1061]: [Rule:80] Rule: No triggers in rule
    month('nov') => 

    Please login or register to see this code.

    I have 12 months as:

    || month('jan') >>

    || month('feb') >>

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, Sjakie said:

    Jan,

    [07.11.2023] [17:40:24] [ERROR] [QUICKAPP1061]: [Rule:80] Rule: No triggers in rule
    month('nov') => 

    Please login or register to see this code.

    I have 12 months as:

    || month('jan') >>

    || month('feb') >>

    month('nov') has never worked as a trigger. It's jus a test.

    The way to check if a specific date has occurred is to have a check every day if the right time is up.

    Do you want your rule to only trigger the first day of November or every day during November? and at what time?

    Link to comment
    Share on other sites

  • Topic Author
  • 39 minutes ago, Sjakie said:

    just whole month

    Please login or register to see this code.

    ..but when do you want the rule to trigger? The first second of November? or every day in November?

    First second of the first day of November 

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Jan can you print also the line of rule who causes the error?

    Please login or register to see this code.

    There are around 20 devices between the blue chapters.

    Thanks

    Link to comment
    Share on other sites

  • Topic Author
  • 31 minutes ago, Sjakie said:

    Jan can you print also the line of rule who causes the error?

    Please login or register to see this code.

    There are around 20 devices between the blue chapters.

    Thanks

    No, I can't give you the line as Fibaro has taken away the Lua function to get at that...

    However, it should not give this kind of error, but a more informative one with the Rule ID etc. So, it's a bug - I will release a new version in an hour or so...

    Link to comment
    Share on other sites

    Please login or register to see this code.

    Jan I have no clue where to locate this error, perhaps I don't get the clue.

    Rule 22???

    I have 12 lines with this frase remote(1066, #... in around 200 lines

    version 0.032

    Please advice

     

    Link to comment
    Share on other sites

  • Topic Author
  • 53 minutes ago, Sjakie said:

    Please login or register to see this code.

    Jan I have no clue where to locate this error, perhaps I don't get the clue.

    Rule 22???

    I have 12 lines with this frase remote(1066, #... in around 200 lines

    version 0.032

    Please advice

     

    It says "

    Please login or register to see this code.

    So check which rule is defined after rule 21 and before rule 23

    Link to comment
    Share on other sites

    Jan thats very easy if I don't count rule(" and only rule([[  I will see a line with the frase

    So I counted all rules

     

    Link to comment
    Share on other sites

  • Topic Author
  • 5 minutes ago, Sjakie said:

    Jan thats very easy if I don't count rule(" and only rule([[  I will see a line with the frase

    So I counted all rules

     

    But don't all rules log something like "[Rule:x] Defined"

    ?

     

    Anyway, I take the feedback and will see if it can be improved. I think that in practice loading of rules should stop at the first error....

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • 6 minutes ago, Sjakie said:

    Jan whats the correct notation to select whole month?

    to check if it's a specific month you do month(....)

    Ex.

    rule("@sunset & month('apr') => log('It's sunset and it's April')") -- Will log every sunset in April

    rule("@sunset & month('apr-jun') => log('It's sunset and it's April to June')") -- Will log every sunset in April.May and June

    rule("@sunset & month('apr-jun,oct') => log('It's sunset and it's April to June, or October')") -- Will log every sunset in April.May and June, and October

    Link to comment
    Share on other sites

    Jan I have this error

    Please login or register to see this code.

     

    Please login or register to see this code.

     

    Edited by Sjakie
    Link to comment
    Share on other sites

  • Topic Author
  • I think you mean 

    Please login or register to see this code.

    with an '&' you get nil/false if Last_Afz_Badkamer_Hum_Delta is nil/false

    Edited by jgab
    Link to comment
    Share on other sites

    okay, thanks!

    The only error(s) left in ER5 are in relation with 1:armed or disarmed used in other rules. Arming is still on ER4.

    Edited by Sjakie
    Link to comment
    Share on other sites

  • Topic Author
  • 3 hours ago, Sjakie said:

    okay, thanks!

    The only error(s) left in ER5 are in relation with 1:armed or disarmed used in other rules. Arming is still on ER4.

    I Will fix and post how to do alarms this weekend 

    • Thanks 1
    Link to comment
    Share on other sites

    Thanks Jan, no hurry at all.

    I made a way around in ER4 1:armed => wallplug1:on  in ER5  1:armed replaced by wallplug1:isOn

    nice weekend

     

    Please login or register to see this code.

    Also error!!

    Edited by Sjakie
    add error
    Link to comment
    Share on other sites

  • Topic Author
  • 10 hours ago, Sjakie said:

    Thanks Jan, no hurry at all.

    I made a way around in ER4 1:armed => wallplug1:on  in ER5  1:armed replaced by wallplug1:isOn

    nice weekend

     

    Please login or register to see this code.

    Also error!!

    It looks like 'Last_Afz_Keuken_Hum_Delta' is set to true....

    Could you add a log before to print it?

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Hi Jan
    I started playing with you new project, it looks great.

    Would it support the hierarchy as EV4 ?

    Please login or register to see this code.

     

    When i press the "list rules" button , i dont see any of my rules (i copied a few from my EV4) and the same when saving the rules.

    Please login or register to see this code.

     

    [11.11.2023] [12:08:07] [TRACE] [QUICKAPP1961]: UIEvent:  {"values":[],"eventType":"onReleased","deviceId":1961,"elementName":"listRules"}
    [11.11.2023] [12:08:07] [TRACE] [QUICKAPP1961]: Posting {"type":"UI","cmd":"listRules"} at Sat Nov 11 12:08:07 2023 
    [11.11.2023] [12:08:08] [TRACE] [QUICKAPP1961]: UIEvent:  {"values":[],"eventType":"onLongPressReleased","deviceId":1961,"elementName":"listRules"}
    [11.11.2023] [12:08:08] [TRACE] [QUICKAPP1961]: Posting {"type":"UI","cmd":"listRules"} at Sat Nov 11 12:08:08 2023

     

    Should rules have the log added like     rule("log('Wind is %sms',weather:wind)",msgOpts)

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