We have moved at community.getvera.com

Author Topic: Working Example: Turn on Light Brightness based on Time of Day  (Read 3657 times)

Offline Chris H.

  • Full Member
  • ***
  • Posts: 199
  • Karma: +3/-0
Working Example: Turn on Light Brightness based on Time of Day
« on: November 06, 2012, 11:40:25 pm »
It took a little while but I thought I would share my working code. Thank you to Flyarmy for a great starting point based on your scene.

What it does:
Triggered by motion from a foscam camera on my sons crib, Vera will now turn on a lamp with a Dimmable CFL bulb connected to a GE 45602 to 100% brightness from 6am - 10pm and 10% brightness from 10pm - 6am for 10 minutes than shut it back off.

Code sample:
Code: [Select]
-- Find the status of the light
local LightStatus = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus", 26)

-- Get the current hour
local t = os.date('*t')
local current_hour = t.hour

-- Set Hour for Hight Light Levels
local light_high_min = 6           -- 6:00 am
local light_high_max = 22          -- 10:00 pm

-- Check to see if it is between 6am & 10pm & if so turn on light 100%
if (current_hour > light_high_min) and (current_hour < light_high_max) then
    luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "100"}, 26) 
    return true
-- Check to make sure the light was not turned on manually then set to 10% brightness
elseif (tonumber(LightStatus) < 30) then
    luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "10"}, 26) 
    return true
end

The reason I return true on both conditions is because I have a delayed action on the advanced tab for the scene that turns the light back off. I also have another scene that is triggered by the light being turned on to turn it back off after 10 minutes incase my wife turns it on manually instead of being triggered by the camera motion detection.

I hope this will be useful to someone else or at least a starting point.
Vera Lite (1), Trane Thermostat (1), Yale Deadbolt (1), Foscam FI9821w (4), GE 45602 (1), GE 45603 (2), Intermatic CA600(11)/CA3000(6)/CA5100(4)/CA3500(3), Aeon Labs MicroSmartSwitch (1), Aeon Door/Window Sensors (3), EnvisaLink 3 on DSC 1616 (1), OpenSprinklerPi

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: Working Example: Turn on Light Brightness based on Time of Day
« Reply #1 on: November 07, 2012, 07:04:01 am »
Hello Chris H.,
I'm wanting enter in the programation world...(lua code)

where do you put this code ?

thanks !

Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Working Example: Turn on Light Brightness based on Time of Day
« Reply #2 on: November 07, 2012, 10:51:59 am »
@Piwtorak,

For maintainability (you have a big, commercial project, right?), perhaps also consider doing this codeless, with the Combination Switch and VirtualClock plug-ins for example.
Dezwaved at the moment...

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: Working Example: Turn on Light Brightness based on Time of Day
« Reply #3 on: November 07, 2012, 11:22:14 am »
for this moment I bought a big quantity of zwave devices and vera3 controller. soon I have a big appartment to execute starting january 2013. and I have many situations to solve in that. I will try this plugins...I´m only using the sqblaster plugin and wunderground weather plugin installed in my vera. maybe I need hire extra labor for the project. I will use 3 vera3 units.
Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline Chris H.

  • Full Member
  • ***
  • Posts: 199
  • Karma: +3/-0
Re: Working Example: Turn on Light Brightness based on Time of Day
« Reply #4 on: November 07, 2012, 11:56:58 am »
Piwtorak - I went to the Automation tab and clicked new scene, then clicked the advanced tab, then named the scene and clicked the drop box next to the name and chose manage delays and added a 10 minute delay. Next choose the device from the drop down list and click add, then choose the device and select SetLoadLevelTarget and type in 0 to have the light turn off. Now go to the LUUP tab and put the code in there. In my example the number 26 is my device ID, you will have to change that number to your device ID.

I haven't messed with the combination switch or virtual alarm yet as oTi@ mentioned.

I hope this helps.
Vera Lite (1), Trane Thermostat (1), Yale Deadbolt (1), Foscam FI9821w (4), GE 45602 (1), GE 45603 (2), Intermatic CA600(11)/CA3000(6)/CA5100(4)/CA3500(3), Aeon Labs MicroSmartSwitch (1), Aeon Door/Window Sensors (3), EnvisaLink 3 on DSC 1616 (1), OpenSprinklerPi

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: Working Example: Turn on Light Brightness based on Time of Day
« Reply #5 on: November 07, 2012, 04:48:37 pm »
Oti@

I have installed combination switch...do you have some documentation to do it runs ?

for this case....

when I turn on 1 switch the another turns on too...and when off, off the another too.

thanks.
Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline oTi@

  • Community Beta
  • Master Member
  • ******
  • Posts: 4041
  • Karma: +32/-6
  • UI what ?!
Re: Working Example: Turn on Light Brightness based on Time of Day
« Reply #6 on: November 11, 2012, 08:48:15 am »
Perhaps something like so.

You require:
- Something that says: 'the motion sensor is tripped and it is night time'.
- Something that says: 'the motion sensor is tripped and it is day time'.

'Something' = Combination Switch
'Motion sensor' = Motion Sensor
'Night time / day time ' = Virtual Clock

So you need:
2 Combination Switches
1 Virtual Clock
1 Motion Sensor

Set up the Virtual Clock so it is 'tripped' during night time (or day time, whatever you prefer).
Set up one Combination Switch to be 'on' when the Motion Sensor is 'tripped' and the Virtual Clock is 'tripped'.
Set up the other Combination Switch to be 'on' when the Motion Sensor is 'tripped' and the Virtual Clock is 'not tripped'.

The proper Combination Switch should now turn on when there is motion during the day, or during the night. You can then use that as triggers in scenes.

Set up a scene with trigger 'Virtual switch status changes'/'On' based on one Combination Switch to turn on the light to say 100%.
Set up a scene with trigger 'Virtual switch status changes'/'On' based on the other Combination Switch to turn on the light to say 10%.
Set up a scene with trigger 'An armed sensor is tripped'/'Device is not tripped' based on the Motion Sensor to turn off the light.


Only partially tested, so up to you to see if it works, possibly tweak it, and report back.
« Last Edit: November 11, 2012, 08:59:43 am by oTi@ »
Dezwaved at the moment...