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
4 hours ago, lux said:

1 second

So it should be in form 00:00:01

Thats it

Posted
18 hours ago, Sjakie said:

01:00 >> 1 hour

01:10 >> 1 hour and 10 min

00:00:01 1 sec

wait(0); in a rule means all above this wait(0) will be executed first before we contimue

 

Guys, switch 2 buttons on and off

press, release, hold properties

on and off no problem

but

how to write in a rule if 1:'Holddown' raise britness fa in steps with 10%

 

@Sjakie 

This is the general pattern for the dim command

<id>:dim = { time, direction, steps, curve, startValue, stopValue }

 

example

 

Ex.

rule("@sunrise-00:30 => lamp:dim = {00:30, 'up', 5, 'Linear', 0, 99}")

  • Topic Author
  • Posted

    Sorry, I'm a bit busy these days. However, ER most likely have problems on the HC3L as it (used to?) have a Lua compiled for 32 bit integers.

    The problem with that is that epoch time (os.time()) is close the the 32bit limit and as soon as we start doing arithmetics with os.time() in our code

    there is a good chance for overflow.

    @lux asked for ER3 and it's true for ER5 too... (and many other QAs doing os.time() arithmetics)

    Please login or register to see this code.

    One could probably recode the arithmetic to cater for overflow but it would in general be to cumbersome...

    • Like 1
  • Topic Author
  • Posted (edited)
    On 9/5/2024 at 10:01 PM, Sankotronic said:

    Hi @Neo Andersson ,

     

    Since this is very small table array with only 10 values, you can use LUA functions table.insert and table.remove. For example, you have table:

    Please login or register to see this code.

    To add new value to the beginning of the table:

    Please login or register to see this code.

    and table will be:

    Please login or register to see this code.

    to remove last value:

    Please login or register to see this code.

    to get:

    Please login or register to see this code.

     

    Why I mention that this two functions are good for small table arrays, maybe up to few hundred values? Because this function needs to move other values in the array when adding or removing one value depending on its position in the array.

    Yes, if its sequential integer values as keys it's normally stored as an array and values need to be shuffled up which takes increasingly longer.

    However, it's still very efficient.

    Please login or register to see this code.

    shifting up and down 100000 values takes 0.038339 seconds on my HC3.

     

    What you probably want is a fixed size queue, that is easy to implement

    Please login or register to see this code.

    ...and use it like

    Please login or register to see this code.

    This one has a fixed insert and remove time as the table is treated as a hashtable

    Edited by jgab
    • Thanks 1
    Posted

    Hi Jan

     

    I'm using a Fibaro blind controller to control a venetian blind.

     

    If I look at the Device editing tab on EventRunner, I can see that the device has a property (-value) which sets the height of the blind, and another (-value2) which sets the slats. 

     

    Please login or register to see this image.

    /monthly_2024_09/Screenshot2024-09-19114126.jpg.e5ef930b743419d5617d663fd36b68e4.jpg" />

     

    This works in the Fibaro UI, which if you translate a simple block scene into lua gives this:

     

    hub.call(71, 'setValue2', 30)
    hub.call(71, 'setValue', 50)

     

    However, if I write a simple script in EventRunner

     

            rule("Test", "$testDayMode == 'On' => study.southVenetians:value = 100 ; study.southVenetians:value2 = 100  ")
            rule("Test2", "$testDayMode == 'Off' => study.southVenetians:value = 0 ; study.southVenetians:value2 = 0")

     

    I get the following error - EventRunner doesn't recognise value2, whilst recognising value.

     

    [Rule:Test2:2]>> [Rule:Test2:$testDayMode == 'Off' => study.southVenetians:value = 0 ; study.southVenetians..] Runtime: :value2 is not a valid device set property for device:71
    $testDayMode == 'Off' => study.southVenetians:value = 0 ; study.southVenetians:value2 = 0

     

    Any idea what's happening?

     

    (this is a great product, by the way - many thanks for it)

     

    Paul

     

    Thanks

    Posted (edited)
    28 minutes ago, Paul Ruskin said:

    Hi Jan

     

    I'm using a Fibaro blind controller to control a venetian blind.

     

    If I look at the Device editing tab on EventRunner, I can see that the device has a property (-value) which sets the height of the blind, and another (-value2) which sets the slats. 

     

    Please login or register to see this link.

     

    This works in the Fibaro UI, which if you translate a simple block scene into lua gives this:

     

    hub.call(71, 'setValue2', 30)
    hub.call(71, 'setValue', 50)

     

    However, if I write a simple script in EventRunner

     

            rule("Test", "$testDayMode == 'On' => study.southVenetians:value = 100 ; study.southVenetians:value2 = 100  ")
            rule("Test2", "$testDayMode == 'Off' => study.southVenetians:value = 0 ; study.southVenetians:value2 = 0")

     

    I get the following error - EventRunner doesn't recognise value2, whilst recognising value.

     

    [Rule:Test2:2]>> [Rule:Test2:$testDayMode == 'Off' => study.southVenetians:value = 0 ; study.southVenetians..] Runtime: :value2 is not a valid device set property for device:71
    $testDayMode == 'Off' => study.southVenetians:value = 0 ; study.southVenetians:value2 = 0

     

    Any idea what's happening?

     

    (this is a great product, by the way - many thanks for it)

     

    Paul

     

    Thanks

    I think the value2 is not defined in ER5, but JGAB can comment on it. If so, either you need to create your own custom preoperty for value2, or you can just use simple LUA command to control the value2.  So you can always use the regular LUA command. hub.call(ID, setValue2, 50).

     

    Please login or register to see this code.

    thats my guess.

    Edited by Neo Andersson
    Posted

    That does seem to work, thank you.  Though like this:

     

            rule("Test", "$testDayMode == 'On' => study.southVenetians:value = 100 ; fibaro.call(study.southVenetians, 'setValue2', 100) ")
            rule("Test2", "$testDayMode == 'Off' => study.southVenetians:value = 0 ; fibaro.call(study.southVenetians, 'setValue2', 0)")

     

    Interestingly, hub.call and fibaro.call seem to be synonomous.

     

    Paul

    Posted
    18 minutes ago, Paul Ruskin said:

    That does seem to work, thank you.  Though like this:

     

            rule("Test", "$testDayMode == 'On' => study.southVenetians:value = 100 ; fibaro.call(study.southVenetians, 'setValue2', 100) ")
            rule("Test2", "$testDayMode == 'Off' => study.southVenetians:value = 0 ; fibaro.call(study.southVenetians, 'setValue2', 0)")

     

    Interestingly, hub.call and fibaro.call seem to be synonomous.

     

    Paul

    Yes they do the same job

    Posted

    I have tried to handle an alarm breach occurring on exit from home but I am unable to get it to work even using the jgab supplied delayed event. Can anyone supply a working version for ER5? My idea was to disarm then retry arming (not tryArm). Logging follows:-

     

    [24.09.2024] [12:36:11] [DEBUG] [QUICKAPP128]: Time:2024-09-24T12:36:11.872061+10:00

    [24.09.2024] [12:36:11] [TRACE] [QUICKAPP128]: 'log('Time:%s',http.get('http://worldtimeapi.org/api/timezone/Australia/Sydney').datetime)' > Time:2024-09-24T12:36:11.872061+10:00 [done]

    [24.09.2024] [12:38:18] [TRACE] [QUICKAPP128]: [Rule:10:1]>> TRUE #device{id=96,valu.. -> redbutton:central.keyId==1 & redbutton..

    [24.09.2024] [12:38:18] [DEBUG] [QUICKAPP128]: ER5 redbutton was clicked 2X

    [24.09.2024] [12:38:18] [DEBUG] [QUICKAPP128]: Current profile:Home

    [24.09.2024] [12:38:18] [DEBUG] [QUICKAPP128]: ER5 The Away profile will be activated

    [24.09.2024] [12:38:22] [DEBUG] [QUICKAPP128]: ER5 About to execute tryArm

    [24.09.2024] [12:38:22] [TRACE] [QUICKAPP128]: Posting #alarm{id=0,value={11=[28]},action="tryArm",property="delayed"} at Tue Sep 24 12:38:22 2024

    [24.09.2024] [12:38:27] [TRACE] [QUICKAPP128]: [Rule:3:1]>> TRUE #alarm{id=0,value=.. -> #alarm{id='$id', property='delayed'} =..

    [24.09.2024] [12:38:27] [WARNING] [QUICKAPP128]: ER5 Partition 11 breached, devices 28

    [24.09.2024] [12:38:27] [WARNING] [QUICKAPP128]: ER5 Disarming

    [24.09.2024] [12:38:32] [WARNING] [QUICKAPP128]: ER5 Rearming

    [24.09.2024] [12:39:32] [TRACE] [QUICKAPP128]: [Rule:1:1]>> TRUE #alarm{id=11,value.. -> #alarm{id='$id', property='breached'} ..

    [24.09.2024] [12:39:32] [WARNING] [QUICKAPP128]: ER5 BREACHED partition:11

    [24.09.2024] [12:39:32] [TRACE] [QUICKAPP128]: [Rule:2:1]>> TRUE #alarm{value=true,.. -> #alarm{property='homeBreached'} => -..

    [24.09.2024] [12:39:32] [WARNING] [QUICKAPP128]: ER5 BREACHED home

    [24.09.2024] [12:39:42] [TRACE] [QUICKAPP128]: [Rule:1:2]>> TRUE #alarm{id=11,value.. -> #alarm{id='$id', property='breached'} ..

    [24.09.2024] [12:39:42] [WARNING] [QUICKAPP128]: ER5 BREACHED partition:11

    [24.09.2024] [12:39:42] [TRACE] [QUICKAPP128]: [Rule:2:2]>> TRUE #alarm{value=false.. -> #alarm{property='homeBreached'} => -..

    [24.09.2024] [12:39:42] [WARNING] [QUICKAPP128]: ER5 BREACHED home

    Posted (edited)

    What cause alarm, device 28 is that a pir or radar?

    if yes should use delay to re-arm till time pir:breached change into pi:safe.

    Split arming in parts take pir's separate?

    I don't use "profile", create it by myself with Iphone.

    rule([[{room1_pir, room2:pir, room3:pir}:safe & $location == 'Away' =>

    4:armed;

    log('Away, pir safe >> partition 4 armed')

    ]])

    I also have different partitions fa when we leave home sometimes certain windows are open. They will be armed at the same way as written above

    Edited by Sjakie
  • Topic Author
  • Posted
    4 hours ago, JagarMan said:

    I have tried to handle an alarm breach occurring on exit from home but I am unable to get it to work even using the jgab supplied delayed event. Can anyone supply a working version for ER5? My idea was to disarm then retry arming (not tryArm). Logging follows:-

     

    [24.09.2024] [12:36:11] [DEBUG] [QUICKAPP128]: Time:2024-09-24T12:36:11.872061+10:00

    [24.09.2024] [12:36:11] [TRACE] [QUICKAPP128]: 'log('Time:%s',http.get('http://worldtimeapi.org/api/timezone/Australia/Sydney').datetime)' > Time:2024-09-24T12:36:11.872061+10:00 [done]

    [24.09.2024] [12:38:18] [TRACE] [QUICKAPP128]: [Rule:10:1]>> TRUE #device{id=96,valu.. -> redbutton:central.keyId==1 & redbutton..

    [24.09.2024] [12:38:18] [DEBUG] [QUICKAPP128]: ER5 redbutton was clicked 2X

    [24.09.2024] [12:38:18] [DEBUG] [QUICKAPP128]: Current profile:Home

    [24.09.2024] [12:38:18] [DEBUG] [QUICKAPP128]: ER5 The Away profile will be activated

    [24.09.2024] [12:38:22] [DEBUG] [QUICKAPP128]: ER5 About to execute tryArm

    [24.09.2024] [12:38:22] [TRACE] [QUICKAPP128]: Posting #alarm{id=0,value={11=[28]},action="tryArm",property="delayed"} at Tue Sep 24 12:38:22 2024

    [24.09.2024] [12:38:27] [TRACE] [QUICKAPP128]: [Rule:3:1]>> TRUE #alarm{id=0,value=.. -> #alarm{id='$id', property='delayed'} =..

    [24.09.2024] [12:38:27] [WARNING] [QUICKAPP128]: ER5 Partition 11 breached, devices 28

    [24.09.2024] [12:38:27] [WARNING] [QUICKAPP128]: ER5 Disarming

    [24.09.2024] [12:38:32] [WARNING] [QUICKAPP128]: ER5 Rearming

    [24.09.2024] [12:39:32] [TRACE] [QUICKAPP128]: [Rule:1:1]>> TRUE #alarm{id=11,value.. -> #alarm{id='$id', property='breached'} ..

    [24.09.2024] [12:39:32] [WARNING] [QUICKAPP128]: ER5 BREACHED partition:11

    [24.09.2024] [12:39:32] [TRACE] [QUICKAPP128]: [Rule:2:1]>> TRUE #alarm{value=true,.. -> #alarm{property='homeBreached'} => -..

    [24.09.2024] [12:39:32] [WARNING] [QUICKAPP128]: ER5 BREACHED home

    [24.09.2024] [12:39:42] [TRACE] [QUICKAPP128]: [Rule:1:2]>> TRUE #alarm{id=11,value.. -> #alarm{id='$id', property='breached'} ..

    [24.09.2024] [12:39:42] [WARNING] [QUICKAPP128]: ER5 BREACHED partition:11

    [24.09.2024] [12:39:42] [TRACE] [QUICKAPP128]: [Rule:2:2]>> TRUE #alarm{value=false.. -> #alarm{property='homeBreached'} => -..

    [24.09.2024] [12:39:42] [WARNING] [QUICKAPP128]: ER5 BREACHED home

    Can you post your rules for the arming?

    Posted

    Hi @Sjakie thanks for your reply:
     

    What cause alarm, device 28 is that a pir or radar? It is a motion sensor

    if yes should use delay to re-arm till time pir:breached change into pi:safe.

    Split arming in parts take pir's separate?

    I don't use "profile", create it by myself with Iphone. 

    rule([[{room1_pir, room2:pir, room3:pir}:safe & $location == 'Away' =>

    4:armed;

    log('Away, pir safe >> partition 4 armed')

    ]])

    I also have different partitions fa when we leave home sometimes certain windows are open. They will be armed at the same way as written above

    Posted

    Hi @jgab thanks for your reply:

     

    Cheers
    JagarMan

     

    rules follow:

     

     rule([[#alarm{id='$id', property='breached'} =>  -- Log when a partition is breached
            fibaro.warning(__TAG,efmt('ER5 BREACHED partition:%s',env.event.id))
        ]])
        rule([[#alarm{property='homeBreached'} =>   -- Log when home is breached
            fibaro.warning(__TAG,efmt('ER5 BREACHED home'))
        ]])
        -- catch an arming request and breach occurred
        rule([[#alarm{id='$id', property='delayed'} =>
            for p,d in pairs(env.event.value) do
            fibaro.warning(__TAG,efmt('ER5 Partition %s breached, devices %l',p,d))
            end;
            fibaro.warning(__TAG,efmt('ER5 Disarming'));
            0:armed=false; -- we disarm so we don't trigger an alarm...
            fibaro.sleep(5000);
            fibaro.warning(__TAG,efmt('ER5 Rearming'));
            0:armed=true
        ]])
       
        -- Trevor's rules start here
     
        -- Turn on facade light at sunset; off at 15 min before sunrise
        rule("facade:value => log('Facade:%s',facade:value)")
        rule("@sunset => facade:on")
        rule("@sunrise-00:15 => facade:off")
        -- Turn on family room lamp at 5 pm; off at 11 pm --15 min before sunrise
        rule("psocket1:value => log('Smart socket 1:%s',psocket1:value)")
        rule("@17:00 => psocket1:on")
        rule("@23:00 => psocket1:off")
        -- rule("@sunrise-00:15 => psocket1:off")
       
        -- The following is used to trigger the Advanced Presence Simulation (and the next Pressed2 will reset profile to Home thus stopping the processing)
        -- Now incorporate alarm enablement with the profile change
        rule("user=2") -- Admin user
        rule([[redbutton:central.keyId==1 & redbutton:central.keyAttribute=='Pressed2' => -- redbutton clicked twice
           local pid = fibaro.activeProfile(); -- return active profile name. Was >> QA:profileName(QA:activeProfile())
           local pName =fibaro.profileIdtoName(pid);
           local sOFF = {44};
           local sON = {45};
           log('ER5 redbutton was clicked 2X');log('Current profile:%s',pName);
           if pName == 'Home' then
             log('ER5 The Away profile will be activated');
             fibaro.activeProfile("Away");
             fibaro.sleep(3000);    --wait 3 secs
             -- execute TRYARM
             log('ER5 About to execute tryArm');
             0:tryArm;
             fibaro.sleep(5000);    --wait 5 secs
             if 0:isDisarmed == true then
             -- run ON Alarm scene after breach captured causing disarming
                log('ER5 About to execute ON Alarm');
                fibaro.scene("execute", sON)
             end
           else -- set val to 1 (Home)
            log('ER5 The Home profile will be activated');
            fibaro.activeProfile("Home");
            fibaro.sleep(3000);    --wait 3 secs
            -- run OFF Alarm scene
            log('ER5 About to execute OFF Alarm');
            fibaro.scene("execute", sOFF)
           end
        ]])
        -- log change of profile  see JGAB Tutorial entry on Posted August 12, 2022
        rule("#profile{property='activeProfile', value='$p'} => log('ER5 Profile changed to %s',QA:profileName(p))")
     
        -- Trevor's rules end here  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  • Topic Author
  • Posted
    On 9/25/2024 at 5:10 AM, JagarMan said:

     

     rule([[#alarm{id='$id', property='breached'} =>  -- Log when a partition is breached
            fibaro.warning(__TAG,efmt('ER5 BREACHED partition:%s',env.event.id))
        ]])
        rule([[#alarm{property='homeBreached'} =>   -- Log when home is breached
            fibaro.warning(__TAG,efmt('ER5 BREACHED home'))
        ]])
        -- catch an arming request and breach occurred
        rule([[#alarm{id='$id', property='delayed'} =>
            for p,d in pairs(env.event.value) do
            fibaro.warning(__TAG,efmt('ER5 Partition %s breached, devices %l',p,d))
            end;
            fibaro.warning(__TAG,efmt('ER5 Disarming'));
            0:armed=false; -- we disarm so we don't trigger an alarm...
            fibaro.sleep(5000);
            fibaro.warning(__TAG,efmt('ER5 Rearming'));
            0:armed=true
        ]])
       
       

    Ok, I looked at your rules and the general mechanism seems to work.

    You get a "delayed" event when you arm and it report the partition/device - 11/28 in your example.

    However, the 0:armed=false just disable the alarm partitions. Device 28 is still probably breached (if it's a door or window or a motion sensor with longer breach period)

    When you then after 5s do 0:armed=true you will get a breached alarm immediately.

     

    You could try to do a 0:tryArm again and it would loop with "delayed" events until the breached devices are fixed.

    Posted

    To jgab

     

    How can I clear any/all delayed breaches programmatically? I thought a disarm might do that. This is a pure motion detection not an open switch (door/window)

     

    Also how do I get the neat reply post@jgab layout that you do?

     

    Cheers
    JagarMan

  • Topic Author
  • Posted (edited)
    52 minutes ago, JagarMan said:

    To jgab

     

    How can I clear any/all delayed breaches programmatically? I thought a disarm might do that. This is a pure motion detection not an open switch (door/window)

     

    Also how do I get the neat reply post@jgab layout that you do?

     

    Cheers
    JagarMan

    On the HC3 we arm and disarm (alarm)partitions.

    Alarm partitions are pure logic constructs that contains one or more physical devices (or QAs).

    Alarm partitions can share devices.

     

    Devices (sensors) can be breached or safe - there is no command we can send to breach them or make them safe. That is controlled physically by opening/closing doors or the sensor sensing motion. (we could have a simulated sensor with a QA that we could breach but that's not the case here...)

     

    So, arming/disarming the partition does not affect the state of the device - and when you arm the partition after 5s the device/sensor is most likely still in the breached state and the partition will trigger.

     

    If you instead do a 0:tryArm and the sensor is not safe you will get a new "delayed" event if the sensor is not safe. Btw, don't use fibaro.sleep(5000) in a rule, use wait(5) instead.

    I assume the sensor turns safe after x seconds and the tryArm will eventually work without sending a "delayed" event...

    Edited by jgab
    Posted

    @jgab Hi jgab,

    Alarm is arming properly now, thank you.

    I notice an action trace in ALARMSTATUSUPDATE on console when house is armed:

    onAction: {"deviceId":118,"manual":false,"args":["status","text","Alarm set to full"],"actionName":"updateView"}
     
    How may I code a rule in ER5 to log this as a message?
     
    Cheers
    JagarMan
    Posted

    @jgab Hello Jan..Is there a way to create ER5 rule variables from a Global variable automatically? Example

     

    I have a global fibaro variable TTSDATA = {"192.168.1.225": {"name": "Business", "mac": ""},"192.168.1.239": {"name": "Kitchen", "mac": ""}}

     

    and i want to create ER5 rule variables (when ER5 starts or when the fibaro global TTSDATA changes) and have the following format

     

    rule ("Business = '192.168.1.225'"}

    rule ("Kitchen = '192.168.1.239'}

     

    So it kinda creates name-IP pairs, where name will be the ER5 variable name, and IP will be its value..

     

    Later on, whenever the TTSDATA fibaro global changes, these varibles should also get updated..

    Too complex to achieve?

  • Topic Author
  • Posted

    rule([[$TTSDATA => 

        for ip, data in pairs($TTSDATA) do

           if data.name == 'Business' then Business = ip else Kitchen = ip end

        end

    ]]).start()

    Posted (edited)
    9 minutes ago, jgab said:

    rule([[$TTSDATA => 

        for ip, data in pairs($TTSDATA) do

           if data.name == 'Business' then Business = ip else Kitchen = ip end

        end

    ]]).start()

    Oh you misundesrstood me...I want to get created these rule for every data int TTSDATA global.

     

    rule(name = ip)

     

    where name is coming from he global, an ip is the corresponding global. So we dont know the names, we cant compare them like if data.name == "Business"...

     

    the data is there, but inside ER5 i cant do the comparison, as these names are always different in different installations.

     

    This process should initialize for me all the rule(speakername = IP) rules automatically.

     

    First we always create that global table when installing and later i would install ER5,so my goal is in ER5 all these name=ip deinifitions would be defined automatically accordint to the TTSDATA global table.

     

     

    This is an exaple from one installations

     

     rule("business_speaker = '192.168.1.225'")
        rule("meeting_speaker = '192.168.1.238'")
        rule("kitchen_speaker = '192.168.1.239'")
        rule("ceo_speaker = '192.168.1.244'")
        rule("corridor_speaker1 = '192.168.1.217'")
        rule("corridor_speaker2 = '192.168.1.235'")
        rule("dining_speaker = '192.168.1.220'")
        rule("corridor_all_speakers = {'192.168.1.217','192.168.1.235'}")
        rule("wellness_speaker = '192.168.1.241'")
        rule("wellness_speaker2 = '192.168.1.216'")
     
     
    I would like to have these rules to be created according to the global TTSDATA variable.

     

    Edited by Neo Andersson

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