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


  • 0

LUA: if power is > 8 then press vd button X ONCE


Question

Posted

Hi,

 

I’m trying to write a LUA scene where power value is the trigger. I want that if power is above 8 then press button 2 on VD once. If power is below 7 press button 4 once.

 

Now when I write a scene like this, everytime there is a power change above 8 watt the button on the VD is pressed. That trips my HC2 and VD.

 

How can I solve it that the VD button is pressed once when the power is above 8 watt regarding the power value changed above the 8 watt?

Recommended Posts

  • 0
Posted

Hi @kevin,

 

Make a global var "runonce" or whatever. on the first click set it to 1, and check against it.

and if power is below 7 set it to 0 and check against it.

Like if power > 8 and runonce is >=8 set 1, if runonce == 1 then debug("all ready 1") end or whatever you need.

Same when power <7

 

Hope this helps.

 

Jim

  • 0
Posted (edited)

Like @jimicr suggestion, storing the last value, and test if it's crossed one of the thresholds. Need to be a bit careful as you wanted < 7 and > 8. 

Please login or register to see this code.

Edited by jgab
  • 0
  • Inquirer
  • Posted (edited)

    Thanks for both answers.

     

    @jgab

    I have created this scene 

    Please login or register to see this code.

     

    In the debug I get error:

    [DEBUG] 13:47:10: current power 6.1, last power 
    [DEBUG] 13:47:10: 2020-05-30 13:47:10.690859 [ fatal] Unknown exception: /opt/fibaro/scenes/288.lua:13: attempt to compare number with string

     

    I have created the variable lastPower but nothing is stored here, think because of the debug error?

     

     

    What am I doing wrong?

     

     

    Please login or register to see this attachment.

    Edited by kevin
    • 0
    Posted

    Sorry, missed to convert values to numbers. Fixed in original post

    • 0
    Posted

    Maybe try to define the Global when you create. set "0" and not leave empty

     

    Jim

    • 0
    Posted
    Just now, jimicr said:

    Maybe try to define the Global when you create. set "0" and not leave empty

     

    Jim

    Yes, the variable 'lastPower' need to be defined also - you can do that in the panels...

    Another bug was that I saved lastValue instead of currentValue in the last statement - also fixed in original post.

    • 0
  • Inquirer
  • Posted

    Thank you.

     

    Maybe I should have told it earlier, but when the power is above 8(maxvalue) it fluctuates.

     

    First let explain why I want this scene.

    I have an AC in the room that can be controlled by a VD by using a Remotec ZXT-120. Because my wife uses the remote a lot the VD status isn't updated to ON or OFF.

    So I wanted a scene that checks the power usage of the AC by using a Fibaro power plug and updates the VD by pressing a button.

     

    Now with the provided scene by @jgab it only works why I press start. When I add %% properties to the header it keeps pressing the button in the VD because the power fluctuates. How can I change the scene that it only presses the the VD button once when the power usage is above 8 (maxvalue) despite the fluctuation?

     

    I apologize for all the questions and my not so clear topic question ??

    • 0
    Posted (edited)

    Ok, It was my intention but my code was still wrong ?

    New attempt.

    Please login or register to see this code.

     

    Edited by jgab
    • 0
  • Inquirer
  • Posted

    Thank you again for the quick reply. 

    First I got an error but that was because in the fibaro:debug line was still lastValue mentioned but you changed that to oldValue.

     

    After that I get the error below

     

    [DEBUG] 09:53:38: current power 183.4, last power 7.5
    [DEBUG] 09:53:38: 2020-05-31 09:53:38.837058 [ fatal] Unknown exception: /opt/fibaro/scenes/288.lua:12: attempt to compare number with string
     

    Sorry to make it so hard for you ?

    • 0
    Posted
    1 hour ago, kevin said:

    Thank you again for the quick reply. 

    First I got an error but that was because in the fibaro:debug line was still lastValue mentioned but you changed that to oldValue.

     

    After that I get the error below

     

    [DEBUG] 09:53:38: current power 183.4, last power 7.5
    [DEBUG] 09:53:38: 2020-05-31 09:53:38.837058 [ fatal] Unknown exception: /opt/fibaro/scenes/288.lua:12: attempt to compare number with string
     

    Sorry to make it so hard for you ?

    Sorry again, the tonumber fell off again. I edited my last post.

    • 0
  • Inquirer
  • Posted (edited)

    Still not pressing the VD buttons automatically?. The scene is on automatic.

     

    See the video, the AC power is idle in standby at 5.80W. When I press the ON button on the physical remote you see that the power is going up, but in the scene/debug is nothing happening. I had added extra lines of debug when the VD button should be pressed to monitor it. 

     

    I also tried by adding %% properties to the header, the scene runs automatically and buttons are pressed but the AC is going on-off-on-off-....

     

    Hope this video helps (it's my son yelling on the background ?)

    Edited by kevin
    • 0
    Posted
    14 minutes ago, kevin said:

    Still not pressing the VD buttons automatically?. The scene is on automatic.

     

    See the video, the AC power is idle in standby at 5.80W. When I press the ON button on the physical remote you see that the power is going up, but in the scene/debug is nothing happening. I had added extra lines of debug when the VD button should be pressed to monitor it. 

     

    I also tried by adding %% properties to the header, the scene runs automatically and buttons are pressed but the AC is going on-off-on-off-....

     

    Hope this video helps (it's my son yelling on the background ?)

     

    Please login or register to see this attachment.

    Hi @kevin look in your device parameters. maybe the report power change is set to high and doesn't trigger the scene

    • 0
    Posted

    I changed the code once again - this was too hard to code on a Sunday morning ;-)

     

    Yes the header should be

    Please login or register to see this code.

    You are sure that the deviceID (377) is correct?

    You should get logs

    • Like 1
    • 0
    Posted
    12 minutes ago, jgab said:

    this was too hard to code on a Sunday morning ;-)

     

    :-D

    • 0
  • Inquirer
  • Posted

    I have tried for hours now. But with %% properties added to the header the scenes goes crazy.

     

    After a few minutes my HC2, Remotec and AC are tripping?

     

     

    • 0
    Posted

    AH, in my last post I said that I changed the code again.

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    Missed that ?‍♂️

     

    I used the new code, but nothing happens. As soon as I add %% properties is again goes on-off-on-off-on-off

    Watch video with volume up to hear the AC

    • 0
    Posted

    Every time the lastValue changes value it will also press a button. You get power changes every second and it seems to switch every ~10s on average.

    I guess instead of the algorithm to switch once above&below the threshold values you could try to dampen the value by calculating a rolling average?

     

     

    • 0
    Posted

    @jgab

    btw. “rolling average” could be very nice feature in EventRunner ?

    rollingAvg(id_powerDev, intervalForCalcAvg, timeForUpdate) > xxx 

     

     

    • 0
    Posted
    35 minutes ago, petrkl12 said:

    @jgab

    btw. “rolling average” could be very nice feature in EventRunner ?

    rollingAvg(id_powerDev, intervalForCalcAvg, timeForUpdate) > xxx 

     

    With some hacking you can get it.

    Please login or register to see this code.

    'rolling55' will be a variable that rules can trigger on that will contain  the rolling average of the las t5 values of device 55. rigger variables only trigger if the actual value changes too so that's nice.

    Could be something to build into future version of ER... could also be over time instead of samples.

     

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

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