light on when lux is lower than 200

Moderator: leecollings

Post Reply
desertdog
Posts: 84
Joined: Sunday 14 August 2016 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Netherlands
Contact:

light on when lux is lower than 200

Post by desertdog »

I want to turn the lights on inside when i am at home (VS - Present) it's daytime (VS - Daytime) and the outside lux meter (Lux) is below 200. I have tried to do this with a blockly script but I can't make it react to the change of the value of the Lux sensor below 200. So now i am having another try with Lua.

Code: Select all

commandArray = {}

if (otherdevices_svalues['Lux'] < "200" and otherdevices['VS - Present'] == 'On' and otherdevices['VS - Daytime'] == 'On') then
    print("Lux is Low")
end
return commandArray 
The problem is this script keeps firing up to ten times a second even when the Lux is above 200.
I have been searching this board and the net but couldn't find any script to help me on the way:

- what is wrong with my script sop far, and/or:
- does anyone know about an example script to help me, and/or
- Is this also doable with a blockly script
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: light on when lux is lower than 200

Post by DanM »

This is my code. It changes the variable day_night to either day or night depending on lux above or below 200.

Code: Select all

-----------------------------------------------------
-- Lux Level Script
-----------------------------------------------------
if tonumber(otherdevices['Conservatory Lux']) <= 200 then
if ( uservariables["day_night"] == "day") then
commandArray['Variable:day_night']= "night"
commandArray['SendNotification']='Lux#Light Levels Low#0'
end
else
print("=====================================================")
print('Lux level >>> ' .. otherdevices['Conservatory Lux'])
print("=====================================================")

if ( uservariables["day_night"] == "night") then
commandArray['Variable:day_night']= "day"
commandArray['SendNotification']='Lux#Light Levels High#0'
end
end

desertdog
Posts: 84
Joined: Sunday 14 August 2016 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Netherlands
Contact:

Re: light on when lux is lower than 200

Post by desertdog »

Thanks. I will have a look and post my final script if everything works
desertdog
Posts: 84
Joined: Sunday 14 August 2016 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Netherlands
Contact:

Re: light on when lux is lower than 200

Post by desertdog »

Sorry, one more question about the script. Is it run as a All, Device or Time script?
desertdog
Posts: 84
Joined: Sunday 14 August 2016 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Netherlands
Contact:

Re: light on when lux is lower than 200

Post by desertdog »

I created a UserVariable 'LightLevel', type 'string', current value 'day'
My Lux Utility is named 'Lux'

My changed code is:

Code: Select all

-----------------------------------------------------
-- Lux Level Script
-----------------------------------------------------
if tonumber(otherdevices['Lux']) <= 200 then
if ( uservariables["LightLevel"] == "day") then
commandArray['Variable:LightLevel']= "night"
commandArray['SendNotification']='Lux#Light Levels Low#0'
end
else
print("=====================================================")
print('Lux level >>> ' .. otherdevices['Lux'])
print("=====================================================")

if ( uservariables["LightLevel"] == "night") then
commandArray['Variable:LightLevel']= "day"
commandArray['SendNotification']='Lux#Light Levels High#0'
end
end
but I keep getting the error:

Code: Select all

Error: EventSystem: Lua script Lux did not return a commandArray
Seems that I am doing something wrong, but I don't see what
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: light on when lux is lower than 200

Post by DanM »

Thats my fault.. I only sent you the part of my script that deals with lux. Its not a full script.

You need ths at the start:

Code: Select all

--Initilise a command array
commandArray={}
And this at the end:

Code: Select all

return commandArray 
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: light on when lux is lower than 200

Post by DanM »

Also.. this wants to be a time script so the light level is checked every minute.
desertdog
Posts: 84
Joined: Sunday 14 August 2016 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Netherlands
Contact:

Re: light on when lux is lower than 200

Post by desertdog »

Is there a way to run it every 5 minutes? As the Lux value is also only changed every 5 minutes.
So basicly it has to run only every 5 minutes, or even better (if possible) only when the Lux value has changed, since it doesn't change at night
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: light on when lux is lower than 200

Post by Nautilus »

desertdog wrote:Is there a way to run it every 5 minutes? As the Lux value is also only changed every 5 minutes.
So basicly it has to run only every 5 minutes, or even better (if possible) only when the Lux value has changed, since it doesn't change at night
try this:

Code: Select all

commandArray = {}
if devicechanged['Lux'] and tonumber(otherdevices['Lux']) < 200 and otherdevices['VS - Present'] ==  'On' and otherdevices['VS - Daytime'] ==  'On'  then
    print("Lux is Low ("..devicechanged['Lux']..")")
end
return commandArray
And save it as a device scrip (runs only when Lux changes)...

Also, should be no problem to do with blockly. You'll probably want to have some additional conditions (like trigger only when light is off to avoid unnecessary repeats. Usually these types of events are based on movement sensor and not just lux changes...)
User avatar
PeGe
Posts: 25
Joined: Tuesday 31 January 2017 14:21
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6328
Location: Sollentuna, Sweden
Contact:

Re: light on when lux is lower than 200

Post by PeGe »

To restrict the execution of the main logic in a TIME script to 5 minute intervals, check the current minute value with an 'IF' statement and put your old commands inside it:

Code: Select all

commandArray = {}

local m = os.date('%M')

if (m % 5 == 0) then
        print("Doing my thing now...")

        -- Your main 'IF/THEN/END' section is placed in here, where it
        -- will only be executed if the "MODULO 5" returns a 0 value.

end

return commandArray
This method is widely recommended, e.g. on the 'wiki' pages. But again; Only for TIME type scripts!

For your specific purpose however, it's smarter to use a DEVICE script that triggers on a value change instead, as recommened in an earlier posting.

/P-G
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest