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

Weekly timer scene outdoor lights; SOLVED


MARCUSP.I.L

Question

I have my outdoor scene running at various time of the day and week and find that the scenes sometimes "miss" the trigger (time =Tid in Norwegian), turning lights back on or off etc.. I am using a lua scene borrowed from 

Please login or register to see this link.

 and have adapted variable names to my native language. I am just starting to program lua scenes and would greatly appreciate any help with this. Thank You in advance. I am trying to "clean up" or improve the functions in this scene .

I see some great scenes here on the forum , really well organized..

Could someone point me in the right direction ?

I thank all contributing members on this forum for helping me get this far.

Still a long way to go , but i like it...

 

Thanking all who helped , really appreciate your time and assistance gentlemen

Edited by MARCUSP.I.L
Link to comment
Share on other sites

17 answers to this question

Recommended Posts

  • 1

 

for  293 you may add the group by own :)

 

see attachment

 

Edited by 10der
Link to comment
Share on other sites

  • 1

Setup visual studio code for example. How? Look my last comments I was provided step by step how.

next steps - debugging. 

Understanding your code with many “ifs”  plus local national names of vars ;) makes me despondent ;)

 

Link to comment
Share on other sites

  • 1

UPD:

 

Please login or register to see this code.

 

but. why you use moment checking instead of checking period when lights should be ON or OFF

 

for example with my code:

if between("1.21:30..6.22:30, 1.22:40..6.23:40,  6.00:00..7.07:00")  then

xxxxxxxx

end

 

at Mo (1), also at all days till Sa (6) from 21:30 till 22:30

at Mo (1), also at all days till Sa (6) from 22:40 till 23:40

at WeekEnd (Saturday Sunday 6,7), from 00:00 till 07:00

 

 

 

 

 

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thank you 

    Please login or register to see this link.

     

    Please login or register to see this link.

    , just back from work, had to laugh when i read your reply..don't get too despondent with newbies like me :))

    Your code is completely new to me, and i will have to experiment a little. I looked everywhere to find a way of setting up triggers "between the hours of".

    It seems i have been looking at block scenes too long ??

    Thank you for your excellent and prompt reply, i feel like i'm heading into unknown waters with this code, but that is the point ..

    Thanking you once again.. Perhaps i can post my final setup when i get it ready ?

     

    ps: thanks for update 

    Link to comment
    Share on other sites

    • 0

    If you can describe without coding ;) on words when lights should be on and when should be off I can help to you develop that

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks for message:

    What i am trying to do is this:

     

    At Sunset , all the days of the week : (Setvalue 70) on id's 303,298,268,273,293,540, (Turn on) id 516.

    At 21.30 , Mon,Tues,Wed,Thur,Sunday : Turn off 303, (Setvalue 50) to id's 298,268,273,540.

    At 22.30 , Mon,Tues,Wed,Thur,Sunday : Turn off id's 298,268,273,540,516.

    At 22.40 , Mon,Tues,Wed,Thur,Sunday : Turn off id 293.

     

    At 23.30 , Friday ,Saturday Turn off 303, (Setvalue 50) to id's 298,268,273,540.

    At 00.01 ,Friday night , Saturday night Turn off id's 298,268,273,540,516.

    At 00.30 , Friday night , Saturday night Turn off id 293.

     

    At 06.15 , Mon,Tue,Wed,The,Friday : Turn on id 293(Setvalue 50 )

    At 07.30 , Saturday, Sunday Turn on id 293(Setvalue 50 )

     

    At Sunrise , all the days of the week : Turn off id's 293.

     

    I hope i have managed to explain my scene ? I looked at visual studio code yesterday and downloaded program. Very difficult for a new beginner, but i see that there are many ways to set up/ code a lua scene for my house.

    I am working my way through basics with global variables / conditional statements / trigger etc..

    Delighted when i manage to get them to work..

    Thank you, thank you for your time , i really appreciate it.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • What can i say ? This is the most amazing lua scene programming, elegant and smart.

    I thank you 10der for your fantastic assistance and for giving me such a comprehensive and speedy response.

    I thought , initially, that all lua (time based) scene coding consisted of setting up global variables (time-day-date-state-etc ) and then promoting these variables to "act" with a timer, running once a minute.

    I see now that the possibilities are endless.

    Thank you again 10der , you have really pointed my in another direction.. Дякую

    I look forward to working with this scene and improving my skills. I will look to your posts to learn more.

    Great insight into lua coding from a true master of programming.

    Look here if you are like me and just staring to use lua scenes.

    • Thanks 1
    Link to comment
    Share on other sites

    • 0

    @MARCUSP.I.L Sir, I do not think what it's difficult. :)

    and btw, 

    I group your problem definition by DeviceId and trying to make groups.

    After - all very easy. 

    we have a group. in the group we have devices. the group can have times periods when  ON (otherwise if OFF). 

    if simple let time as periods, that's all. if not simple separate time periods when a group should change the lighting level.

    and last, if you want to use Tid event - remove 

    1) while true do   fibaro:sleep(59700) end

    2) %% autostart from header

    3) add %% globals
    Tid

    to header

     

    as I can understand Tid event run every 1 min. It's also ok

     

    Edited by 10der
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks again 10der, i understand what you are telling me..

    However, i tried to change the settings to include id 293 and got error in debug.

    So i tired with the Lua file you sent me (no changes), just to check  and i got this error:

     

    [DEBUG] 22:54:21: [1;31m2018-10-26 22:54:21.035645 [ fatal] Unknown exception: /opt/fibaro/FibaroSceneAPI.lua:115: attempt to concatenate local 'deviceId' (a nil value)

     

    I have tried to work with this problem and have looked at variable names and tried to change settings but alas....

    I suspect it might be predefined variables ??? Line 115 to 117  compares values that i really don't understand..

     

           return m1 <= t and t <= m2 -- 01:00-02:00

            else

                return m1 <= t or t <= m2 -- 23:00-21:00

     

    Perhaps you could have a quick look if you have time ?

    Thanking you..

    I also will try scene with "Tid" and change header/autostart/sleep  etc..

    Just one last question, how do you debug your lua file in VSC ?

    Thought it might be smart to try out ideas there before moving to Hc2?

    Thank you again for helping me understand more about lua, i am grateful for your help.

    Link to comment
    Share on other sites

    • 0
    8 hours ago, MARCUSP.I.L said:

    settings to include id 293 and got error in debug.

    So i tired with the Lua file you sent me (no changes), just to check  and i got this error:

    Please show me how 

    8 hours ago, MARCUSP.I.L said:

    return m1 <= t and t <= m2 -- 01:00-02:00

            else

                return m1 <= t or t <= m2 -- 23:00-21:00

    This is check on period 

    you may set period as 

    I what to light from 18:00 till 22:00

    also you may setup,period as 

    I what to light from 15:00 till 13:00 that’s mean what lighting will Turing on at 15 day , still light at night next day morning and will turning off at 13... on two hour and light at 15h again 

    About debugging. Ok, Will do. After breakfast with my family ;) 

    Link to comment
    Share on other sites

    • 0

    so I hope you’re doing well :)

    also, I hope you already installed VSC and can write and debug Hello World LUA application.,

    if not, please install VSC, plugin CBA3JIvx3G.png

     

    Lua Debug by actboy168

    now you may create first LUA file

     

    HelloWorld.LUA

    with content 

     

    Please login or register to see this code.

    so, now simple press F5

    and walk (debug) by your code via F10 - step by step

    finally, you should get answer 4 :Qn58QHqwWG.png

     



    now. create a new file fibaro.lua 

    with content

    Please login or register to see this code.

    save and close.

    create in current folder "lib" directory and here attached libs.zip 

    edit fibaro_emu.lua 

    change first two lines

    local hc2IPAddress = "192.168.1.36"

    change 192.168.1.36 on IP Address you HC2

     

    change b2xlZy5kZW5pc2Vua29AZ21haWwuY29tOjEwZGVyU3VwcG9ydA== on you hash

    Hash can be generated here:

    Please login or register to see this link.

    just provide you creds for HC2 and get result. copy/past to file hash. Save.

    TzgzEkloGi.png

     

    so now time for changing HelloWorld.lua script

     

    Please login or register to see this code.

    press F5 and F5 again,

    you should see 4 in debug console again.

     

    now you may copy this script to buffer (Ctrl+C)

    and Paste (Ctrl+V) in Fibaro UI

    save

     

    should get the same result

     

    S4tfCOp7BX.png

     

    well done!

     

     

     

     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks 10der, was at birthday party yesterday, thanks for your massages. I will work with the VSC code today (thank you for instruction), look forward to exploring new ideas.

    I am still struggling with Lua file you sent me. I have tried everything to make it work..

    I have used the file you sent , made no change but still receive the error: 

     

    [DEBUG] 12:18:17: 12:18 | October 28, 2018 Bakkelys Master Soverom check

    [DEBUG] 12:18:17: 12:18 | October 28, 2018 Bakkelys Master Soverom 1.$Sunset..4.22:30, 5.$Sunset..6.23:00, 7.$Sunset..7.22:30 => isn't the time for lighting

    [DEBUG] 12:18:17: [1;31m2018-10-28 12:18:17.109713 [ fatal] Unknown exception: /opt/fibaro/FibaroSceneAPI.lua:115: attempt to concatenate local 'deviceId' (a nil value)

     

    This is what i want to do when i get the Lua file to work. For trial now i am using the file you sent with no changes made

    Please login or register to see this image.

    /monthly_2018_10/971448004_Skjermbilde2018-10-28kl_12_23_26.png.d1c6d45d0c2fa6679ea9fc00adefe169.png" alt="971448004_Skjermbilde2018-10-28kl_12_23_26.png.d1c6d45d0c2fa6679ea9fc00adefe169.png" />

     

    I am sorry to keep bothering you with this, i really hoped i would be capable of fixing it myself, but there is something i don't understand ??

    Otherwise i am extremely grateful for all of your assistance, i hope you don't think i'm trying to get you to write code for me, i can only imagine how many requests you recieve?

     

    Hoping you find time ,when available, to answer my inquiry.

    Thanks 10der for introducing to a whole new element of Lua programming...

     

    Link to comment
    Share on other sites

    • 0
    6 hours ago, MARCUSP.I.L said:

    [DEBUG] 12:18:17: [1;31m2018-10-28 12:18:17.109713 [ fatal] Unknown exception: /opt/fibaro/FibaroSceneAPI.lua:115: atte

    Sir

    Just look at 115 line and trying to understand what happens here.

     

    ahh stop. it's FIBARO lua code. Ж)

     

    hmm!

     

    Please login or register to see this code.

    115 line of FibaroSceneAPI.lua 

    Ha- ha!

     

    bug!

     

    just trying to fix.

    sorry!

    fix attached!

     

    do not forget setup own values for local lighting!

     

    sorry, for bug.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hei and thanks again 10der - scene with timer/ weekday/ on off /sunset is working great now. I have changed settings to include my var Tid. I am now using this scene for different locations in and around the house. 

    Your help has really started my new journey into lua. I sincerely thank you.

     

    Playing with VSC  and learning new things. Slight problems with vac on mac but and reading my way through it..

     

    Is it commonly recommended to use ( Main scene for time based events)?

    Do scenes running simultaneously ,aka:  autostart, impede system response ?

     

    Anyways, thanking you for your invaluable time and assistance..

    Link to comment
    Share on other sites

    • 0
    2 hours ago, MARCUSP.I.L said:

    Is it commonly recommended to use ( Main scene for time based events)?

    Do scenes running simultaneously ,aka:  autostart, impede system response ?

     

     

    if honestly, I use own time bases scene 

    Please login or register to see this spoiler.

    welcome!

    Edited by 10der
    Link to comment
    Share on other sites

    • 0
    On 10/24/2018 at 1:03 AM, MARCUSP.I.L said:

    I have my outdoor scene running at various time of the day and week and find that the scenes sometimes "miss" the trigger (time =Tid in Norwegian), turning lights back on or off etc.. I am using a lua scene borrowed from 

    Please login or register to see this link.

     and have adapted variable names to my native language. I am just starting to program lua scenes and would greatly appreciate any help with this. Thank You in advance. I am trying to "clean up" or improve the functions in this scene .

    I see some great scenes here on the forum , really well organized..

    Could someone point me in the right direction ?

    I thank all contributing members on this forum for helping me get this far.

    Still a long way to go , but i like it...

     

    --[[
    %% properties
    %% events
    %% globals
    Tid
    Dag
    Sunsettime
    Sunrisetime
    --]]

    if (fibaro:countScenes() > 1) then fibaro:abort() end 

    local Tid = fibaro:getGlobal("Tid")
    fibaro:debug(Tid)
    local Dag = fibaro:getGlobal("Dag")
    fibaro:debug(Dag)
    local Sunsettime = fibaro:getGlobal("Sunsettime")
    fibaro:debug(Sunsettime)
    local Sunrisetime =fibaro:getGlobal("Sunrisetime")
    fibaro:debug(Sunrisetime)

    if (
        (Tid == Sunsettime) and (Dag == "Mandag" or "Tirsdag" or "Onsdag" or "Torsdag"  or "Fredag" or "Lørdag" or "Søndag")
        ) then 
            fibaro:call(303, "setValue", "70");---utelys 1
           fibaro:call(298, "setValue", "70");---utelys 2
          fibaro:call(268, "setValue", "70");---utelys 3
          fibaro:call(273, "setValue", "70");---master 4
           fibaro:call(293, "setValue", "80");---utelys 5
           fibaro:call(540, "setValue", "70");---utelys 6
           fibaro:call(516, "turnOn");---flomlys T2
    elseif
        (
        (Tid == "21:30") and (Dag == "Mandag" or "Tirsdag" or "Onsdag" or "Torsdag"  or "Søndag")
        ) then 
            fibaro:call(303, "turnOff");---
            fibaro:call(298, "setValue", "50");---
           fibaro:call(268, "setValue", "50");---
            fibaro:call(273, "setValue", "50");---
           fibaro:call(540, "setValue", "50"); ----
    elseif
      (
        (Tid == "22:30") and (Dag == "Mandag" or "Tirsdag" or "Onsdag" or "Torsdag" or  "Søndag")
        ) then 
      fibaro:call(298, "turnOff");---
      fibaro:call(268, "turnOff");---
      fibaro:call(273, "turnOff");---
      fibaro:call(516, "turnOff");---
      fibaro:call(540, "turnOff");---
    elseif
        (
        (Tid == "22:40") and (Dag == "Mandag" or "Tirsdag" or "Onsdag" or "Torsdag"  or "Søndag")
        ) then   
      fibaro:call(293, "turnOff");  

      elseif
        (
        (Tid == "23:30") and  (Dag == "Fredag" or"Lørdag")
        ) then   
      fibaro:call(303, "turnOff");
      fibaro:call(298, "setValue", "50");
      fibaro:call(268, "setValue", "50");
      fibaro:call(273, "setValue", "50");
      fibaro:call(540, "setValue", "50");  

    elseif
      (
        (Tid == "00:01") and (Dag == "Lørdag" or"Søndag" )
        ) then   
      fibaro:call(298, "turnOff");
      fibaro:call(268, "turnOff");
      fibaro:call(273, "turnOff");
      fibaro:call(516, "turnOff");
      fibaro:call(540, "turnOff");

    elseif
        (
        (Tid == "00:30") and (Dag == "Lørdag" or "Søndag")
        ) then 
      fibaro:call(293, "turnOff");

    elseif
        (
        (Tid == "06:15") and (Dag == "Mandag" or "Tirsdag" or "Onsdag" or "Torsdag"  or "Fredag")
        ) then   
      fibaro:call(293, "setValue", "50");

    elseif    (
        (Tid == "07:30") and (Dag == "Lørdag" or "Søndag")
        ) then   
      fibaro:call(293, "setValue", "50");
     elseif
        (
        (Tid == Sunrisetime) and (Dag == "Mandag" or "Tirsdag" or "Onsdag" or "Torsdag" or "Fredag" or "Lørdag" or "Søndag")
        ) then 
      
      fibaro:call(293, "turnOff");
      fibaro:sleep(1000);
      end

     

    Hi

    I'm totally new with the LUA, but I've been programming a lot in other systems. When I see into LUA i see some similarity with "old days" programming.

    BUT, I Think we all can help each other to make this better!

     

    I made this simple example with a timer control to turn on/off a device (Device 17 is the number of the device in my system, you have to put in you're unique Id for your device)

    In this example you can put in the time to start and stop the device by time. 

    (Change the hour and Minute for you're test/use)

    You can use this for as many timestamps you would like for as many devices you like

     

    --[[
    %% properties
    %% events
    %% globals
    --]]

     

    while (true) do
      local hour = tonumber(os.date('%H'))
      local minute = tonumber(os.date('%M'))
      
      -- debug to show whats going on
      fibaro:debug(hour)
      fibaro:debug(hour == 22)
      fibaro:debug(minute)
      fibaro:debug(minute == 15)

      
      --Program
      if (hour == 22 and minute ==30) then
        fibaro:call(17, 'turnOn')
      elseif (hour == 22 and minute == 32) then
        fibaro:call(17, 'turnOff')
      end
      
      fibaro:sleep(55000) 
    end

     

    -- Information (55000 is only to secure that the time limit is less than 1 minute, and then the result of the outcome not will be disturbed by the timestamp)

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hei @Geir-Arne, welcome to less time with your wife :) Thanks for tip but i have moved on a bit since last.

    There are many great solutions here on the forum , from basic to advanced , all depends on your interest.

    For me, i started with easy to understand scenes and kind of moved up as i learned more. You can always replace / upgrade as you go along. 

    I can recommend using LUAScheduler for HC2 v1.1.5 original by robmac, contributions from jompa68 , A.Socha.

    I was using several scenes to run different time based programs , all were running with autostart , but opted for a single scene that runs multi events..

    I use the below Lua Scheduler specifically for my outdoor lights , and more ...

    Easy to start with but it is very smart and covers nearly all time based scenes - been using it for several months now with no bugs ...

     

    Less CPU usage and easier to manage. 

    Check site : 

    Please login or register to see this link.

    go about half way down page and download

     

     

    Or look at solution from @10der, also working for several months with no problems.

    Read and then read again, try and learn - great program, great insight into API and debugging etc.....

     

    Edited by MARCUSP.I.L
    • Thanks 1
    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...