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)
    6 minutes ago, Neo Andersson said:

     

     

    OKay, this would work if

     

    1. daypart names equals to night and day

    2. Are you sure, i can call this led.data[dp].color as dp is a string from global variable while in the rule it is not...or is it?

     

    Sorry, i can't do too much tests, so i rather 100 times ask before uploading anything, becasue every single time i save the QA i need to restart HC3 because of those ghost processes..really hard to work this way, mostly on customers systems..so i have to ask 100 times

    Note , there should not be a ';' after  (fixed in earlier post)

    Please login or register to see this code.

     

    1. Yes the names needs to be the same or you have some way to convert dayPart to key

    2. Yes dp is set to $dayPart and then used as key (if dayPart has no value it is set to "" to not crash the logic. But dayPart/dp must be the same as the key in led.data

    Edited by jgab
    Posted
    On 12/28/2023 at 8:40 AM, ChristianSogaard said:

    Hei Jan

    (contactSpec | $DayControl) == 'Wake-up' 

    This is an OR rule, right ? contactSpec OR $DayControl == Wake-up ?

    I understand the triggervar the .start() ect but not the When the variable 'contactSpec' is set to a value it overrides what DayControl is set to.

     

    if rule([[(contactSpec | $DayControl) run at 0800 because $DayContro is triggered and contactSpec = CO2 then both are true, right , but only equal to one thing ? - that will not be an overrride, 

     

     

     

       

    Hi Jan

    i see these two functions.

    • table.insert(table ,position,value)
    • table.remove(table ,position)

    the numbers is below structure only have unique numbers, in rooms, baths and common.

    How can i move eg 103 from rooms.rooms to rooms.baths ? and later back again ?

     

    I can use the table.insert because the position dont mean anything and it can be first in the table, but how do i delete the 103 when i dont the the position ?  

     

     

    Please login or register to see this code.

     

    Posted
    7 minutes ago, Neo Andersson said:

     

     

    OKay, this would work if

     

    1. daypart names equals to night and day

    2. Are you sure, i can call this led.data[dp].color as dp is a string from global variable while in the rule it is not...or is it?

     

    Sorry, i can't do too much tests, so i rather 100 times ask before uploading anything, becasue every single time i save the QA i need to restart HC3 because of those ghost processes..really hard to work this way, mostly on customers systems..so i have to ask 100 times

    Jan, last question to this..if i set an element in HT table like this

     

    Please login or register to see this code.

    can i call this device later in rules like Kitchen_led:id:on?

  • Topic Author
  • Posted

    So, now you need to re-save the QA when you update the rules, and possibly create a ghost.... because the rules resides in a file in the ER5 QA.

     

    Maybe you could read in the rules from a file in another QA - they are just strings...?

    Then the QA would not need to be re-saved when rules are updated, only when new Lua code is updated/added.

    Just a thought...

    Posted (edited)
    4 minutes ago, Neo Andersson said:

    Jan, last question to this..if i set an element in HT table like this

     

    Please login or register to see this code.

    can i call this device later in rules like Kitchen_led:id:on?

    I guess that would fail, but perhaps use :leafs that takes an arbitrary complex key-value table and returns a list with the leafs (removing duplets)

    rule(" => kitchen.led:leaf:on")

    Copied from one of the other posts

    Edited by ChristianSogaard
    Typo
  • Topic Author
  • Posted
    5 minutes ago, Neo Andersson said:

    Jan, last question to this..if i set an element in HT table like this

     

    Please login or register to see this code.

    can i call this device later in rules like Kitchen_led:id:on?

     Kitchen_led.id:on

     

    .id as id is a key in the table

    2 minutes ago, ChristianSogaard said:

    I guess that would fail, but perhaps use :leafs that takes an arbitrary complex key-value table and returns a list with the leafs (removing duplets)

    rule(" => kitchen.led:leaf:on")

    Copied from one of the other posts

    Unfortunately it would return the colors and values too - and they can't be turned on...

    • Like 1
    Posted

    Jan - can you add table.indexOf command into EV5 ?

    Please login or register to see this code.

     

  • Topic Author
  • Posted (edited)
    15 minutes ago, ChristianSogaard said:

    Jan - can you add table.indexOf command into EV5 ?

    Please login or register to see this code.

     

    It's already there but is called member and the arguments are switched

    Ex.

    Please login or register to see this code.

     

    returns nil/false if it's not a member, otherwise the number index

    3 minutes ago, jgab said:

    It's already there but is called member and the arguments are switched

    Ex.

    Please login or register to see this code.

     

    returns nil/false if it's not a member, otherwise the number index

    table.delete(item, tab) removes the first item in table if it exists

    It's defined as 

    local idx = table.member(item, tab); if idx then table.remove(tab, idx) end

    Edited by jgab
    • Thanks 1
  • Topic Author
  • Posted (edited)

    Here is a simple holidays checker for ER5

     

    Please login or register to see this code.

     

    Every night it fetches the holidays and creates a table holidays with { date1 = data, date2 = data, ...}

    and sets holidays.today to todays holiday (if any) or nil

    It uses 

    Please login or register to see this link.

    so you need to set the country code in the URL to your country

    It also sets types to true for the types field in the returned result.

    The available types are

     

    The types of the public holiday, several possible

    • Public
    • Bank (Bank holiday, banks and offices are closed)
    • School (School holiday, schools are closed)
    • Authorities (Authorities are closed)
    • Optional (Majority of people take a day off)
    • Observance (Optional festivity, no paid day off)

     

    we can do rules like

    Please login or register to see this code.

    to not turn on lights too early on holidays... 

     

    Edited by jgab
    • Thanks 1
    Posted (edited)

    @jgab

    Jan is there a way to define a virtual switch, that can be turned on / off ? Kinda LUA global boolean, that can be a rule action triggered upon?

     

    like

     

    myVirtualSwitch:isOn => doSomething

     

    i think among those thousands of lines in this topic i saw something like trigerVAR

     

    Edited by Neo Andersson
  • Topic Author
  • Posted

    Yes a triggerVar is a rule variable that also works as a trigger, and trigger rules when it changes value.

    Please login or register to see this code.

     

    Like other rule variables they don't keep their states when the QA restarts.

  • Topic Author
  • Posted

    Ex. to test a time rule you can do

    Please login or register to see this code.

     

    If it's just for testing one can also do

    Please login or register to see this code.

    It sets the "virtual time" of ER5 to 09:59:58 in this case and then the rule will trigger 2s later.

    Posted
    58 minutes ago, jgab said:

    Here is a simple holidays checker for ER5

     

    Please login or register to see this code.

     

    Every night it fetches the holidays and creates a table holidays with { date1 = data, date2 = data, ...}

    and sets holidays.today to todays holiday (if any) or nil

    It uses 

    Please login or register to see this link.

    so you need to set the country code in the URL to your country

    It also sets types to true for the types field in the returned result.

    The available types are

     

    The types of the public holiday, several possible

    • Public
    • Bank (Bank holiday, banks and offices are closed)
    • School (School holiday, schools are closed)
    • Authorities (Authorities are closed)
    • Optional (Majority of people take a day off)
    • Observance (Optional festivity, no paid day off)

     

    we can do rules like

    Please login or register to see this code.

    to not turn on lights too early on holidays... 

     

    Great idea - and thank you for providing.

    I did a copy/paste into EV5 - and getting Runtime: calling 'mapHolidays' - attempt to index a nil value.

    Something i missed?

     

    [Rule:1:1]>> [Rule:1:@00:00 => holidays = mapHolidays(http.get(fmt('https://date.nager.at/api/v3/PublicHolidays/%s/SE',os.date('*t').year)))] Runtime: calling 'mapHolidays' - attempt to index a nil value
    @00:00 => holidays = mapHolidays(http.get(fmt('https://date.nager.at/api/v3/PublicHolidays/%s/SE',os.date('*t').year)))
                         ^^^^^^^^^^^

     

     

     

    Posted

    @jgabJan, i want to simplify my code, becuase i have some lon long tables that keep up so much line, that i would like to define them in a separate function, and just call it when creating rules.

     

     

    Please login or register to see this code.

     

    i would like to create a separate function for this table definition, and just call it in one line among other rules. Question is, can a create a function ex. setUpbdtTable() that will be defined in a different file of my QA and just call it among rules? Like

     

    Please login or register to see this code.

     

     

     

  • Topic Author
  • Posted
    24 minutes ago, ChristianSogaard said:

    Great idea - and thank you for providing.

    I did a copy/paste into EV5 - and getting Runtime: calling 'mapHolidays' - attempt to index a nil value.

    Something i missed?

     

    [Rule:1:1]>> [Rule:1:@00:00 => holidays = mapHolidays(http.get(fmt('https://date.nager.at/api/v3/PublicHolidays/%s/SE',os.date('*t').year)))] Runtime: calling 'mapHolidays' - attempt to index a nil value
    @00:00 => holidays = mapHolidays(http.get(fmt('https://date.nager.at/api/v3/PublicHolidays/%s/SE',os.date('*t').year)))
                         ^^^^^^^^^^^

    Yep, doesn't seem to work on the HC3 with https - will come back to this....

    9 minutes ago, Neo Andersson said:

    @jgabJan, i want to simplify my code, becuase i have some lon long tables that keep up so much line, that i would like to define them in a separate function, and just call it when creating rules.

     

     

    Please login or register to see this code.

     

    i would like to create a separate function for this table definition, and just call it in one line among other rules. Question is, can a create a function ex. setUpbdtTable() that will be defined in a different file of my QA and just call it among rules? Like

     

    Please login or register to see this code.

     

    Yes, that should work.

  • Topic Author
  • Posted (edited)

    Here is a simple QA

    Please login or register to see this code.

    It keeps a table of ER rules and assigns a global variable 'ER5rules' the table.

    A little like the principle with keeping a HT table...

     

    Then in ER5 we do

    Please login or register to see this code.

     

    Just to avoid having to re-save the QA....

    Edited by jgab
  • Topic Author
  • Posted
    1 hour ago, ChristianSogaard said:

    Great idea - and thank you for providing.

    I did a copy/paste into EV5 - and getting Runtime: calling 'mapHolidays' - attempt to index a nil value.

    Something i missed?

     

    [Rule:1:1]>> [Rule:1:@00:00 => holidays = mapHolidays(http.get(fmt('https://date.nager.at/api/v3/PublicHolidays/%s/SE',os.date('*t').year)))] Runtime: calling 'mapHolidays' - attempt to index a nil value
    @00:00 => holidays = mapHolidays(http.get(fmt('https://date.nager.at/api/v3/PublicHolidays/%s/SE',os.date('*t').year)))
                         ^^^^^^^^^^^

    Ok, have a fix for next version. Turned out that http.get always set checkCertificate=false but it shouldn't do that.

    In particular it didn't work with this site.

    In next version checkCertificate is an option to http.get.

    Posted
    5 hours ago, jgab said:

    Note , there should not be a ';' after  (fixed in earlier post)

    Please login or register to see this code.

     

    1. Yes the names needs to be the same or you have some way to convert dayPart to key

    2. Yes dp is set to $dayPart and then used as key (if dayPart has no value it is set to "" to not crash the logic. But dayPart/dp must be the same as the key in led.data

    Unofrtunatelly this approach is not suitable, becasue setting the value of a LED will actually turn it on..We dont want to turn them on, we just want ensure, that according to a daypart, when some led gets turned on by a user, or by some code, its brightness and color will correspond with those values set in their data..

    Kinda tricky one, but will grind my mind further to find a simple solution, and not write hundrds of lines.. 

     

  • Topic Author
  • Posted
    1 hour ago, Neo Andersson said:

    Unofrtunatelly this approach is not suitable, becasue setting the value of a LED will actually turn it on..We dont want to turn them on, we just want ensure, that according to a daypart, when some led gets turned on by a user, or by some code, its brightness and color will correspond with those values set in their data..

    Kinda tricky one, but will grind my mind further to find a simple solution, and not write hundrds of lines.. 

     

    Ok, I think I know how to fix that with a custom property....

    but that's for tomorrow - now it's time to put on the tuxedo... 🍾

    • Like 1
    Posted
    13 hours ago, jgab said:

     

    Are you sure fibaro.callUI is defined? It's not available in ER5 unless you have defined it yourself.

    In ER4 it was available through fibaroExtra...


    My bad, fixed and working now thanks 

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