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

12 hours ago, okidoki said:

@ppeterr: how did you make Alexa speak? I have a google via sonos, could that also work?

 

 

 

 

 

I managed to do that with the help of a number of posts already here on the forum.

There are a number of smart users who have put it together. I've tweaked that a bit here and there for my purpose. When I search on TTS and Sonos, I get enough results that shows it will be possible for you too.

 

I'd say get on with it. Open a topic and I'll take a look with you.

I don't have a google home myself, but I'm pretty sure others will help.

 

[edit] I just found this, a sonos player with TTS, you only need something to run Node.js on - like a rpi.

 

 

Edited by ppeterr
Link to comment
Share on other sites

Guest Benrive

Hi again @SmartHomeEddy,

 

How are you?.
I have returned to my small changes to regulate the intensity when turning on depending on the amount of lux.
I must have a problem with the variables or how I interpret them, because I can't get the routine to work.

Can you give me some advice?.

 

This is a variables.

 

 

local lux = {65-- ID's the Lux just the show the lux level, nothing more
local Bridgness = 99 -- Next change this value 
 
Local Funtion.
local function ON(light) fibaro.call(light,"value","Bridgness"end -- Send on witch value bridgness , 99 and then xx
local function LUX(lux) return fibaro.getValue(lux,"value"end -- Get value for lux level
 
Then Get value
 
for _,lux in ipairs(lux) do -- Show lux level at this moment
  DEBUG("Actual nivel Lux %s = %d",NAME(lux),LUX(lux))
end
 
conditional for change value in ON Bridgness.
 
if LUX(lux) <= 100 then -- I have and error , but o dont know , i have lux ( id of luxsensor ), funtion LUX(lux) , I think get value sensor ... Yes or not?.
    Bridgness = 99
elseif LUX(lux) > 101 and LUX(lux) < 150 then
    Bridgness = 80
elseif LUX(lux) >= 150 and LUX(lux) < 200 then
    Bridgness = 60
elseif LUX(lux) >= 200 then
    Bridgness = 40
end      
 
 
Many Thank's
 
 

 

 

Link to comment
Share on other sites

Guest Benrive
13 hours ago, SmartHomeEddy said:

@Benrive can you post your complete code? 

Yes, Of course.

 

local light = {55,59,60-- ID's of all the lights to turnOn and turnOff
local garageLight = 59 -- ID Garage light to exclude if already on
local laundryLight = 60 -- ID Laundry light to exclude if already on
local motion = {64-- ID's the Motions
local lux = {65-- ID's the Lux just the show the lux level, nothing more
local maxTime = 1*10  -- Maximum time to wait to turnOff the lights
local sleepTime = 5 -- Check motioon interval (default = 5)
local safeTime = 0 -- Default value to count until maxTime is reached
local debug_TAG = "Temporizador de luces: " ..sceneId -- Tag for the debug messages
local Bridgness = 99 -- Next change this value 
 
local function DEBUG(fmt,...) fibaro.debug(debug_TAG,string.format(fmt,...)) end
local function isON(light) return fibaro.getValue(light,"value"end
local function ON(light) fibaro.call(light,"value","Bridgness"end -- Send on witch value bridgness
local function OFF(light) fibaro.call(light,"value",0end
local function NAME(dev) return ""..dev..":"..fibaro.getName(dev) end
local function LUX(lux) return fibaro.getValue(lux,"value"end -- Get value for lux level
local function BREACHED(sensor) return fibaro.getValue(sensor,"value"end
 
if isON(garageLight) > 0 and isON(laundryLight) > 0 then -- Check if the garage and Laundry lights is allready on
  light = {55-- ID's of all the lights to turnOn and turnOff
elseif isON(laundryLight) > 0 then -- Check if the Laundry lights is allready on
  light = {55,59-- ID's of all the lights to turnOn and turnOff
elseif isON(garageLight) > 0 then -- Check if the Garage light is allready on
  light = {55,60-- ID's of all the lights to turnOn and turnOff
end
 
local luxAverage = 0;
for i = 1,#lux do 
    luxAverage = luxAverage + tonumber(fibaro.getValue(lux[i], "value"));
end
luxAverage = roundit( (luxAverage / #lux), 0 );             
return luxAverage;
 
for _,light in ipairs(light) do -- Turn On the lights and dimmer
  DEBUG("Enciende %s durante %d segundos",NAME(light),maxTime)
  ON(light)
end
 
for _,lux in ipairs(lux) do -- Show lux level at this moment
  DEBUG("Actual nivel Lux %s = %d",NAME(lux),LUX(lux))
end
 
if luxAverage <= 100 then 
    Bridgness = 99
elseif luxAverage > 101 and luxAverage < 150 then
    Bridgness = 80
elseif luxAverage >= 150 and luxAverage < 200 then
    Bridgness = 60
elseif luxAverage >= 200 then
    Bridgness = 40
end      
 
while safeTime < maxTime do -- Loop until maxTime is reached
  fibaro.sleep(sleepTime*1000)                 
  safeTime=safeTime+sleepTime 
  DEBUG("Segundos encendido %d hasta %d segundos",safeTime,maxTime)
  for _,motion in ipairs(motion) do 
    if BREACHED(motion) then -- Check se Motion violado(s)
      DEBUG("Hay movimiento,reseteo tiempo %s",NAME(motion))
      safeTime = 0 -- Reset safeTime 
    end
  end
end 
 
for _,light in ipairs(light) do
  DEBUG("Apago %s",NAME(light))
  OFF(light)           -- TurnOff the lights
end
Link to comment
Share on other sites

I think you have to put the “if luxAverage <= 100 then ” part above the “for _,light in ipairs(light) do” part. That way you first set the brightness level and then you turn on the lights at the right brightness level. 
 

Or do you get an error message?

Link to comment
Share on other sites

Guest Benrive
On 9/10/2021 at 10:12 PM, SmartHomeEddy said:

I think you have to put the “if luxAverage <= 100 then ” part above the “for _,light in ipairs(light) do” part. That way you first set the brightness level and then you turn on the lights at the right brightness level. 
 

Or do you get an error message?

 

Hi, @SmartHomeEddy.

 

I have reset my home center to change the motor to Zwave 3. I have to reconnect all the zwave, when I have it I will try again. Luckily I only had 4 or 5 units connected out of the almost 40 that I will have.

 

I'll try everything and tell you, but I remember I had an error with a conditional.

I tell you as soon as it purifies to try

Link to comment
Share on other sites

  • 3 weeks later...

Thansk for sharing this Chiel-S!

 

I used the code to build my own countdown solution. It is more basic then you created (only 1 LUX sensor, no difference in day and night).

Link to comment
Share on other sites

  • 1 month later...
W dniu 2.08.2020 o 20:20, chiel-s napisał:

 

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! 

 

 


 

 

 

Hi!!

 

This is awesome! Great job! :)

One question. I need to make groups of lights and launch it when exact motion sensor is breached.

In each room I have one sensor and group of lights. I like that it would turn lights on in different setup depending on time of day but is it possible to divide it in groups and lounch only few of lights when one sensor is breached?

I have it in multiple scenes but it would be perfect if it could be done in one quickapp.

Link to comment
Share on other sites

  • 1 month later...
Guest Benrive

Hello @SmartHomeEddy and Happy new year.

 

I am already in the new house and with almost all the modules installed.

I am trying to make this scene work with different brightness levels depending on the lumen level.
But I am having an error in the line of the condition where I compare and and where do I capture if the button has been pressed and scene 14 launched (In this case you must leave it on and interrupt the code).

 

First error in line 

if LUX(lux) <= 10 then -- Ther first error ( LUX is a function )

And second error

if isON (scene == 14)  then -- Check the scene activation SECOND ERROR

 

Can help me ?

 

 

Please login or register to see this code.

 

Link to comment
Share on other sites

I have a simple brain. I cannot handle this:

 

Please login or register to see this attachment.


 

The name “lux” is used as local variable, function, within the function() as variable and lux in  ipairs(lux). I hope Fibaro can handle, I can’t ?

 

Why not use a different name for each? 
 

 

 

 

8 hours ago, Benrive said:

Please login or register to see this code.

 

should that be: isON(14)

Link to comment
Share on other sites

Guest Benrive
14 hours ago, SmartHomeEddy said:

I have a simple brain. I cannot handle this:

 

Please login or register to see this attachment.


 

The name “lux” is used as local variable, function, within the function() as variable and lux in  ipairs(lux). I hope Fibaro can handle, I can’t ?

 

Why not use a different name for each? 
 

 

 

 

 

should that be: isON(14)

 

Thank's @SmartHomeEddy for your comments.

 

I have changed, as you say, the variables for others.
LUX for LUM and IsON I have corrected it, but in the comparison I still have this error.
Something is escaping me that I honestly do not know what it can be.

 

I have this error in the first comparison 

The funtion

 

local function LUM(lux) return fibaro.getValue(lux,"value"end -- Change LUX for LUM
----
 
if LUM(lux) <= 10 then 
    Bridgness = 60
elseif LUM(lux) > 10 and LUM(lux) < 15 then
    Bridgness = 50
elseif LUM(lux) >= 15 and LUM(lux) < 25 then
    Bridgness = 40
elseif LUM(lux) >= 25 then
    Bridgness = 20
end 

[ERROR] [SCENE64]: (load):21: attempt to compare function with number

 

In this part, It doesn't recognize that I pressed to launch scene 14, it doesn't do anything.

 

if isON(14)  then -- Check the scene activation
      DEBUG("Se ha pulsado %s",NAME(scene))
      pulsado = 1 -- Reset scene
end
 
 
Link to comment
Share on other sites

I hope the “lux” in “LUM(lux)” doesn’t fights with the “local lux = {216}”
 

I would expect LUM(lux) returns a number, but apperently not.
You could force is with tonumber(LUM(lux))

 

or in the function:

tonumber(fibaro.getValue(lux,"value"))

 

But first I would get rid of the different lux things. 

Link to comment
Share on other sites

Guest Benrive
30 minutes ago, SmartHomeEddy said:

I hope the “lux” in “LUM(lux)” doesn’t fights with the “local lux = {216}”
 

I would expect LUM(lux) returns a number, but apperently not.
You could force is with tonumber(LUM(lux))

 

or in the function:

tonumber(fibaro.getValue(lux,"value"))

 

But first I would get rid of the different lux things. 

 

Changed local sensor for lux 

local luxSensor = {216}
changed funtion
local function LUM(lux) return tonumber(fibaro.getValue(luxSensor,"value")) end
 
And compare 
 
if LUM(lux) <= 10 then 
    Bridgness = 60
 
I have the same error
[ERROR] [SCENE64]: (load):18: Assertion failed: Expected number
 
My brain is locked?

 

Edited by Benrive
Link to comment
Share on other sites

I see you also don’t know which “lux” does what

 

2 minutes ago, Benrive said:

local function LUM(lux) return tonumber(fibaro.getValue(luxSensor,"value")) end


should be:


local function LUM(lux) return tonumber(fibaro.getValue(lux,"value")) end

 

Link to comment
Share on other sites

Guest Benrive
21 hours ago, SmartHomeEddy said:

I see you also don’t know which “lux” does what

 


should be:


local function LUM(lux) return tonumber(fibaro.getValue(lux,"value")) end

 

 

Oppppss, I Have the Same error.

I Copy the full scene again

 

Please login or register to see this code.

 

(load):18: Assertion failed: Expected number

Edited by Benrive
Link to comment
Share on other sites

Guest Benrive
5 hours ago, SmartHomeEddy said:

I think you mean with lux your luxSensor

 

No, there is no way. I have the same error in the lines of the conditionals.

When I remove them, everything works fine but I don't have different light levels.

 

The error  it's here.

 

Please login or register to see this code.

Edited by Benrive
Link to comment
Share on other sites

Guest Benrive
22 hours ago, SmartHomeEddy said:

Loose the {} for luxSensor

I do not understand what you mean

Link to comment
Share on other sites

You get an error: 
(load):18: Assertion failed: Expected number

 

Your variabel:

luxSensor = {216}

 

Try:

luxSensor = 216

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