We have moved at community.getvera.com

Author Topic: Scene to turn light on if door unlocked, only between sunset and sunrise  (Read 25277 times)

Offline mpenda

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +1/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #15 on: October 27, 2009, 12:30:30 pm »
Ah. That's MUCH simpler.
Thanks.
v1.0.980, HA09C, HA07C, WDTC-20, HRDS1, BLC131A, SM103, ZIR000, HA-18WD, ZRW103, HA02C, HA03C

Offline LVince

  • Sr. Newbie
  • *
  • Posts: 43
  • Karma: +0/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #16 on: October 27, 2009, 08:29:09 pm »
I noticed with my Intermatic switches, if the bulb is burned out, the switch will not turn on.  So testing if a switch is ON may not be foolproof.  Somewhere else in the forums, I saw Luup code for sunrise/sunset.  Just something to think about :-)
Vera (1.0.939), HA07, HA02, (4) HA06,(2) HA04C, HA03 and a WDHA-12R.
Retired: ThinkEssentials, HomeZIX, X10

Offline mpenda

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +1/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #17 on: October 27, 2009, 09:13:09 pm »
Are you talking about an Intermatic lamp module or a wall switch? From what I read, the plug in lamp modules need to have something plugged in to work. I haven't had much experience with the wall switches, but I know wall outlets work fine with or without something plugged in.

The sunrise/sunset code is quite complex. I'm hoping they'll expand the scenes a bit more.
A pseudo device would work as well, but arming and bypassing them from the scenes doesn't seem to work just yet.
v1.0.980, HA09C, HA07C, WDTC-20, HRDS1, BLC131A, SM103, ZIR000, HA-18WD, ZRW103, HA02C, HA03C

Offline denix

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1088
  • Karma: +1/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #18 on: October 27, 2009, 10:12:36 pm »
@LVinci,

If you are talking about in-wall switches w/o neutral line, then that's the way they work - they need to have an incandescent load to close the circuit and get power for the Z-Wave radio...
Veras (1, 2, 3, Lite, Plus), lots of different Z-Wave modules, Luup plugins and theater/security integration.

Offline kristinaw

  • Jr. Member
  • **
  • Posts: 56
  • Karma: +0/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #19 on: October 28, 2009, 09:21:40 am »
the device i'm querying status for is an in wall switch, not a plug in module. i'm very happy with it so far, as I know have a scene to turn lights on for me when i come in the front door and it's dark outside, which is all i wanted :)

Offline lyonne

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +0/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #20 on: January 10, 2010, 07:17:42 pm »
I guess I'll do something similar and try to set variables based on the sunrise and sunset events and then reference them in other scenes.  However, it would be cleaner if there was a way to get sunrise and sunset from Vera similar to the os.date function. 
Version 1.0.996 -- Schlage Lock, WD-20 Thermostat, HSM100 and a boatload of switches and outlets.

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 642
  • Karma: +15/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #21 on: January 10, 2010, 11:37:01 pm »
You probably already know this, but just in case: I suggest you use a virtual device to hold the "night" status rather than a global variable.

The reason being is that if Vera decides to reboot, your global variables will get reset.

If you search on "Virtual Device" in this forum, you will find a link that leads you to virtual device code that you can download and install on your Vera. Once downloaded, its easy to use. I have several copies of the virtual device, one for night, one for vacation, etc.

Offline denix

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1088
  • Karma: +1/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #22 on: January 10, 2010, 11:50:20 pm »
How did you get the virtual device to save its state between reboots?
Veras (1, 2, 3, Lite, Plus), lots of different Z-Wave modules, Luup plugins and theater/security integration.

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 642
  • Karma: +15/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #23 on: January 11, 2010, 10:08:15 am »
I do not have to do anything. Vera saves the virtual device state in her internal table, so the state survives a reboot.

Offline denix

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1088
  • Karma: +1/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #24 on: January 11, 2010, 02:53:35 pm »
Hmm, never worked for me. Is your virtual device derived from the motion sensor?
Veras (1, 2, 3, Lite, Plus), lots of different Z-Wave modules, Luup plugins and theater/security integration.

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 642
  • Karma: +15/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #25 on: January 11, 2010, 04:00:03 pm »
I use the "Binary Switch" code created by user 325xi, in thread

http://forum.micasaverde.com/index.php?topic=2138.0

Very simple implementation. I did have to do a (one-time) initialization of the device (by setting it) before I could start reading it. One thing I like about virtual devices is that you can see the value set in the Vera Interface, something that doing for global values is difficult.

For other readers looking at this thread, the LUA code I use to set the "state" is (assuming this instance of the virtual device is device #4):

luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status",1,4)

To Reset:

luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status",0,4)

and to Test (the return is a string, btw):

local sNight=luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",4)
if (sNight == "1") then


Offline woodsby

  • Beta Testers
  • Sr. Member
  • *****
  • Posts: 466
  • Karma: +1/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #26 on: January 31, 2010, 08:12:23 am »
I set up a virtual sensor, only because I didn't want to accidentally hit the on or off buttons.  But I used the following code to trip the sensor at sunrise and untrip at sunset.  You could probably even just initiate this from the test code window.  "t" means sunset and "r" means sunrise in the call_timer command.  I've only been using this a few days, but seems to work.  Please note that 46 is the device number of my virtual sensor - replace with your device number. I called this script at startup, but when I have the time, I will consolidate it into my virtual sensor code.  One more note - this script assumes that you will run it while the sun is up and that you want tripped status during the day.  Only run this once.



luup.call_timer("setSunset", 2,"t","1,2,3,4,5,6,7","")

function setSunrise()
  luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped","1", 46)       
  luup.call_timer("setSunset", 2,"t","1,2,3,4,5,6,7","")
end

function setSunset()
  luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped","0", 46)
  luup.call_timer("setSunrise", 2,"r","1,2,3,4,5,6,7","")
end
Vera1 (1.1142), Vera2 (1.1182), VRI06 (12), VRS15 (3), VRS05 (2), VRF01 (2), VRCS4 (2), ZRW113, ZRF113 (2), 45602, 45603, TZMT400 (2), FE599 (2), 99100, Thinkstick, Harmony 890Pro (2), Harmony RF Extender, Nevo S70, Nevo NC-50, Minimote, SQ Remote, SQ Blaster, EtherRain-8, Cliste ActiveRFID, TED5002

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 642
  • Karma: +15/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #27 on: January 31, 2010, 04:10:56 pm »
I set up a virtual sensor, only because I didn't want to accidentally hit the on or off buttons.  But I used the following code to trip the sensor at sunrise and untrip at sunset.  You could probably even just initiate this from the test code window.  "t" means sunset and "r" means sunrise in the call_timer command.  I've only been using this a few days, but seems to work.  Please note that 46 is the device number of my virtual sensor - replace with your device number. I called this script at startup, but when I have the time, I will consolidate it into my virtual sensor code.  One more note - this script assumes that you will run it while the sun is up and that you want tripped status during the day.  Only run this once.

Only problem with the above code is if Vera reboots itself (due to a power failure or what not), your timers get reset, and the pointers to your functions get lost (until Vera re-encounters the function declaration in a scene it is executing).

I tried putting the function declarations in the Start up code, but that did not work for me either. (It appears to me that the startup code was in a different stack than scenes, but I am just guessing).

Offline woodsby

  • Beta Testers
  • Sr. Member
  • *****
  • Posts: 466
  • Karma: +1/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #28 on: January 31, 2010, 06:55:27 pm »
I actually tested this today.  I moved the code I posted above into the functions section of the implementation file.  I put the first call_timer at the end of the init function.  The sensor was in the tripped position during the day - to indicate daytime.  I unplugged for 5 minutes about an hour before sunset.  When I plugged it back in, the virtual sensor was still in the tripped position.  It doesn't seem to lose this status when losing power.
Then, at sunset, the first call_timer worked fine, and should have in turn called the next call timer.  We'll find out in the morning, but it appears power outage does not screw this up.  Maybe for up to 23 hours, 59 minutes, if it get's unplugged right at sunset, but it'll eventually call a timer.
One more note - I misspoke earlier - the code worked when I ran it in the test lua window.  I tested it in the startup lua code today, and it didn't work.
Vera1 (1.1142), Vera2 (1.1182), VRI06 (12), VRS15 (3), VRS05 (2), VRF01 (2), VRCS4 (2), ZRW113, ZRF113 (2), 45602, 45603, TZMT400 (2), FE599 (2), 99100, Thinkstick, Harmony 890Pro (2), Harmony RF Extender, Nevo S70, Nevo NC-50, Minimote, SQ Remote, SQ Blaster, EtherRain-8, Cliste ActiveRFID, TED5002

Offline michaelk

  • Hero Member
  • *****
  • Posts: 633
  • Karma: +0/-0
Re: Scene to turn light on if door unlocked, only between sunset and sunrise
« Reply #29 on: January 31, 2010, 08:50:02 pm »
Hmmm- that seems neat.

so if I'm folowing- with that code in the I_ file then we wouldn't even need to create the scenes to flip between day and nightstates? So we'd just install the device and presto chango it would all on it's own flip states at sunrise and sunset?

seems that way we would probably even be better off f there is a power failure that shuts vera down from before sunset to after sunset?  And if I am doing 'the math right' in my head using scenes based on sunrise and sunset to flip the bit wouldn't work under such conditions?