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

Cant get peace of LUA code to work, can somebody plz help.


Question

Posted

Hi everybody,

 

Who can help me with my lil problem. Im trying to get a 0-10Vdc signal to my ventilation box controlled bij air quality.

the higher the Co2 gets the higher the 0-10Vdc signal gets.

 

Now i have been writing some LUA (im a beginner of the beginners). with a bit of cut and paste and modifying etc etc etc.....

but i cant get a finger on the problem in this one: 

 

--[[
%% properties
%% globals
448 value
467 value
470 value
473 value
%% time
%% autostart
--]]

while true do
 local LQ1 = fibaro:getValue(448, "value");-- ID of Air quality woonkamer
 local LQ2 = fibaro:getValue(473, "value");-- ID of Air quality slaapkamer 1
 local LQ3 = fibaro:getValue(467, "value");-- ID of Air quality slaapkamer 2
 local LQ4 = fibaro:getValue(470, "value");-- ID of Air quality slaapkamer 3
 local LQsturing = 496; -- ID of WTW sturing 0-10Vdc
 Q40 ="400"
 Q45 ="450" 
 Q50 ="500"
 Q55 ="550"  
 Q60 ="600"
 Q65 ="650"  
 Q70 ="700"
 Q75 ="750"  
 Q80 ="800"
 Q85 ="850"  
 Q90 ="900"
 Q100 ="950"  
 
  local startSource = fibaro:getSourceTrigger();
 
  if ((LQ1 > Q100 ) or (LQ2 > Q100) or (LQ3 > Q100) or (LQ4 > Q100))
 then
 fibaro:call(LQsturing, "setValue", "100")
   if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 100% sturing"); end
 
elseif ((LQ1 > Q90) or (LQ2 > Q90) or (LQ3 > Q90) or (LQ4 > Q90))
 then
    fibaro:call(LQsturing, "setValue", "88")
   if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 90% sturing"); end
 
elseif ((LQ1 > Q85) or (LQ2 > Q85) or (LQ3 > Q85) or (LQ4 > Q85))
 then
     fibaro:call(LQsturing, "setValue", "83")
   if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 85% sturing"); end
  
 elseif ((LQ1 > Q80) or (LQ2 > Q80) or (LQ3 > Q80) or (LQ4 > Q80))
 then
   fibaro:call(LQsturing, "setValue", "78")
       if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 80% sturing"); end

  elseif ((LQ1 > Q75) or (LQ2 > Q75) or (LQ3 > Q75) or (LQ4 > Q75))
 then
   fibaro:call(LQsturing, "setValue", "73")
   if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 75% sturing"); end   
 
 elseif ((LQ1 > Q70) or (LQ2 > Q70) or (LQ3 > Q70) or (LQ4 > Q70))
 then 
   fibaro:call(LQsturing, "setValue", "68")
   if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 70% sturing"); end
 
     elseif ((LQ1 > Q65) or (LQ2 > Q65) or (LQ3 > Q65) or (LQ4 > Q65))
 then
   fibaro:call(LQsturing, "setValue", "63")
   if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 65% sturing"); end  
 
  elseif ((LQ1 > Q60) or (LQ2 > Q60) or (LQ3 > Q60) or (LQ4 > Q60))
 then
   fibaro:call(LQsturing, "setValue", "58")
   if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 60% sturing"); end   
 
   elseif ((LQ1 > Q55) or (LQ2 > Q55) or (LQ3 > Q55) or (LQ4 > Q55))
 then
   fibaro:call(LQsturing, "setValue", "53")
   if tonumber(fibaro:getValue(LQsturing, "value")) > 0 then fibaro:debug("WTW unit krijgt 55% sturing"); end  

  elseif ((LQ1 < Q50) or (LQ2 < Q50) or (LQ3 < Q50) or (LQ4 < Q50))
 then
   fibaro:call(LQsturing, "setValue", "0")
   if tonumber(fibaro:getValue(LQsturing, "value")) < 5 then fibaro:debug("WTW unit krijgt 0% sturing"); end
  end
  fibaro:debug("Woonkamer is " .. LQ1 .. " ppm");
  fibaro:debug("Slaapkamer 1 is " .. LQ2 .. " ppm");
  fibaro:debug("Slaapkamer 2 is " .. LQ3 .. " ppm");
  fibaro:debug("Slaapkamer 3 is " .. LQ4 .. " ppm");
 fibaro:sleep(60*5000)
end

 

what is wrong with this???

 

Thanks for helping!!

 

Greetings TSN

6 answers to this question

Recommended Posts

  • 0
Posted

What your debug window say?

Please decide, do you use DO loop in this scene or triggers?

  • 0
  • Inquirer
  • Posted
    3 minutes ago, drboss said:

    What your debug window say?

    Please decide, do you use DO loop in this scene or triggers?

     

    [DEBUG] 00:18:41: WTW unit krijgt 80% sturing
    [DEBUG] 00:18:41: Woonkamer is 787 ppm
    [DEBUG] 00:18:41: Slaapkamer 1 is 425 ppm
    [DEBUG] 00:18:41: Slaapkamer 2 is 805 ppm
    [DEBUG] 00:18:41: Slaapkamer 3 is 690 ppm

     

     

    Thanks for ur answer,

     

    It seems to work for now, but it works like a few hours and then it stops working.

     

    Sorry dont know what u mean by a DO loop?

     

    Greetings TNS

     

    • 0
    Posted
    8 hours ago, TSN1 said:

    %% properties
    %% globals
    448 value
    467 value
    470 value
    473 value
    %% time
    %% autostart

    Can you check your web UI and warnings about reach limits max instances for this script?
    You used this scrip for start by

    1) changes values. So you script will always Starr when any value in devices 448 ...473 was changed 

    2) your script always started on HC reboot or after saving this scrip

    3) and finally your script will started by %%time directive in Jan G. mini framework for scheduling 

     

    8 hours ago, TSN1 said:

    while true do

    And all started  instances  will looping infinity....

    • 0
  • Inquirer
  • Posted
    3 hours ago, 10der said:

    Kunt u uw web-UI en waarschuwingen over bereiklimieten max instanties voor dit script controleren?
    Je hebt deze scrip gebruikt om mee te beginnen

    1) verandert waarden. Dus je script zal altijd Starr zijn wanneer een waarde in apparaten 448 ...473 is gewijzigd 

    2) uw script is altijd gestart bij HC reboot of na het opslaan van deze scrip

    3) en ten slotte wordt uw script gestart door %% time-richtlijn in Jan G. mini-framework voor planning 

     

    En alle begonnen instanties lopen oneindig door ...

    Hi 10der,

     

    Thx for ur help (again)

     

    Its quite strange, it works like a charm since i posted this, but it will go wrong in time.

     

    The scene tells me there only 1 instance running (also the max limit is 1) and no alarms have been activated.

    i have deleted %%time and %%autostart does it mean it will only start on changes of 1 of the values? (448, 467, 470, 473)

     

    while true do: what can i change it to?

     

    I want to learn LUA but the lessons are quite expensive, so is there a way to learn LUA basics by my self?

     

    Thx for ur time

     

    greetings TSN

    • 0
    Posted (edited)
    1 hour ago, TSN1 said:

    n it will only start on changes of 1 of the values? (448, 467, 470, 473)

    1st - its wrong cuz under %% globals

    2nd - you use loop. please hear me. hej! you can't mix starting scene by value and looping - it's nie dziala! zaufaj mi :)

     

    Edited by 10der
    • 0
  • Inquirer
  • Posted
    2 minutes ago, 10der said:

    1st - its wrong cuz under %% globals

    2nd - you use loop. please hear me. hej! you can mix starting scene by value and looping - it's nie dziala! zaufaj mi :)

     

    Hi,

     

    1st - i noticed, so i allready changed that.

    2nd - is the hard part, i dont now how to do that. (cause i copy paste other scene's) i have (almost) no idee what im doing. Thats why im looking for a way to learn LUA. im getting better at it, but i have a long way to go.... :(

    so how do i not loop this?

     

    i changed: while true do. to: do. it seems to work to. (dont know if its better)

     

    thx again for ur answer.

     

    Greetings TSN

     

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