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

Changed Lua Code


amatt

Question

before upgrading to the latest Beta I had a simple scene that turned on and off my desk light whenever I sat down or got up (see below). this does have Hue light Bulbs. 

 

  if 
 tonumber(fibaro:getValue(189, "value")) == 0
then
  fibaro:call(118, "setSlider", "2", "100")
  fibaro:debug("Desk Light on");
  
elseif
  
     tonumber(fibaro:getValue(189, "value")) == 1
    then
    
      fibaro:call(118, "setSlider", "2", "0")
    fibaro:debug("Desk Light off");

end

 

since upgrading now when I sit down the light does not come on ( I did not change any code). so I changed the code to this to make the light come on every 10 seconds. I don't want it to check every 10 seconds I want it to be instant like before I upgraded. Can anyone help? ps. if this code can be redone entirely please let me know how I am not the best at coding yet I am trying my best. thank you!

 

--[[
%% autostart
%% globals
--]]

fibaro:debug("Waiting...")

while true do
  
  if 
 tonumber(fibaro:getValue(189, "value")) == 0
then
  fibaro:call(118, "setSlider", "2", "100")
  fibaro:debug("Desk Light on");
    fibaro:sleep(10000);
  
elseif
  
     tonumber(fibaro:getValue(189, "value")) == 1
    then
    
      fibaro:call(118, "setSlider", "2", "0")
    fibaro:debug("Desk Light off");
    fibaro:sleep(10000);

end
  
  end

Link to comment
Share on other sites

16 answers to this question

Recommended Posts

  • 0

 

 

your code should (must) works

 

Please login or register to see this code.

 

btw.

if motion value ==1

if no motion value == 0 

 

Edited by 10der
Link to comment
Share on other sites

  • 0
  • Inquirer
  • @10der yeah it still does not work properly. I tried about everything I know. The only way I have somewhat have it working is by doing a do while true. but it keeps printing my debug every 1 second. 

    Link to comment
    Share on other sites

    • 0

    Ок

     

    Please login or register to see this code.

    Just run this

    Edited by 10der
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Get the Following....

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
    On 7/31/2018 at 2:30 PM, amatt said:

    before upgrading to the latest Beta I had a simple scene that turned on and off my desk light whenever I sat down or got up (see below). this does have Hue light Bulbs

    Please try your original script, but add fibaro:sleep(250) after the header and before the "if". So right at the start of the script, to delay the execution of that script a little bit.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @10der

     

    i changed it to V. the result is 0 when sitting down and ran it again while off the chair got a result of 1.

     

    you have to remember that this is a door sensor. 0 is "door" closed (aka when i am sitting down) 1 is "door" open (aka when not sitting down)

     

    @Sankotronic thanks i removed it

     

    @petergebruers i added fibaro:sleep(250) to the code but no difference. still have to run it manually to make it change

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    Ah!

     

    Your header is missing a trigger right now, it should be like this:

     

    Please login or register to see this code.

    Tip: do CTRL-A then SHIFT-TAB in the scene editor (code part), and your text will auto-flow. It will look nicer and also be easier to read.

     

    The %%autostart seems optional to me, it means "run once, at boot" and "run once, when you save".

     

    The weird thing is, you have said:

     

    On 7/31/2018 at 2:30 PM, amatt said:

    before upgrading to the latest Beta I had a simple scene that turned on and off my desk light whenever I sat down or got up

     

    I wonder if you had accidentally removed that: "233 value" line while debugging your original problem. Because all versions need that line, it must have been there previously.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @petergebruers thanks for the tip. i tried your suggestion for the trigger but no luck still does the same thing. 

    Link to comment
    Share on other sites

    • 0

    What is device 233? What is it connected to, eg a switch? I am trying to understand what starts the scene.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • it is a door sensor that runs to a pressure sensor. that is it.

    Link to comment
    Share on other sites

    • 0
    5 hours ago, amatt said:

    it is a door sensor that runs to a pressure sensor. that is it.

    Nice idea!

     

    Then it must be the old FGK-101 because the new D/W version does not have an input. Maybe you get too many on/off events from this sensor? Issues with multiple instances? I do not know...

     

    Thinking out of the box... You can set parameter 14 "scene activation" to 1 then wake up the device.

     

    Then trigger on this instead of value, like:

     

    Please login or register to see this code.

    You can also detect click/double click/hold - it i in the manual.

     

    Have you ever used sceneActivation before?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @petergebruers no none of those issues came about. I worked perfect before don't know what would have changed to cause this. 

     

    I have never used sceneActivatino before.

     

    @Sankotronic do you have any ides?

    Link to comment
    Share on other sites

    • 0

    Hi @amatt ,

     

    I have just tested scene on my test HC2(4.510) with DW sensor ID:189 and my Philips HUE VD ID:118 and this code work just fine:

    Please login or register to see this code.

    NOTE - I didn't use external contact with DW sensor but magnet. That should not make any difference since they are both triggering same. If your DW sensor is reachable maybe you can test with magnet just to see that it works properly because there is a chance that something get wrong with connection between DW sensor and pressure sensor?

    If you still don't get light turned on with above code but debug lines are OK then maybe you should check VD that controls light?

    BTW In your first post you used sensor device with ID 189, but then later you change it to 233? Why device ID was changed later?

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @Sankotronic your code is now working correctly. Do not know why it was not taking mine correctly.

     

    yeah it was 189 but then I removed it and re-added it back that gave it a new id of 233.

     

    Thanks for Everyone's help!

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