[Release] Plugable Lighting

This is something I've been playing with for a few weeks, and maybe of use to more advanced users, or those who want to dive into code. I figured I'd share it..because it's fun to toil away in your own world, but maybe it could help others.

So my goal was to make a lighting app that ran in under 150ms, so when you see the blink on the motion sensor, or blink on the contact sensor the lights come on "instantly." Simple lighting does this, but:

  1. I wanted something more complicated than Simple lighting
  2. I hit several problems with Motion lighting. Maybe I didn't understand it...maybe it had bugs, but I got annoyed by it and went to RM4.
  3. I ended up with 10 RM4 rules that were almost the same
  4. I wanted something faster than RM4 to control lights via motion/switches/etc.
  5. I wanted to be able to complicate it, and maybe sacrifice speed for but only for certain lights

Known issues:

  1. Don't use this if your lights don't report state back. It only applies deltas, so if your light/switch/whatever is reporting off, but it's actually on then it won't get switched on/off consistently.
  2. Probably a ton of others, I warned you, it seems to work for me and gets past the GAF (Girlfriend acceptance factor)
  3. This is probably built backwards. It's very easy for a child to call parent.function() so instead of keeping a list of child functions a parent can call, it would seem easier to keep a parent library of common functions and exposing it to the child. Ah well...next time?
  4. Always click done in the parent before adding children or your edits in the parent get lost. Arg.

Features: (you're still reading?)

  1. Built around a base app, PlugableLights. You will have to install one of these, App->Add User App. one for each motion or contact controlled lights.
  2. The base app turns on lights based on a motion sensor, or contact switch opening, and turns them off after a period when motion stops, or the contact closes.
  3. Optionally install as many of the feature plugins as you like.
  4. Plugin Mode: Change the level, or colortemp per hub mode
  5. Plugin Blocker: Have a (virtual) contact sensor block turning on lights
  6. Plugin Delay Off: Longer motion is active the longer the off time becomes when motion ends. Avoids the "sitting still, off, wave hands"
  7. Plugin Force On: Have a (virutal) switch turn on and force the lights on regardless of motion
  8. Plugin Short Off: If there's a very short Motion Off->On transition there's almost certainly someone there, so it adds a longer off period
  9. Plugin Max On: turn the lights off after a period regardless of motion/contact. Aka someone left the closet door open.
  10. The kind of neat part, you can instantiate the "plugins" more than once. For example you can force on on multiple switches by making multiple force on children. Surely this will lead to mostly more confusion than good...but I am using it.

I don't know what happens if you mix to many conflicting plugins together...for example the blocker and the force on...might work?

Feedback appreciated.

Here's what my config looks like:

5 Likes

I pushed to github about 5 little bug fixes for "Plugable Lights" to fix up a bunch of issues I've found over the last few weeks.

I'm now using this app and plugin as my main motion lighting control for my whole house.

Change log:

  1. Moved time log message into debug only
  2. Fixed off/on plugin to use lights going off/on not motion sensors
  3. Fixed delay plugin, it reported time in seconds not ms resulting in no significant increase in the delay
  4. Fix the blocker plugin, when removing block only turn on lights if motion/contact sensors are triggered.

Pushed a few more "fixes"

  1. New plugin, "Do not adjust" once a light is turned on, don't change the levels nor turn on/off lights until it turns them off. This means if you adjust the lights by hand the code won't reset your manual adjustments until it turns off then on again.

  2. Use submitOnChange for parent, so you can setup the parent, add plugins and have all the settings stick.

  3. Improve parent logging so you have a choice between nothing and an insane level of spam.

  4. Add setup/clear subscription API so children can more easily unsubscribe the parent from events and not have to call update() on the parent, which is expensive and slow and spams logs.

I've just tried out your app, and it seems pretty good so far. I haven't had enough time to play with it much, or to see what real-word issues I might come across, but I like the general idea. I do have a few suggestions/requests:

  1. Lux thresholds, so that if it's a dark day, the motion lights will activate even in Day mode.

  2. Warning before switching off. This is something I was thinking of trying to implement in RM, but would be could if you could turn it into a plugin. I'd like the lights to give me a warning before actually switching off, giving people a chance to do the hand wave before they actually find themselves in the dark! For dimmable lights, I would have them dim down and up a few times by a configurable amount, and then wait X seconds before actually switching off. For non-dimmable lights, a few flashes on/off instead of the dimming.

  3. Is it possible to put all the code into one file? I don't know if this is a restriction of Hubitats parent/child app structure, but I'd prefer not to have to keep all the plugin code in separate files, especially if this expands to the point where you could have over a dozen different plugins.

  4. A brief description of each plugin at the top of the plugin's configuration page.

I'll probably think of more at a later time, but overall I think the app is pretty cool :slight_smile: Thanks for making this start, and keep up the great work!

@jason-lane Thanks for the input!

  1. Sounds like a good idea for a plug-in. I've moved to using hub modes "day/night/etc" but there's no reason this can't be gated by lux. :slight_smile:

  2. Should be an easy plugin. There's enough event data to do it.

  3. Sadly no. :frowning: (or I sure don't think so) Each app has to be a different file afaik, and each plugin is just a child app. This was neat when there were 2 or 3 plugins, but it's getting a bit of a headache now. :confused:

  4. For sure! I was just thinking this the other day.

@asj I've been trying the Mode plugin to dim a particular light to a different level when the house is in "Sleep" mode, but it seems to be reverting to the default level of 99% after briefly setting to 20% . Below is a snippet of my logs. Any idea what might be wrong?

[dev:1]2019-12-23 00:28:26.787 [info]Upstairs Landing Lamp level is 99

[dev:1]2019-12-23 00:28:26.783 [info]Upstairs Landing Lamp switch is on

[dev:1]2019-12-23 00:28:26.750 [info]Upstairs Landing Lamp level is 20

[dev:1]2019-12-23 00:28:26.746 [info]Upstairs Landing Lamp switch is on

[app:328]2019-12-23 00:28:26.718 [debug]turnOnEvent(): time: 117

[app:328]2019-12-23 00:28:26.716 [debug]Upstairs Light Automation: pluginExec: num plugins: 2

[app:328]2019-12-23 00:28:26.699 [info]Upstairs Light Automation turn on event

[app:328]2019-12-23 00:28:26.687 [info]turnOnEvent(): switch off -on

[app:328]2019-12-23 00:28:26.656 [info]turnOnEvent(): has setLevel 99 want: 20

[app:328]2019-12-23 00:28:26.655 [debug]turnOnEvent(): has setLevel 99 want: 20

[app:328]2019-12-23 00:28:26.644 [debug]Upstairs Light Automation: pluginExec: num plugins: 2

[app:328]2019-12-23 00:28:26.642 [debug]turnOnEvent(): turning on Upstairs Landing Lamp

[app:328]2019-12-23 00:28:26.638 [debug]turnOnEvent(): skip: false new values: [devices:[Upstairs Landing Lamp], devices_off:null, mode_level:20, mode_temp:2700] false

[app:457]2019-12-23 00:28:26.630 [debug]Sleep Mode: preTurnOn(): updated [devices:[Upstairs Landing Lamp], devices_off:null, mode_level:99, mode_temp:3000]

[app:328]2019-12-23 00:28:26.618 [info]Upstairs Light Automation: pluginExec: Sleep Mode -preTurnOn

[app:328]2019-12-23 00:28:26.615 [debug]Upstairs Light Automation: pluginExec: Sleep Mode [preTurnOn, preTurnOff, parentUpdated] com.hubitat.app.InstalledAppWrapper@71d69f6f

[app:328]2019-12-23 00:28:26.610 [debug]Upstairs Light Automation: pluginExec: num plugins: 2

[app:328]2019-12-23 00:28:26.604 [info]turnOnEvent(): Iris Sensor 1(motion) active values: [devices:[Upstairs Landing Lamp], devices_off:null, mode_level:99, mode_temp:3000]

Does the version I have posted have a switch called ‘don’t turn on after setting level (zooz)’ or something similar in the parent app? I found some switches go to 99% when you call on(), which is very much not what we want. The default was to call setLevel() the on()

If it’s not there I’ll update the github version in a day or two. I’m away for the holidays, and only have my phone at the moment.

Sorry for the hassle.

No worries at all! I do see that option, so I''ll give that a try. Thanks!

@jason-lane great! let me know if it help, if it doesn't we'll have to dig into it more.

I might have missed this, but it would great if there was a plugin for time-based restrictions (eg. I want a motion lighting to turn on a light from sunrise to 8 pm).

It seems to be working now with that option enabled :slight_smile: Thank you!

(The bulb I'm controlling with that automation is an Aeotec LED Bulb 6 Multi-Color)

I don't believe that currently exists, but you could possibly use the Mode plugin, or else a virtual switch to block the automation when you don't want it.

Ah great! It's annoying how different devices react differently to commands, neither my Sengled lights nor my GE dimmers act that way.

I dunno, it feels like setLevel should be separate from on, and on shouldn't be 100%. Ah well.

Good idea! It would be easy to duplicate and modify the blocker plugin to that based on time instead of a switch.

For the "I need it right now solution" you could do it with the blocker plugin. Create a virtual switch you turn on/off with a rule. It's kind of silly it need 3 different system components to do 1 thing. =)

Could you file an issue at: Issues · as-j/PlugableLights · GitHub

Then I won't forget about it, and it's so little work there's no reason not too do it, except I'm vacation at the moment and will forget by the time I get home.

I was going to do that, but ideally would like to avoid using RM.

Will do. Thanks for considering the suggestion!

Doh! I think I coded the wrong feature. I copied the mode plugin but made a time based version. So you can say between 8pm and 10pm set the light to level XYZ when you detect motion.

Well it's useful anyways.

Let me see about coding the feature you want. :smiley:

1 Like

@aaiyar There you go, faster than I thought. You can now force a light on at a certain time, and have it turn off at another. If there's motion or a contact is open it'll stay on though. So basically during the interval it stays on, then reverts to motion/contact based operation outside it.

It only supports 1 interval, but you can create multiple sub-apps so you have many intervals that way. Umm, don't overlap them. :wink:

1 Like