Author Topic: Plugin: DelayLight  (Read 9627 times)

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 759
  • Karma: +115/-1
Plugin: DelayLight
« on: February 19, 2018, 07:15:45 am »
DelayLight is my version of a time-delay light/load control. It will turn off a configured set of lights after a delay period, optionally using one or more sensors to determine presence. Sensor triggers can also turn lights on. Sensor-based triggering turns lights on for an automatic timing interval, while manual activation of a light uses a separate manual timing interval.

I wrote this plugin in late-2017 when I had to rebuild my Vera configuration from scratch, and I decided not to use the same approach I had used for years prior. Until now, this plugin was just a tool I kept for my own use, and it didn't even have a UI--it was configured by directly manipulating its state variables. But recently, some of the older plugins that implemented this kind of functionality seem to have lost their maintainers and their future has become less certain, so I decided to package up my expression of a solution for public use.

The GitHub repository for this project is here: https://github.com/toggledbits/DelayLight

Documentation for the project is also found in its GitHub repository. Please post issues or questions in this thread.

DelayLight can be installed from the Vera plugin marketplace (search "DelayLight" with no space between words), or using the AltAppStore (ALTUI users).

DelayLight is free to use, and if you find it useful, please make a small donation to support its ongoing development.


REVISION HISTORY
Note: You can always see the current release info and latest changes by looking at the CHANGELOG.md file in the Github repo.

2018-08-19: Version 1.7 released (expected approval/availability tomorrow Monday 20th). This version fixes a deployment error in posting 1.6 to the Vera Plugin Marketplace that was creating problems for fresh installs. Users of AltAppStore/openLuup are not affected, and there are no changes to the code of this release.

2018-08-05: Version 1.6 released. This version allows devices that implement SwitchPower1 to be used as inhibitors, and corrects a bug in the initialization of inhibitor tests.

2018-07-29: Version 1.5 released. This version allows the timer to not turn on lights if there's an "on" delay and the trigger sensors all reset before it expires; handles change in load level to a dimmer that is already on as a manual trigger; adds ability for manual-on to not "set scene" by turning on all "on" list devices, just leave everything under manual control. See the Github repo's CHANGELOG.md for more detail on these changes.

2018-07-02: Version 1.4 has been released to the Vera Plugin Marketplace and AltAppStore. This version fixes a bug in "Mode 2" timer restrictions (don't start timing until all triggers have reset).

2018-06-24: Version 1.3 has been released to the AltAppStore and Vera Plugin Marketplace. See changelog.

2018-06-11: The "stable" branch of DelayLight has been enhanced to add Inhibit devices and active time periods. There is no UI for these functions yet, so you'll need to edit state variables if you want to try them. Also, if running on openLuup, this version checks to make sure you're not using a version of openLuup that a child startup bug.

2018-04-12: A beta version based on 1.2/1.3dev is available for openLuup and installable using the AltAppStore.

2018-03-19: Version 1.2 is now available in the Vera plugin marketplace. This version creates timer devices as children of the parent controller device, making it a single-instance plugin in which all timers share the same code. This should result in a much smaller in-memory footprint for systems with lots of timers (I have 16 in 9 rooms, for example). A single Luup timer/delay task is used as well, so it's very resource-efficient.

2018-02-26: Version 1.1. This was a maintenance release that includes some code cleanups and an extension of the status interface for additional reporting when needed. Status reports are user-initiated by requesting http://your-vera-ip/port_3480/data_request?id=lr_DelayLight&action=status

2018-02-19: Version 1.0 has been released in the Vera plugin marketplace.
« Last Edit: August 19, 2018, 10:58:55 am by rigpapa »
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline wilme2

  • Hero Member
  • *****
  • Posts: 1230
  • Karma: +29/-13
Re: Plugin: DelayLight
« Reply #1 on: February 19, 2018, 10:50:21 am »
I like the idea.  I use PLEG for this today, but having an easier way to automate lights would certainly speed adoption.  I agree this is such a common use case that Vera really should have this as a built-in module.

In your design, would you have a copy of the plug-in for every room with automatic lights?   I have at least 13 "rooms" with automated lighting, around 17 switches, with full on-off functionality.  Plus a few more switches that are automatic off only...
Long Live UI5!  (OK finally made the switch to UI7 in January 2018, and am pretty happy....)

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 759
  • Karma: +115/-1
Re: Plugin: DelayLight
« Reply #2 on: February 19, 2018, 11:19:18 am »
My own production install has these spread all throughout the house. Most bathrooms have at least two: lights and fan. My master ensuite has five (main lights (for 5 dimmers), shower light, WC light, WC fan, main fan).

I also used PLEG (four licenses worth), but I decided to not include it in my configuration when I did a full rebuild a few months ago.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 759
  • Karma: +115/-1
Re: Plugin: DelayLight
« Reply #3 on: March 16, 2018, 02:46:22 pm »
@wilme2, I took your inquiry as a suggestion, since these timers have a way of multiplying like rabbits (keep on coming up with ideas/uses around the house).

I will be releasing v1.2 of the plugin this weekend, for Vera's marketplace approval on Monday 3/19, that is a single-instance version: one copy of the plugin for as many timer child devices as you want to create. Existing devices from prior versions will be converted to children with settings copied.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 759
  • Karma: +115/-1
Re: Plugin: DelayLight
« Reply #4 on: April 12, 2018, 11:27:48 am »
A beta version for openLuup is now available for installation via the AltAppStore.
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline RyanS

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: Plugin: DelayLight
« Reply #5 on: April 18, 2018, 11:27:08 pm »
Great work Rigpapa

Is there a way to only activate the lights/load if it's night time.



Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 759
  • Karma: +115/-1
Re: Plugin: DelayLight
« Reply #6 on: April 19, 2018, 07:13:10 am »
Working on it
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline Tillsy

  • Full Member
  • ***
  • Posts: 207
  • Karma: +13/-5
Re: Plugin: DelayLight
« Reply #7 on: May 08, 2018, 06:31:45 am »
G'day rigpapa

Your plugin sounds fantastic, especially that it is lean and mean given Vera's limited resources, so I have just installed your plugin and done the following:
  • Clicked the Control Panel
  • Clicked Add Timer
  • Waited for the process to complete
  • Gone back to my devices list and found the new DelayLight Timer

I have then:
  • Edited its Device name and assigned room, then clicked Saved Changes
  • Gone back to the devices list and found no change
  • Refreshed, still no change
  • Repeated the editing and save
  • Repeated the refresh
  • Continued to repeat

I haven't done anything else, nor have I installed anything else - clean vanilla Vera but with a crapload of Fibaro dual switches and Fibaro dimmers.  Hoping you might spot something obvious I have overlooked...

Offline Tillsy

  • Full Member
  • ***
  • Posts: 207
  • Karma: +13/-5
Re: Plugin: DelayLight
« Reply #8 on: May 08, 2018, 06:44:41 am »
Okay that's weird... I tried setting just the room and saving, it moved.  I then edited the name and saved, it worked.

So I added a second timer and edited both in one shot - also worked.

Looks like my nice clean Vera wasn't playing nice after all.

Have configured the two test ones up.  One of those rooms the light is already on, so the timer has started itself.  VERY nice touch with the animated hourglass :) :) :) :)

Offline Tillsy

  • Full Member
  • ***
  • Posts: 207
  • Karma: +13/-5
Re: Plugin: DelayLight
« Reply #9 on: May 08, 2018, 08:09:53 am »
Okay I have 16 set up and working great - though strangely many settings had to be set multiple times to stick, but probably because I was ploughing through them.

Only run into one drama.  I have a dimmer light that is triggered by two different sensors - no worries.  That dimmer is set to retain its dim level, as I have various scenes that will automatically set a relevant dim level at relevant times.  Works fantastic because the sensors and events simply turn the dimmer on and it comes on at its existing dim level.

However, when I use DelayLight to control this dimmer it insists on a dim level.  I don't actually want the dim level touched, I just want it turned on or off.  Can that be done - do I set the dim level to -1 or leave it at 100 to simply turn on, (as full brightness is actually 99), or will DelayLight specifically set a dim level?

Cheers!

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 759
  • Karma: +115/-1
Re: Plugin: DelayLight
« Reply #10 on: May 11, 2018, 05:58:49 pm »
I've noted some interesting intrinsic behavior in UI7 API response with respect to moving off the control panel pages, and that could be related. But more likely, the cause is simply that the plugin UI causes a reload when devices are changed in the configuration (watches, etc.) at the time you return to the dashboard. Timing parameter changes, on the other hand, are more easily handled on-the-fly and do not cause this reload. So, I'm guessing that you were probably running through the interface a little faster than UI7 and Vera could actually deal with while the reload was happening.

On the dimming level, DelayLight specifically sets the dim level as you've discovered, but I see your requirement. I think most users believe 100 is full brightness, so I think the option to leave the dimming level field blank and have that treated as "on without level change" (for "on" list devices) seems best. What do you think about that?
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline Tillsy

  • Full Member
  • ***
  • Posts: 207
  • Karma: +13/-5
Re: Plugin: DelayLight
« Reply #11 on: May 11, 2018, 08:27:03 pm »
Mate I am really loving this plugin - it is fantastic in absolutely every regard, seriously well done!  As I said I have 16 of them set up now and they are awesome!

Setting the dim level blank to instead have a binary on would be perfect, yes.  This would enable me to configure my two multi-sensors into that DelayLight, presently it's just reacting to the initial "on" which is sort of working but also causing some issues with the sensors being out of sync with one another.  If I could add them both in as a trigger without causing the dim level to change that would be awesome!

I have also thought of two other great uses for this plugin, but would depend upon your release notes commenting consideration of monitoring other parameters:

1. I would like to react to power consumption of smart switches.  So if power usage drops below a certain threshold then the DelayLight kicks in, and only after it stays below that level for a certain amount of time would something be triggered.  At the moment best I can think is a scene that detects wattage dropping below a certain level, and using that to trigger the DelayLight, but I'm not sure I want the potential of repetitive scene triggers.  Still thinking about this, but the ability to react to the wattage parameter might be cool.

2. Of more importance, I will be reacting to the door lock on my other home.  I have pre-set a scene for this already, so if the door is unlocked then the DelayLight is triggered.  So it'll already work once I get out there with a smart switch - whenever the front door is unlocked the smart switch will activate for 36 hours, and presumably if the door is unlocked again during that 36 hours and the scene triggers again then the re-trigger of the DelayLight will restart the countdown?  Thus the smart switch will automatically be on so long as anyone has come - so should work with existing capabilities, but another area where your thoughts of being able to use other parameters could be helpful... as the DelayLight could directly react to the door lock without the use of a scene?

Offline rigpapa

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 759
  • Karma: +115/-1
Re: Plugin: DelayLight
« Reply #12 on: May 11, 2018, 09:51:58 pm »
It always was my plan to have DelayLight react to a much wider range of devices than just those that implement SecuritySensor1 as it does now. I actually had that written and was testing it for version 1, but I started to wonder why I should go to the trouble if scenes can be used to trigger DelayLight out of the box. Given that and the considerable additional complexity, I chose to stash that code and go with the simpler trigger path for version 1, put it out there, and see what happens. I think scene-based triggering works fine, although I can also see that it may add some complexity for the user by de-coupling the trigger decision away from DelayLight's configuration, rather than having it all in one place. I'm still weighing benefits and costs there. DelayLight, in my mind, has a clear raison d'etre: to be very simple, light-weight and reliable step between the void that Vera has left for this use case (reliable on/off delay of a load), and the considerable weight and complexity introduced by PLEG (it's awesome, but a big solution for this small problem). That keeps me tipping the scale toward the simple solution of using a scene (with or without Lua), which leverages a well-established, existing interface for creating a trigger response when DelayLight's simple intrinsic capability doesn't do enough. The things that leaves unaddressed that concern me, though, are (1) many devices have considerably more triggerable conditions than the current scene logic/eventList2 structures define, (2) AND vs OR of conditions in scenes, and (3) hysteresis (e.g. trigger when value goes below X, but don't reset until value goes above Y, where Y > X, and maybe a time component as well, which may address your retrigger concerns).

On your door lock scene, yes, every time your scene "triggers" DelayLight, the timer will restart, so every unlock of your door will stretch the delay out to 36 hours beyond that event as you've configured it. Should work fine.
« Last Edit: May 11, 2018, 10:38:18 pm by rigpapa »
Author of Reactor, DelayLight, SiteSensor, Rachio, Deus Ex Machina II, Intesis WMP Gateway, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline Tillsy

  • Full Member
  • ***
  • Posts: 207
  • Karma: +13/-5
Re: Plugin: DelayLight
« Reply #13 on: May 11, 2018, 10:32:39 pm »
Completely agree - I would prefer configuration not be spread everywhere yet at the same time given Vera's, shall we say, limitations I would prefer even more that DelayLight remain lean and mean.

The door lock situation I'm confident will work fine, the smart switch I'll do some testing and see how it goes :)

Offline HSD99

  • Sr. Member
  • ****
  • Posts: 305
  • Karma: +11/-0
Re: Plugin: DelayLight
« Reply #14 on: May 14, 2018, 12:09:41 pm »
I've been evaluating DelayLight on my test VP running 1.7.3798 and it does exactly what it says it does.  I'll be installing it on my production system (VP running 1.7.3232---it's stable and does what I need) and replacing the workarounds or Vera delays I've used to get this function.

While I can envision some other features/functions, I'm strongly drawn to the idea of lightweight and simple. Thanks for doing this!