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


Automatic Lightning System for HC3 (Motion/Average Lux)


chiel-s

Recommended Posts

 

Hi,

 

I want to share my automatic lightning system with the community. It controls my lights in a room based on motion sensors and average lux in the room. It’s build for HC3.

 

Goals:

-    I don’t want to use any buttons in this room, lights should turn on automatic by motions sensors
-    I want to measure the lux average and based on this value the lights turn on.
-    I want to have the ability to include exceptions, such as TV is on or Sonos is playing. In that case I don’t want the script to turn off the lights when there is no motion.
-    I want different light settings for day and night. I also want to reuse these light settings and don’t want it to integrate it into the motion script.
-    I want to reuse the scripts easily for other rooms.

 

Good to know:

-    The basic of the

Please login or register to see this link.

is from

Please login or register to see this link.

 
-    I was also inspired by this

Please login or register to see this link.

(but it's build for HC2) 
-    I bought a HC3 couple of weeks ago and I am totally new into LUA.
-    I am not a professional software engineer. I am sure my code is not the best and can be improved. Feel free.
-    I post this information for beginners and amateurs like me. Spent a lot of time finding the correct information because most of the scripts are created for HC2 and is not always easy to migrate to HC3.
-   Below a step by step guide to achieve above goals.
 

Step 1: Measure the average lux in the room

-    Create a global variable. In my script “luxAverageKitchen”.
-    Make sure to change Fibaro Motion Sensor parameter 40 (set it to 5lux) and parameter 42 (set it to 900s) of all the motions sensors that you want to use for calculating the average lux in the room. In my script I use sensor 69 and 38.

- Make sure to set this script to automatic.

 

Calculate average lux scene

 

Triggers

Please login or register to see this code.

Actions

 

Please login or register to see this code.

 

 

Step 2: Set TV Status

In the motion script we need the TV status. I use Fibaro wall plugs for my TV in the living room and the TV in the bedroom.

-    Create a global variable for each TV (tvLivingStatus and tvBedroomStatus in my script)

-    Device ID 44 is my TV in the living room and is used in the motion script.

- Make sure to set this script to automatic.

 

Set TV Status scene

 

Triggers

Please login or register to see this code.

Actions:

 

Please login or register to see this code.

Step 3: Motion script
- Now finally the script that runs after motion detection. Please make sure that you fill in the correct global variables and id’s.

- Make sure to set this script to automatic.

 

Motion Scene:

 

Triggers

 

Please login or register to see this code.

Actions

 

Please login or register to see this code.

 

Step 4: Manage all room lights from 1 Quick app (optional)

 

-   As you can see I only use 1 light in the motion script, id 65 refers to a quick app managing all the lights of the ground floor.

-  This way I can easly switch on all lights using Google home, the app or maybe in the future a button.
-    Make sure to create a global variable for the Day/Night settings (from 06:00 till 02:00 Day is set, from 02:00 till 06:00 Night is set in the script). In my script the global variable it is called “SetTimeOfDayLights” and only has two variables: Day or Night.
-    Below you can find the scripts.

 

SetTimeOfDayLights scene

 

Triggers

 

Please login or register to see this code.

Actions

 

Please login or register to see this code.

 

Quick app (Lights switch for whole room)

-    Create a quick app by using the Binary switch template.

- Go to the device --> Edit & Preview --> Edit

- Paste below code.

 

Please login or register to see this code.

 

 All these scripts are working great on my HC3 (5.040.37) . But in my log file I see (sometimes) an error is occurring in the motion scene without any information in the debug line. If someone knows what it is, let me know ;-)


That's it. Enjoy! 

 

 


 

 

 

Edited by chiel-s
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

TBh I hate Fibaro condition rules ... in HC2 it was suxxx in HC3 more pretty but still as for me suzpxx also 

so, I have script for motion lights what do not used any conditions (loops events) , works for all rooms in my home, have exclusion by other devices, have time rules and you can override any conditions by time slot for example min lux at the motion 100 and 50at the evening or set dim event evening 50 and 1 at the night 

can keep off state with pre defined dim level (so if no motion my led strip for example has level 1 instead of full off...)

etc 

 

Link to comment
Share on other sites

  • Topic Author
  • 49 minutes ago, 10der said:

    TBh I hate Fibaro condition rules ... in HC2 it was suxxx in HC3 more pretty but still as for me suzpxx also 

    so, I have script for motion lights what do not used any conditions (loops events) , works for all rooms in my home, have exclusion by other devices, have time rules and you can override any conditions by time slot for example min lux at the motion 100 and 50at the evening or set dim event evening 50 and 1 at the night 

    can keep off state with pre defined dim level (so if no motion my led strip for example has level 1 instead of full off...)

    etc 

     

     

    That's the difference between a newbie and an expert ☺️

    Link to comment
    Share on other sites

    just want to share my code

     

     

     

     

    NB: in header of this message - samples. actually  I have ~20 ligthing devices controlled by this script

    Edited by 10der
    Link to comment
    Share on other sites

    • 1 month later...
  • Topic Author
  • On 8/4/2020 at 8:34 AM, 10der said:

    just want to share my code

     

    NB: in header of this message - samples. actually  I have ~20 ligthing devices controlled by this script

     

     

     

    Great script @10der! It is working :-) I added the script to a Quick App using the Multilevel sensor as template, was that correct?

    I got a question. I don't want to turn off the light in a room when my TV is on. How is that possible in your script? Could you help me out? I got a global variable that determines the status of my TV. Does your script support this function by default? Else I will try to integrate it myself.

     

     

     

     

     

    Edited by chiel-s
    Link to comment
    Share on other sites

    51 minutes ago, chiel-s said:

    sing the Multilevel sensor as template, was that correct?

    I use general. I do not want use controls on the face.

     

    52 minutes ago, chiel-s said:

    I got a global variable that determines the status of my TV. Does your script support this function by default? Else I will try to integrate it myself.

    yes. you can.

     

    just make minor fix. 

    in HC3 i have disable it by default,

    1 minute!

     

    "Motion_Lights (4).fqa" 

    fixed

     

    local lighting = {
        Test = {
            name = "Test Test ",
            sensors = {"Test1"},
            luxs = {},
            powers = {989},
            timeout = 60 * 1,
            times = {
                ["$Sunset..$SunriseTwilight"] = {
                    timeout_manual = 60 * 1
                }
            }
        }
    }

    Test1 - global var 

    can be 0..99 as dimmer

    0 / 1 like switch

    Link to comment
    Share on other sites

  • Topic Author
  • 30 minutes ago, 10der said:

    I use general. I do not want use controls on the face.

     

    yes. you can.

     

    just make minor fix. 

    in HC3 i have disable it by default,

    1 minute!

     

    "Motion_Lights (4).fqa" 

    fixed

     

    local lighting = {
        Test = {
            name = "Test Test ",
            sensors = {"Test1"},
            luxs = {},
            powers = {989},
            timeout = 60 * 1,
            times = {
                ["$Sunset..$SunriseTwilight"] = {
                    timeout_manual = 60 * 1
                }
            }
        }
    }

    Test1 - global var 

    can be 0..99 as dimmer

    0 / 1 like switch

     

    Thanks for your quick reply! I have installed the new script and it's up and running.

    I tested it with a global variable (value is 0 or 1), but I get the following error:

     

    Please login or register to see this code.

    I added:

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    @chiel-s Yes, cuz 

    Please login or register to see this code.

    unknown for you.

    just change to

     

    local lighting = {
        Test = {
            name = "Test Test ",
            sensors = {"Test1"},
            luxs = {},
            powers = {989},
            timeout = 60 * 1,
            times = {
                ["$Sunset..$Sunrise"] = {
                    timeout_manual = 60 * 1
                }
            }
        }
    }

    or remove ovirrede condition at all

     

    local lighting = {
        Test = {
            name = "Test Test ",
            sensors = {"Test1"},
            luxs = {},
            powers = {989},
            timeout = 60 * 1,
        }
    }
    Link to comment
    Share on other sites

  • Topic Author
  •  

    Thanks!! What a great script :-) It is working! Now I get it, you can combine the TV as a "motion sensor" in the room configuraton. Brilliant.

     

    Please login or register to see this code.

     

    Edited by chiel-s
    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • 8 hours ago, jorge rintaro said:

    [email protected],

    forgive me for the stupid question, but how do I open your code for viewing (.fqa)? thankful

     

    See the post from @10der on the 4th of august :-)

     

     

      

    On 8/4/2020 at 8:34 AM, 10der said:

    just want to share my code

     

     

    Please login or register to see this attachment.

     

    NB: in header of this message - samples. actually  I have ~20 ligthing devices controlled by this script

     

    Link to comment
    Share on other sites

    On 8/4/2020 at 8:34 AM, 10der said:

    just want to share my code

     

     

    Please login or register to see this attachment.

    Hi @10der, Just uploaded your QA to my HC3, but getting error:

    07.09.2020] [12:21:00] [ERROR] [QUICKAPP623]: QuickApp crashed[07.09.2020] [12:21:00] [ERROR] [QUICKAPP623]: /usr/share/lua/5.3/json/decode.lua:74: bad argument #1 to 'match' (string expected, got nil)

    Any ideas?

    line 74:

     

    times = {
          ["$SunriseTwilight..$NightTime"] = {timeout = 60 * 30},["$NightTime..$SunriseTwilight"] = {timeout = 60 * 5}
        }
    Edited by Bodyart
    Link to comment
    Share on other sites

    to @Bodyart and others

    if you wnat to use the custom var in times?

    for example

    ["$SunriseTwilight..$NightTime"] 

    ["$SunriseTwilight..$SleepTime"] 

    ["$SunriseTwilight..$EatTime"] 

     

    etc please define this var in globals,

    Please login or register to see this image.

     

     

     

    • Thanks 1
    Link to comment
    Share on other sites

    Thanks for fast response :-D I think i will put those definition to Quickvars :-)

     

    Link to comment
    Share on other sites

    it's vars may used all QA's or scenas - so this vars should be in Global vars.

    alas.

    Link to comment
    Share on other sites

    PS: If you used some additional vars from sun calculation do not forget import my QA with 

    Please login or register to see this image.

     

    ths QA alos update globalvars with actial values.

     

    @Bodyart

    • Thanks 1
    Link to comment
    Share on other sites

    14 minutes ago, 10der said:

    hs QA alos update globalvars with actial values.

    I will add also creation of globals :-D otherwise one must add them manually....

     

    Link to comment
    Share on other sites

  • Topic Author
  • @10der, is it possible to configure settings for hue lights? Such as:

     

    Please login or register to see this code.

    Would be great. The last piece to finalize my light automation :-) I have tried 'level' but that seems not be working for Hue lights.

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