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
  • The checkLocations handler was buggy. This should work better

    Please login or register to see this code.

    The bank holidays I would make a Lua function called from the rule

    Please login or register to see this code.

    or populate the table from some online calendar service...

    Edited by jgab
    Link to comment
    Share on other sites

    14 minutes ago, jgab said:

    The checkLocations handler was buggy. This should work better

    No. First missing ) after last end, but still error

     

    Please login or register to see this code.

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, jompa68 said:

    No. First missing ) after last end, but still error

     

    Please login or register to see this code.

     

    Fixed in post - it was 'end)' missing. Missed when cutting&pasting

    Edited by jgab
    Link to comment
    Share on other sites

    41 minutes ago, jgab said:

    or populate the table from some online calendar service...

    Yes, i have json with all holidays so i will use that.

    your function for BankDays is wrong

    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, jompa68 said:

    Yes, i have json with all holidays so i will use that.

    your function for BankDays is wrong

    fixed.

    Link to comment
    Share on other sites

    need some help with my code..

    thought it should show that it is BankHoliday today.

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 15 minutes ago, jompa68 said:

    need some help with my code..

    thought it should show that it is BankHoliday today.

    Please login or register to see this code.

     

    On the subway now so can’t code...

    however, after JSON decoding the table, make a new table with

    BankDays2={}

    for k,v in pairs(BankDays) do

      BankDays2[osDate(‘%x’,v)]=k

    end

    ...then you can look it up like the function I showed, but with BankDays2. And you don’t have look through the table every time 

      

    Link to comment
    Share on other sites

    Perfect! Thanks for your help

    here is the code for bankHoliday. This will work together with scene "

    Please login or register to see this link.

    "

     

    Please login or register to see this code.

     

    Edited by jompa68
    lift out bankdays2 from function
    Link to comment
    Share on other sites

  • Topic Author
  • 22 hours ago, jompa68 said:

    Perfect! Thanks for your help

    here is the code for bankHoliday. This will work together with scene "

    Please login or register to see this link.

    "

     

    Please login or register to see this code.

     

    Ok, you can lift out the loop making BankDays2 outside the bankholidays() function as it it is only needed to create it once.

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    Jan

     

    Finally made some time to play around more.  Hats off - it is fantastic.

     

    What am I missing here ...

     

    Please login or register to see this code.

    The last lines x2 are my attempt a simply switching on towel radiator if GuestMode is set at 06:30am.  
     

    gives me error "can't assign a variable in rule header".
     

    Please login or register to see this code.

     

    It must be something simple but I cannot spot it!

     

    Otherwise really enjoying trying to make the switch to this programming model - your script is functionally rich and your support and productivity to the community outstanding.  Thanks

    Link to comment
    Share on other sites

  • Topic Author
  • 6 minutes ago, ipsofacto said:

    Jan

     

    Finally made some time to play around more.  Hats off - it is fantastic.

     

    What am I missing here ...

     

    Please login or register to see this code.

    The last lines x2 are my attempt a simply switching on towel radiator if GuestMode is set at 06:30am.  
     

    gives me error "can't assign a variable in rule header".
     

    Please login or register to see this code.

     

    It must be something simple but I cannot spot it!

     

    Otherwise really enjoying trying to make the switch to this programming model - your script is functionally rich and your support and productivity to the community outstanding.  Thanks

    So, there can't be any assignments on the left hand of the '=>'. But maybe you wanted to test if GuestMode equals "Guests"?

    Then it is '=='

    Please login or register to see this code.

    The rule before has '||' that doesn't work. '||' is part of '|| <test> >> <actions' syntax only allowed on the right hand side of a rule.

    The 'OR' operations is a single bar '|', but doesn't make sense for that rule either.

    So, left hand side of '=>' should only be tests, and logical combinations of tests, and no side effects (assigning variables)

     

    Link to comment
    Share on other sites

  • Topic Author
  • Just now, ipsofacto said:

    I am a donkey! 

     

     == is the blindingly obvious answer. 

     

    I could not see for looking.  thanks!

    No problem, I've been there too.

    I'm happy to help you get going with this so please ask if you run into something you think is difficult to express with the rules. 

    Btw, I really recommend trying to set it up in ZeroBrane to test offline if you haven't already managed to do that.

     

    Link to comment
    Share on other sites

    I have been amusing myself with simple time-based rules to phase out older lua/block scenes.  It has been going well until I tripped over ==!    I have been doing this directly but do have zerobrane in mind - I've studied your posts and will switch.

     

    Something I was building up to ...  any recommendations on if/whether/how this should be addressed in event runner mode?

     

    I have a extended data structure in some rooms that holds a weekly alarm schedule.  It is managed by a VD.  It looks something like this.

     

    Please login or register to see this code.

    I have not yet managed to get sufficiently up to speed to work out the best way to create/manage/update a set of event runner rules that would at the setTime trigger the required action; lights, sonos etc. as an alarm.   I could see my way to setting them up for each day of the week from the HomeTable.<Room>.AlarmClock.<Day> when active but not sure how to trap/recreate when the user changes them in the VD.   VD is generic and picks up which room it is in to update HomeTable.<Room>.

     

    Any guidance?

     

    UPDATE.

     

    OK.  I just spent the 15mins to  transfer my hobbyist workflow to ZeroBrane with Jan's event runner scripts.    Working offline is a massive advantage!   Thanks Jan.

     

    Anyone looking at Jan's work,   who has not taken the time to set up ZeroBrane and remote/simulation options ... do it as step 1.  Once you get the hang of that running to simulate HC2 is fantastic ... being able to switch over an run remotely by API is even better.

     

    Thanks Jan.

    Edited by ipsofacto
    Link to comment
    Share on other sites

  • Topic Author
  • 7 hours ago, ipsofacto said:

    OK.  I just spent the 15mins to  transfer my hobbyist workflow to ZeroBrane with Jan's event runner scripts.    Working offline is a massive advantage!   Thanks Jan.

     

    Anyone looking at Jan's work,   who has not taken the time to set up ZeroBrane and remote/simulation options ... do it as step 1.  Once you get the hang of that running to simulate HC2 is fantastic ... being able to switch over an run remotely by API is even better.

     

    Thanks Jan.

    Thanks!.

    I would code it like this - you have to adapt to your specific home table.

    Please login or register to see this code.

    The tricky part is that you want to recalculate the alarms when the hometable changes. 

    The other thing is to cancel eventual timers (alarm events) that is not executed yet when you recalculate the alarms. So we save all the references to the 'posts' we do so that we can cancel them when recalculating (it's no problem to cancel a timer that already has expired). On the HC2 these translate to 'setTimeout' and 'clearTimeout' and is pretty efficient.

    And you recalculate the alarms every midnight to see if it is the right day and then post the alarm.

     

    Then you can easily write AlarmClock rules do do whatever action you need.

    Edited by jgab
    Forgot to read in hometable again in setUpAlarms
    Link to comment
    Share on other sites

    Jan.

     

    wow.  Great response.  I think I get it.   I am out  of time this evening but will be trying this out later in the week.  It would have taken me  lots of trail and error to get here without your help.

    Link to comment
    Share on other sites

  • Topic Author
  • 8 hours ago, ipsofacto said:

    Jan.

     

    wow.  Great response.  I think I get it.   I am out  of time this evening but will be trying this out later in the week.  It would have taken me  lots of trail and error to get here without your help.

    The example I gave uses the feature to post an event into the future, and at midnight we post the events for that day. This is very efficient as it uses setTimeout but the drawback is the complexity to remember the posts/timers we have done to be able to cancel them if the alarm definitions changes.

    Another approach is to run a loop every minute to check if any alarm should be posted immediatly. It may not be as efficient if we have a lot of alarms, but It's still quite ok to do so. The code becomes a little bit easier. However, the loop that checks alarms "@@00:01 => checkAlarms()" will run every minute (without time drift), but we need to make sure that the rule starts on the minute. That can be accomplished with a sleep, but that will delay the setup of the rest of the rules - or better using a post as in the example.

    The advantage here is that we can change the HomeTable anytime, just make sure that we update the HT variable with the latest version. We do that here with a Lua event handler triggering on the global HomeTable changing value, and decode the json and set the HT variable. We can't use an EventScript rule for that because we can't assign global Lua variables from an EventScript rule (in the previous example I cheated by calling 'decodeHomeTable()' )

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Jan

     

    Having a quick go with the more purist "first version" - it feels more elegant and efficient despite the timers{} cancel step.   

     

    A quick question.  When running in ZeroBrane in offline mode,  how are global variables set/defined?  Asking as I had decided to make Alarms a global separate from HomeTable which I understand you read in if offline from <device>.data i.e. hometable.data in working directory.     

     

    Is there a mechanism baked in for define values of other GV ?   Just a question about good development workflow with zerobrane really I guess!

     

    Edited by ipsofacto
    Link to comment
    Share on other sites

  • Topic Author
  • 15 hours ago, ipsofacto said:

    Jan

     

    Having a quick go with the more purist "first version" - it feels more elegant and efficient despite the timers{} cancel step.   

     

    A quick question.  When running in ZeroBrane in offline mode,  how are global variables set/defined?  Asking as I had decided to make Alarms a global separate from HomeTable which I understand you read in if offline from <device>.data i.e. hometable.data in working directory.     

     

    Is there a mechanism baked in for define values of other GV ?   Just a question about good development workflow with zerobrane really I guess!

     

    Hadn't thought about that (I tend to avoid fibaro globals).

    One way is to set them in the beginning of the code like

    Please login or register to see this code.

    However, the problem is that this triggers a fibaro event that the global has changed value and that may interfere with your code.

    I will add a function that allows to setup globals (or maybe another initfile for them).

    However, meanwhile you can do this

    Please login or register to see this code.

    This will initialize the globals without generating events.

    One way top get a "workflow" is to create your own initialisation file for the scene/project you are working on

    Please login or register to see this code.

    and then in the mysetup.lua file you can set all the stuff you need, including triggering events to test the logic.

    Please login or register to see this code.

     

    Edited by jgab
    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...