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

Hello Jan

Basic question, but I have a keyfob, and would like to slowly increase light value when long pressing let’s say button 1, then when releasing it and long pressing it again, I would like it to slowly decrease that same light value (ie mimic behaviour of a fibaro dimmer). What’s the best way to build a rule to do that? I tried with a local variable changing from true to false each time the long press was released but not much success..

thanks

Link to comment
Share on other sites

Hello, thanks. Actually I have it working for a 2 buttons setup, however I'm trying to make a single button solution for this. I tried the following but it does not seems to work: 

 

Quote

Please login or register to see this code.

 

 

Any idea?
Thanks

 
Link to comment
Share on other sites

  • Topic Author
  • 8 hours ago, ndelaet said:

    Hello, thanks. Actually I have it working for a 2 buttons setup, however I'm trying to make a single button solution for this. I tried the following but it does not seems to work: 

     

     

    Any idea?
    Thanks

     

     

    Haven't tested but this should work

    Please login or register to see this code.

     

    You need :levelStop to stop the ongoing dimming.

    Now it will toggle direction every time the button is released.

    Note, it can be tricky to try to synchronise the dimming between to lights this way...

    ...maybe just dim one light and copy the value from that to the other? Then you are guaranteed that they end up with the same value...

    Ex. rule("478:value => 490:value = 478:value")

    • Thanks 1
    Link to comment
    Share on other sites

    10 hours ago, jgab said:

     

    Haven't tested but this should work

    Please login or register to see this code.

     

    You need :levelStop to stop the ongoing dimming.

    Now it will toggle direction every time the button is released.

    Note, it can be tricky to try to synchronise the dimming between to lights this way...

    ...maybe just dim one light and copy the value from that to the other? Then you are guaranteed that they end up with the same value...

    Ex. rule("478:value => 490:value = 478:value")

    Hi Jan

     

    Can you elaborate how you use the "pipe" and "&" after the => sign

    before the => its "and" and "or", but how should it be read after=> ?

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, ChristianSogaard said:

    Hi Jan

     

    Can you elaborate how you use the "pipe" and "&" after the => sign

    before the => its "and" and "or", but how should it be read after=> ?

    Please login or register to see this code.

     

     

    Well, it has the same function on the right hand side of the =>.

    it's kind of a short cut for if-then-else.

    In the beginning of ER there were no if-then-else or || >> constructs so this was the only way to have conditions in the action.

    A & B will evaluate both A and B if A is not false/nil. If A is false/nil it will return false/nil without evaluating B

    In that way A & B is like 

    if A then B end

    | (or) is similar both returns the first value that is not false/nil

    So, '&' has higher precedence then '|' so

    A & B | C

    becomes

    (A & B) | C

    which is (almost) like

    if A then B or C

    Almost, because if B return false, then C will be evaluated.

    • Thanks 1
    Link to comment
    Share on other sites

    Daily operation time of the device.
    Hello Jan. Happy New Year everyone!
    The idea of calculating the time, how much the device worked per day, came up.
    the task is as follows: I have 4 pumps from the heating of my house at home, each of them heats its own rooms. Not long ago, I noticed that my 1 pump never turned off at all, and the whole problem was in one thermal head on the battery... if every morning I received a report on how many hours were worked yesterday, then I would quickly find out what something is wrong...
    similarly, the same logic can be used for light, understanding that someone forgets to turn off the light, etc.

    How can this be calculated in ER4?

    Link to comment
    Share on other sites

  • Topic Author
  • Haven't tested this live but the logic I believe is correct. It will sum the 'on' time for each device in 'timeDevices' for every day and reset and report/log at midnight.

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    Haven't tested this live but the logic I believe is correct. It will sum the 'on' time for each device in 'timeDevices' for every day and reset and report/log at midnight.

    Please login or register to see this code.

     

     

    Please login or register to see this image.

    /monthly_2023_01/image.png.fe35780625baecc55b0e0520c02f0f5c.png" />

    Please login or register to see this attachment.

    Enter the ID of your two light bulbs. But I don't really understand something when it should show me this time! This is my clean test ER4 v0.991

    Edited by fastvd
    Link to comment
    Share on other sites

  • Topic Author
  • Every midnight at 00:00

    Link to comment
    Share on other sites

    Please login or register to see this attachment.

     

     

    I changed the time so that the rule would work faster, but unfortunately there is nothing (

    Link to comment
    Share on other sites

    it was 8:42 p.m., I corrected it so that the report came at 9:00 p.m., at 8:46 p.m. I turned on the light for 2+ minutes, then waited a few seconds and at 8:49 p.m. turned on the light again for 2 minutes...and that was between the start of ER4 and the specified time of the report , which is 21.00, the light was turned on twice for 2 minutes, 4 minutes in total... at 21.00 theoretically we should have received some information... but unfortunately nothing came ((((

    Please login or register to see this attachment.

    Edited by fastvd
    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, fastvd said:

    any idea?

    Can you post the whole changed rule? My original was a bit sensitive to being a full day starting at 00:00...

     

    Link to comment
    Share on other sites

    4 hours ago, jgab said:

    an you post the whole changed rule? My original was a bit sensitive to being a full day starting at 00:00...

     

     

    I just replaced 00:00 with 21:00, and yes, when the specified device (in my case ID=497) is turned on or off, I can see in the console that some rules are triggered! it can be seen on the previous screen!

     

    timeDevices = { 497 }
    sumOn,lastOn = {},{}
    for _,id in ipairs(timeDevices) do sumOn[id],lastOn[id]=0,0 end -- initialize
      
      rule([[@21:00 => 
        local res = {};
        for id,_ in ipairs(timeDevices) do
          res[id] = id:isOn & (sumOn[id] + now - lastOn[id]) | sumOn[id];
          lastOn[id]=0;
          sumOn[id]=0 
        end
        post(#timeReport{value=res})
        ]]) 
      rule("timeDevices:isOn => lastOn[env.event.id]=now")
      rule("timeDevices:isOff => sumOn[env.event.id]= sumOn[env.event.id] + now - lastOn[env.event.id]")
      
      rule([[#timeReport{value='$res'} =>
        for id,t in ipairs(res) do
           log("Device %s on for %s",id,HMS(t))
        end]])
    Edited by fastvd
    Link to comment
    Share on other sites

    16 minutes ago, fastvd said:

    I just replaced 00:00 with 21:00, and yes, when the specified device (in my case ID=497) is turned on or off, I can see in the console that some rules are triggered! it can be seen on the previous screen!

     

    timeDevices = { 497 }
    sumOn,lastOn = {},{}
    for _,id in ipairs(timeDevices) do sumOn[id],lastOn[id]=0,0 end -- initialize
      
      rule([[@21:00 => 
        local res = {};
        for id,_ in ipairs(timeDevices) do
          res[id] = id:isOn & (sumOn[id] + now - lastOn[id]) | sumOn[id];
          lastOn[id]=0;
          sumOn[id]=0 
        end
        post(#timeReport{value=res})
        ]]) 
      rule("timeDevices:isOn => lastOn[env.event.id]=now")
      rule("timeDevices:isOff => sumOn[env.event.id]= sumOn[env.event.id] + now - lastOn[env.event.id]")
      
      rule([[#timeReport{value='$res'} =>
        for id,t in ipairs(res) do
           log("Device %s on for %s",id,HMS(t))
        end]])

    just now, I turned on the light at 17:06:26 and turned it off at 17:12:10, it was clearly recorded in the ER console...

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    Hi @jgab,

     

    Was just wundering.. This monitoring of a devices ontime is perfect.. Would it be possible to "extend" the rule to monitor the power usage of a device and log it the same way as this scene?

    Ex. I currently have a power meter on all of my freezer and fridges. It would be really nice if the system could monitor the power usage of these devices and alert me if this goes over or under a certain level of power usage per day. This way I would get a heads up if one of these goes dead or starts to run more than normal.

     

    And besides that, thanks a lot for Your great work with this QA. It currently runs most of my house.. :-)

    Link to comment
    Share on other sites

  • Topic Author
  • So, this I think is better. It handles custom report times better.

    rule("@21:00 => post(#timeReport{reset=true})") will log a report at 21:00 and reset the sum counters.

    rule("@21:00 => post(#timeReport{reset=false})") will report without resetting the counters.

     

    You could do a 

    rule("497:off => post(#timeReport{reset=false})") to trigger a report every time you turn off the light  and see if it sums correctly.

     

    To do it for power usage you need to have the power usage x time, so if you have the time? I believe that @fastvd has experimented with power consumptions...

     

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    Yes, I've been using your code to report energy consumption for about 1 year now, and I've gotten it to work the way I want, namely:
    1) Every day at 09:00 a.m. it gives me a report on how much electricity was used yesterday
    2) Every day at 09:00 a.m. gives me a report on how much electricity has been used since the beginning of the month (from the 1st)
    It is very convenient for me to control my expenses in this way and to understand in general whether everything is working correctly! Thank you so much again Jan!
    Perhaps someone did not fully understand the energy function, so I will give 2 versions of the code here.

     

    --II) Energy function for yesterday
    --1) Make the following data triggers
     Util.defTriggerVar('eConsumption_1day')
     Util.defTriggerVar('eConsumptionCost_1day')

    ---
    --2) Energy function for 1 day
    function energyConsumption_1day(time)
    return api.get("/energy/consumption/summary?period="..os.date("%Y-%m-%d",time))
    end

    --
    --3) The collection of information itself
    rule([[@{07:00,catch} =>
    local e=energyConsumption_1day(os.time()-1*24*60*60);
    -- here the first number 1 is the number of days from today's date...in other words - from yesterday
    --local e=energyConsumption(os.time()); -- and that's it for today
        eConsumption_1day = e.consumption;
        eConsumptionCost_1day = e.consumptionCost
      ]])

    ---
    --4) The report itself for yesterday
       rule([[#notify_power & eConsumption_1day > 0 => -- my post notify_power starts at 09:00 every day
       log('Consumed yesterday: %s kW',eConsumption_1day);
       log('Cost for yesterday %s UAH',eConsumptionCost_1day);
       fibaro.call(teleg_fastvd, 'sendMessage', fmt('Consumed yesterday %.2f kW, cost %.2f UAH' , eConsumption_1day, eConsumptionCost_1day), -700919895)
       ]])

     

    ------
    --III Energy function since the beginning of the month
    --1) Make the following data triggers
    Util.defTriggerVar('eConsumption')
    Util.defTriggerVar('eConsumptionCost')

    ---
    --2) Energy function since the beginning of the month
    function energyConsumption(time)
        local start=os.date("%Y-%m-%d",time)
        local stop = os.date("%Y-%m-%d")
        local call = "/energy/savings/detail?startDate="..start.."&endDate="..stop.."&intervalType=Monthly"
        print("call:"..call)
        local res = api.get("/energy/savings/detail?startDate="..start.."&endDate="..stop.."&intervalType=Monthly")[1]
        print("production:"..res.production)
        print("consumption:"..res.consumption)
        print("productionCost:"..res.productionCost)
        return res
      end

    --3) At 9 in the morning, he checks how many kilowatts have been stored since the 1st
    rule ([[#notify_power => -- my post notify_power starts at 09:00 every day
        local day = os.date("*t").day;
        local e = energyConsumption (os.time ()-day*1*3600);
    -- This month
        eConsumption = e.consumption;
        eConsumptionCost = e.consumptionCost

    ]])
    --4) If it is more than 0 Kwat, then a message
       rule([[eConsumption > 0 =>
       log('Consumed since the beginning of the month: %s kW',eConsumption);
       log('Cost %s UAH',eConsumptionCost);
       fibaro.call(teleg_fastvd, 'sendMessage', fmt('Consumed since the beginning of the month %.2f kW, costing %.2f UAH' , eConsumption, eConsumptionCost), -700919895)
       ]])

    Edited by fastvd
    Link to comment
    Share on other sites

    If we could overcome the calculation of the device's operating time, then we could make such a super report:
    1) We will have device operating time, in my case these are pumps that drive hot water to my batteries on the second floor and to the warm floor on the 1st floor
    2) I have a temperature sensor that measures the temperatures in these pumps (more precisely, I have 2 barrels of 1 ton that heat up at night and give off heat during the day)
    3) each pump has its own technical characteristics, how much WATER, and accordingly it is easy to calculate the heat it pumps in a certain time
    4) accordingly, we can actually calculate how much heat the pumps pumped out, which will be equal to the HEAT LOSS OF THE HOUSE as a whole, which is a VERY valuable indicator!

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