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
  • 2 minutes ago, Hans_Raven said:

    Is there a way to easily translate this to another z-wave remote control with multiple buttons? I have a RC-90 where each button can be given different tasks for one press, double press, and "long" press. I tried the below rule where I want to turn on a window lamp that is connected through a Fibaro wall plug. I do not get any error message so it is hard to say what is wrong...

     

     rule("Remote_entre:centralSceneEvent=='1' => Arbetsrum_fonster:on")

    The <id>:central returns the 'data' part of the CentralSceneEvent, typically {keyId=<x>, keyAttribute='attribute'}

    keyId is the number of the key and 'attribute' is usually 'Pressed', "Hold' etc.

    That's why we can test ex.

    <id>:central.keyId == 1

    or

    <id>:central.keyAttribute == 'Pressed'

     

    You can check your remote by doing

    Please login or register to see this code.

    and it will log the data structure and you can see what key values it provides.

     

    However, it may be that your remote sends "SceneActivation" events.

    In that case the rule looks like

    Please login or register to see this code.

    and the rule will log the sceneIds returned.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, michal85pl said:

    Is it possible to arm zone alarm from rule without using scene?

    rule("@00:00 => fibaro.alarm(<partition_id>, 'arm')")

    Link to comment
    Share on other sites

  • Topic Author
  • 10 hours ago, jgab said:

    Ok, I managed to trigger one.

    I have pushed v0.5fix15

    Rule

    Please login or register to see this code.

    {type='location', id=<user>, value=<"leave"/"enter">, property=<location id>}

     

    and remember to self:enableTriggerType({"location"}) 

     

    With the "new" location trigger one can do rules like this

    Please login or register to see this code.

    The set of rules keep track of the number of people at home, all, some, and none.

    It can trigger rules with the trigger variables 'allAway', 'allAtHome' and 'someAtHome'

    Now 'allAtHome' causes 'someAtHome' to trigger too - it's easy to modify if you want it exclusive.

    When the QA starts locations are unknown - need some more code to lookup current positions.

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

    6 hours ago, jgab said:

    The <id>:central returns the 'data' part of the CentralSceneEvent, typically {keyId=<x>, keyAttribute='attribute'}

    keyId is the number of the key and 'attribute' is usually 'Pressed', "Hold' etc.

    That's why we can test ex.

    <id>:central.keyId == 1

    or

    <id>:central.keyAttribute == 'Pressed'

     

    You can check your remote by doing

    Please login or register to see this code.

    and it will log the data structure and you can see what key values it provides.

     

    However, it may be that your remote sends "SceneActivation" events.

    In that case the rule looks like

    Please login or register to see this code.

    and the rule will log the sceneIds returned.

     

    Thanks for getting back so quickly. I'm a real rookie with the eventrunner so maybe I have missed something basic in the coding but I tried your proposals but nothing happens when I push the buttons on my RC-90 remote.  Maybe something completely obvious that is wrong? (I know the remote works as I have used it for activating some simple block scenes etc)

     

    --[[
    %% properties
    185 value
    %% events
    22 GeofenceEvent 220
    21 GeofenceEvent 220
    %% globals
    %% autostart 
    --]] 

    -- Don't forget to declare triggers from devices in the header!!!
    if dofile and not _EMULATED then _EMULATED={name="EventRunner", id=10} dofile("HC2.lua") end

    _version,_fix = "2.0","B66"  -- July 29, 2019  

    --[[
    -- EventRunner. Event based scheduler/device trigger handler
    -- Copyright 2019 Jan Gabrielsson. All Rights Reserved.
    -- Email: [email protected]
    --]]

    _sceneName   = "Demo"      -- Set to scene/script name
    _homeTable   = "devicemap" -- Name of your HomeTable variable (fibaro global)
    _HueHubs     = {}          -- Hue bridges, Ex. {{name='Hue',user=_HueUserName,ip=_HueIP}}
    _myNodeRed   = "http://192.168.1.50:1880/eventrunner" -- Ex. used for Event.postRemote(_myNodeRed,{type='test'})
    --if dofile then dofile("credentials.lua") end -- To not accidently commit credentials to Github, or post at forum :-)
    -- E.g. Hue user names, icloud passwords etc. HC2 credentials is set from HC2.lua, but can use same file.

    -- debug flags for various subsystems...
    _debugFlags = { 
      post=true,invoke=false,triggers=true,dailys=false,rule=true,ruleTrue=false,hue=false,msgTime=false,
      fcall=true, fglobal=false, fget=true, fother=true
    }

    ---------------- Here you place rules and user code, called once at startup --------------------
    function main()
      local rule = Rule.eval

      local HT =   {                    -- Define your devices
        kontakt = 185,                    --Virtual device home_away arbrum
        
        Spots_entre = 7,                --Takspotlights entréhallen
        Remote_entre = 187,                --Fjärrkontroll entréhallen
        
        Gymnastikrum_tak = 12,
        Home_away_switch = 174,            --Fysisk hemma_borta-brytare
        
        Sovrum_vuxna_tak = 22,            --Taklampa föräldrasovrum
        Sovrum_vuxna_fonster = 124,        --Fönsterlampa föräldrasovrum
        
        Dressing_room = 27,             --Klädkammare sovrum
        
        Sovrum_barn = 32,                --Taklampa barnsovrum
        Sovrum_barn_fonster = 126,        --Fönsterlampa barnsovrum
        
        Badrum_spots = 37, 
        Badrum_spegel = 42,
        Badrum_Sonos = 133,
        
        Tvattstuga_spots = 52,
        Tvattstuga_bank = 47,
        Tvattstuga_rorelse = 164, 
        Tvattstuga_temp = 165,
        Tvattstuga_lux = 166,
        
        Hall_uppe_tak = 57,
        
        Vardagsrum_tak_kamin = 62,
        Vardagsrum_tak_soffa = 67,
        Vardagsrum_fonster_gavel = 130,
        Vardagsrum_fonster_balkong = 116,
        
        Koksbord = 77,
        Kok_tak = 87,
        Kok_fonster_gata = 122, 
        Kok_fonster_gavel = 120,
        
        Matsal_tak = 82,
        Matsal_fonster = 147, 
        Matsal_skap = 110,
        
        WC_tak = 92,
        WC_spegel = 93,
        
        Arbetsrum_tak = 97,
        Arbetsrum_fonster = 114,
        
        Fasad_entre = 17,
        Fasad_garage = 108,
        Fasad_uterum = 102,
        Fasad_balkong = 72,
        Fasad_forrad = 138,
        PIR = 103,                            --Strålkastare fasad
        
        Garage_inne = 107,
        Garage_temp = 156,
        Garage_rorelse = 155,
        Garage_lux = 157,
        Forrad_inne = 139
          
        
      }

      Util.defvars(HT)                -- Make HomeTable variables available in EventScript
      Util.reverseMapDef(HT)     -- Make HomeTable variable names available for logger

      rule("kontakt:isOff => $Home_Away='Away' ")
      rule("kontakt:isOn => $Home_Away='Home' ")
        
      rule("@22:18 & $Home_Away=='Away' => Arbetsrum_fonster:off")
      rule("@22:19 & $Home_Away=='Away' => Arbetsrum_fonster:on")
      
      rule("@22:18 & $Home_Away=='Home' => Arbetsrum_fonster:off")
      rule("@22:19 & $Home_Away=='Home' => Arbetsrum_fonster:on")
      
      rule("Remote_entre:central.keyID=='1' & keyAttribute=='Pressed' => Arbetsrum_fonster:on")
      rule("Remote_entre:scene=='1' & keyAttribute=='Pressed' => Arbetsrum_fonster:on")
      
      rule("Remote_entre:central => log('Remote:%s',Remote_entre:central)")
      rule("Remote_entre:scene => log('Remote:%s',Remote_entre:scene)")
      
      
      
        
        
    end

     

    Link to comment
    Share on other sites

  • Topic Author
  • Ok, so you are on the HC2?

    You need to declare the trigger in the header

    Please login or register to see this code.

    Be careful with the capitalisation 

    Please login or register to see this code.

    If it happens to be a sceneActivation it's under properties

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Yes, I run it on my HC2 as I'm not authorized to install software on my employer's laptop. It is in my pipeline to install the offline scene emulator on my old and slow Mac Mini but it hasn't happened yet. 

     

    Thanks for the input! Now I'm able to read the code when I push the buttons on the remote but I'm still not able to turn on a light (wallplug) with rule #7. I'm aware that the rule doesn't seem to be complete (ends with an "o") when you read the debug but I double checked the code and it is and goes like this: 

     

    rule("Remote_entre:central.keyId=='1' & keyAttribute=='Pressed' => Arbetsrum_fonster:on"

     

    I also tried to turn on another wallplug and I get same error message. 

    ----------

    Please login or register to see this link.

    [DEBUG] 22:48:35: Demo - EventRunner v2.0 B66
    [DEBUG] 22:48:35: Fibaro software version: 4.600
    [DEBUG] 22:48:35: HC2 uptime: 311 hours
    [DEBUG] 22:48:35: fibaro:getValue(1,"sunriseHour")="06:06"
    [DEBUG] 22:48:35: fibaro:getValue(1,"sunsetHour")="19:22"
    [DEBUG] 22:48:35: Sunrise 06:06, Sunset 19:22
    [DEBUG] 22:48:35: Hue system inited (experimental)
    [DEBUG] 22:48:35:
    [DEBUG] 22:48:35: Loading rules
    [DEBUG] 22:48:35: Rule:1:kontakt:isOff => $Home_Away='Away'
    [DEBUG] 22:48:35: Rule:2:kontakt:isOn => $Home_Away='Home'
    [DEBUG] 22:48:35: Rule:3:@22:18 & $Home_Away=='Away' => Arbetsrum_fonster:off
    [DEBUG] 22:48:35: Rule:4:@22:19 & $Home_Away=='Away' => Arbetsrum_fonster:on
    [DEBUG] 22:48:35: Rule:5:@22:18 & $Home_Away=='Home' => Arbetsrum_fonster:off
    [DEBUG] 22:48:35: Rule:6:@22:19 & $Home_Away=='Home' => Arbetsrum_fonster:on
    [DEBUG] 22:48:35: Rule:7:Remote_entre:central.keyId=='1' & keyAttribute=='Pressed' => Arbetsrum_fonster:o
    [DEBUG] 22:48:35: Rule:8:Remote_entre:central => log('Remote:%s',Remote_entre:central)
    [DEBUG] 22:48:35:
    [DEBUG] 22:48:35: Scene running

    [DEBUG] 22:48:50: Incoming event:{"type":"event","event":{"type":"CentralSceneEvent","data":{"icon":{},"deviceId":187,"keyId":1,"keyAttribute":"Pressed"}}}
    [DEBUG] 22:48:50: [false]>>'Remote_entre:central.keyId=='1' & keyAttribute=='Pressed' => Arbetsrum_fonster:on'
    [DEBUG] 22:48:50: [{"icon":{},"keyAttribute":"Pressed","keyId":1,"deviceId":187,"timestamp":1599770930}]>>'Remote_entre:central => log('Remote:%s',Remote_entre:central)'

    [DEBUG] 22:48:50: Remote:table: 0x8bc8c08
    ----------

    Link to comment
    Share on other sites

  • Topic Author
  • 10 hours ago, Hans_Raven said:

    Yes, I run it on my HC2 as I'm not authorized to install software on my employer's laptop. It is in my pipeline to install the offline scene emulator on my old and slow Mac Mini but it hasn't happened yet. 

     

    Thanks for the input! Now I'm able to read the code when I push the buttons on the remote but I'm still not able to turn on a light (wallplug) with rule #7. I'm aware that the rule doesn't seem to be complete (ends with an "o") when you read the debug but I double checked the code and it is and goes like this: 

     

    rule("Remote_entre:central.keyId=='1' & keyAttribute=='Pressed' => Arbetsrum_fonster:on"

     

    I also tried to turn on another wallplug and I get same error message. 


    [DEBUG] 22:48:50: Incoming event:{"type":"event","event":{"type":"CentralSceneEvent","data":{"icon":{},"deviceId":187,"keyId":1,"keyAttribute":"Pressed"}}}
    [DEBUG] 22:48:50: [false]>>'Remote_entre:central.keyId=='1' & keyAttribute=='Pressed' => Arbetsrum_fonster:on'
    [DEBUG] 22:48:50: [{"icon":{},"keyAttribute":"Pressed","keyId":1,"deviceId":187,"timestamp":1599770930}]>>'Remote_entre:central => log('Remote:%s',Remote_entre:central)'

    [DEBUG] 22:48:50: Remote:table: 0x8bc8c08
    ----------

    Sorry, to log a table in a readable format you need to trosform it to a json string

    log('Remote:%s',tjson(Remote_entre:central))

    'tjson' is the same function as json.encode, just shorter to write.

     

    However, you do see that the incoming trigger is a CentralsSceneEvent and the keyId is 1 and the keyAttribute is "Pressed".

    The only problem is the rule now.

    Please login or register to see this code.

    You need to test against the value returned from Remote_entre:central

    You could assign it a local variable

    Please login or register to see this code.

    ...but I'm not sure it looks better.

     

    What I would recommend is to let the different keys post events. (ex. REPressed Remote Entre Pressed)

    Please login or register to see this code.

    Ex.

    Please login or register to see this code.

       

    Edited by jgab
    Link to comment
    Share on other sites

    Hmm, feel like an idiot here (I actually manage to write some code in R at work) but I'm not getting this to work...

     

    Please login or register to see this code.

    The above rule doesn't work, I inserted the second and last " but that didn't help. It give this error message when I run it so I guess there is just some basic sign missing in the code:  

    Please login or register to see this code.

     

     

    Please login or register to see this code.

    The above is ok to run but when I push 1-key on the remote I get this log. What does that "attempting to index non table with key:'keyId' mean? 

    Please login or register to see this code.

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 30 minutes ago, Hans_Raven said:

    Hmm, feel like an idiot here (I actually manage to write some code in R at work) but I'm not getting this to work...

    Please login or register to see this code.

     

     

    Missing parentheses at the end

    Please login or register to see this code.

     

    30 minutes ago, Hans_Raven said:

     

    Please login or register to see this code.

    The above is ok to run but when I push 1-key on the remote I get this log. What does that "attempting to index non table with key:'keyId' mean? 

     

    index non table means that you do x.y where x is not a table. In this case csl. Because you assign cs, not csl at the start

    Please login or register to see this code.

    You should test against 1 and not '1' as the keyId value in the CS event is a number.

     

    Link to comment
    Share on other sites

    Thanks for helping out, much appreciated and the parenthesis issue I should have spotted myself. The other part, despite your proposed corrections, still cause a problem (Rule 8 is complete and ends with Arbetsrum_fonster:on")

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • It was my fault. Assignment (=) has a lower priority than ‘and’ (&), like in most programming languages. Thus you need to put a parenthesis around it.

    Please login or register to see this code.

    Link to comment
    Share on other sites

  • Topic Author
  • On 9/11/2020 at 8:16 AM, jgab said:

    What I would recommend is to let the different keys post events. (ex. REPressed Remote Entre Pressed)

    Please login or register to see this code.

     

     

    So, remotes with keys can be used in various ways

    Please login or register to see this code.

    The above example listens for a code (1-3-2-4) and if input in right order and less than 2s in-between it will post an #codeOK event that can trigger some action
     

    I have a keyfob with 6 buttons but I like to assign more functions. These simple rules concatenates two keypresses into a two-key code that is posted.

    Ex. #Key1_1  or #Key_4_1

    The keys needs to be pressed within 2s to count as a double code

    This way I have 36 buttons...

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • So, continuing with the key events in the previous post.

     

    One way to structure the rules in EventRunner is to think in "events".

    Actions that causes events to be posted, and actions that are carried out when the events are posted.

     

    Ex. assume you have a time in the evening when you turn on some lights. Like at sunset. (and the reverse at sunrise) One way to do that is

    Please login or register to see this code.

    A better way is to split it up.

    Define an event, #turnOnLights and create rule that trigger on sunset and post the event. Then another rule that carries out the action when it sees the event.

    Please login or register to see this code.

    It has the same effect but now you can turn on the lights with other actions also.

    Please login or register to see this code.

    Now when we come home before sunset and it's a bit dark we can turn on the light with our remote also.

    ...and we could have a fire alarm that also post #turnOnLights etc.

     

    So our rule becomes subroutines that can be triggered by posting events. (and events can carry arguments too, like #myEvent{value=42} )

    So, think in "events" :-) 

    Edited by jgab
    Link to comment
    Share on other sites

    Hello. I am using ER4 well. I would like to provide additional comments.

     

    I wish there was a restart button for ER4 and an update confirmation button (or automatic update on-off button, etc.) on the preview screen of ER4. It looks like a good test for home center errors (or other checks).

    Link to comment
    Share on other sites

  • Topic Author
  • Some more use-cases for new comers to  ER.

     

    1. Turn off light in a room after x minutes of inactivity

    Please login or register to see this code.

    many sensors and many lights

    Please login or register to see this code.

     

    2. Turn on light decided by current lux or level decided by time or ...

    Please login or register to see this code.

    many lux sensors

    Please login or register to see this code.

    light level depending on time

    Please login or register to see this code.

     

    3. Remind me of an open window

    Please login or register to see this code.

     

    4. Randomly turn on lights from a list of lights when global variable 'Away' is set to "true"

    Please login or register to see this code.

    (this could be made more intelligently but works as a simple case...)

     

    Edited by jgab
    Link to comment
    Share on other sites

    Hi @jgab , I discovered your brilliant Eventrunner4 for myself and have a question right away.
    Is it possible to give a rule a random value?
    for example:

    Please login or register to see this code.

    I use the random values for all of my outdoor lights and shutters. So that nobody recognizes an automatism behind it.
    Thanks for this great job.

    Link to comment
    Share on other sites

  • Topic Author
  • 11 hours ago, jwi said:

    Hi @jgab , I discovered your brilliant Eventrunner4 for myself and have a question right away.
    Is it possible to give a rule a random value?
    for example:

    Please login or register to see this code.

    I use the random values for all of my outdoor lights and shutters. So that nobody recognizes an automatism behind it.
    Thanks for this great job.

     

    Please login or register to see this code.

    Time constants HH:MM(:SS) ex. 10:15 or 10:15:30 is translated to numbers representing the seconds.

    Ex. 10:15 is 3600*10+60*15,  10:15:30 is 3600*10+60*15+30

    This allows us to do arithmetic with time constants as they are treated as numbers by the rules.

    'sunset' in rules is a variable that is set to the current day's sunset time ex. 20:00 (the variable is updated every midnight)

    So this allows us to add offsets to ex. sunset.

     In your example (besides missing the +) it would only randomise -10s to +15s and 5s to 20s

    The time scheduling function '@<expr>' schedules the rule <expr> seconds after midnight - so that's how it works.

    This means that we can also use a fibaro global (or any expression that calculates a valid number)

    Please login or register to see this code.

    assuming that the fibaro global contains a number with seconds after midnight. In fact, when accessing a fibaro global and the content is a string that looks like a time constants (HH:MM(:SS)) it is automatically translated to a number when accessed. So we can set the fibaro global MORNING to the string ex. "07:00" and it works too.

    (another trick here is that if the global changes value the rule is re-scheduled to take into account the global's new value)

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

    1 hour ago, jgab said:

    Please login or register to see this code.

    assuming that the fibaro global contains a number with seconds after midnight. In fact, when accessing a fibaro global and the content is a string that looks like a time constants (HH:MM(:SS)) it is automatically translated to a number when accessed. So we can set the fibaro global MORNING to the string ex. "07:00" and it works too.

     

    Thanks @jgab , that sounds good, I'll try

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