Smart Switch Plugin

Introduction

Ok, well maybe “Smart Switch” is a bit of an exaggeration. However, the idea behind this plugin is to allow you to more easily (and intelligently) control your switches (lights and dimmers) using your security sensors (i.e. motion activation).

The problem with “normal” motion activated lights is that it’s troublesome to override the automatic settings. For example, you may have a scene that turns on your family room lights when you walk in the room, and turns then off when you leave. However, what if you’re sitting down to watch a movie in the family room and want the lights to stay off during the movie? You could turn off the lights at the switch, but as soon as you move an inch, they’ll turn back on. If you thought about it ahead of time, you could manually disable the scene / motion sensor that controls them, and then turn off the lights, but then you’d have to remember to re-enable the scene again when you’re done. (Plus, you’d need some sort of remote control) Also, what if you don’t want the lights to turn on during the day? Or maybe, late at night, you only want lights to turn on to a very low dim level if you enter an area? (i.e. There’s nothing worse than getting blasted with bright flood lights when you walk down stairs for that midnight snack :slight_smile:

Obviously, you could muck with the motion sensor timeouts, write Lua code to do this and/or create numerous triggers and other scenes, but that’s a lot of work and hard to get right.

So, that’s where this plugin comes in. This plugin provides a one stop, integrated solution that implements (slightly) more intelligent motion controlled lights.

It behaves as follows:

[ul][li]Lights will be turned on when motion is detected, and turned back off when no motion has been detected for the specified “automatic timeout” period (i.e. normal “basic” motion controlled activation)[/li]
[li]The on and off levels can be specified - lights don’t necessarily have to turn all the way on or off, or even turn on at all[/li]
[li]When the user manually overrides the light either using the switch itself, or some other interface, Vera stops trying to control the light automatically. However, when no motion has been detected for the “manual timeout” period, automatic operation will resume.[/li][/ul]

And that’s it. Lights operate automatically until you don’t want them to, and then resume automatic operation on their own.

Installation

The plugin is easily installed from the MiOS apps portal:

[ol][li]Click on the “Apps” tab in UI5[/li]
[li]Click on the “Install Apps” sub-tab[/li]
[li]Search for the “Smart Switch” plugin, and click the “Install” button to install it.[/li][/ol]

If the plugin installs correctly, Vera will create a “Smart Switch” device in the “no room” location.

Usage

To control a switch / light using “Smart Switch” plugin, you must first add the switch to the plugin.

To add the switch to the Smart Switch plugin:

[ol][li]Click on the wrench icon for the Smart Switch plugin. (By default, this is located in “no room” as an “Other” device type)[/li]
[li]On the Settings tab, select the switch you could like to control with the smart switch plugin, and click the “Add” button[/li][/ol]

Vera will now create a Smart Switch device to control your switch. The name of the device will be “SS: ”, and will be created in “no room” by default.

To control the switch using motion sensors, you must add your motion sensors to the newly created Smart Switch. Adding a motion sensor to a smart switch is very similar to the procedure you used to add the switch to the plug-in.

To add a sensor to a smart switch:

[ol][li]Click on the wrench icon for the newly created Smart Switch device (not the smart switch plugin). (By default, this is located in “no room” as an “Other” device type)[/li]
[li]On the Settings tab, select the motion sensor you would like to use to control the switch, and click the “Add” button[/li][/ol]

Vera will not turn on and off the light as it senses motion from the motion sensor. If you manually change the light level, Vera will stop controlling the light using the motion sensor, and will instead wait for the “Manual Timeout” to expire before attempting to control the light again.

The timeouts and on/off levels can be controlled using the smart switch device.

Suggestions / Tips

[ul][li]You can control the light levels using scenes. This can be used, for example, to have the lights automatically turn on to a lower level at night time, or not turn on at all during the day.[/li][/ul]

Future Enhancements

[ul][li]If MCV fixes their “Slider” implementation, I will be able to replace the ridiculous number of buttons on the Smart Switch with a handful of sliders. (Currently, there can be only one slider per device, and the max / min limits for the slider are broken)[/li][/ul]

Cool. Let’s hope MCV gets a fix in for sensing the manual activation of a CA3000! (bug 2346)

Just as an FYI, the Smart Switch plugin has (finally) been uploaded. To install, just search for “Smart Switch” in the MiOS apps portal.

Hi hugheaves,

Awesome idea for a plugin. This’ll fill a useful niche for plenty of people. I’ve installed it from apps.mios.com and tested it out with a motion sensor and appliance switch.

If you’d like some help with converting your configuration tabs to JavaScript let me know.

Nice plugin, much easier than coding LUUP for different light levels based on the time of day!

Question: How do I delete a smart switch device?

I added a device for testing, and once I was satisfied, I added another for production, but I can’t get the testing device to delete. This is for the “SS: ” device (with all the levels, timeouts, etc). If I click the wrench, then trash can, and confirm, it will disappear, but then reappear when LUUP restarts.

*When I deleted it, it seems to have deleted the association with the motion sensor, so I don’t have the “test” light turning on and off, it is just taking up room on the dashboard.

Go to the Parent Device and in the Advance tabs you will find the SwitchIds it is managing. Remove it Device Id from here before deleting the child or otherwise, as you identify, it will reappear when LUUP restarts.

hugheaves
great plugin! I think “Timer Switch” is a more accurate name… just like the physical switches you can get at the DIY stores.

also, are you going to expand this to work with other devices… X10, Alsteon, etc… Maybe it already does?

I dont think i fully understand how this works. I added a switch and a motion sensor, but how do you activate the smart switch?
My motion sensor keeps turn off the light after 5min even if i turn on the light manually. I think its a very nice plugin you made :slight_smile:

[quote=“futzle, post:4, topic:172134”]Hi hugheaves,

Awesome idea for a plugin. This’ll fill a useful niche for plenty of people. I’ve installed it from apps.mios.com and tested it out with a motion sensor and appliance switch.

If you’d like some help with converting your configuration tabs to JavaScript let me know.[/quote]

Thanks futzle. The JavaScript is exactly what I need to tackle next. I’ve been avoiding it up until now (just haven’t had the time), but it would definitely help make this plugin more user friendly. (And my 3M-50 plugin - half the features are never used because they’re only configurable on the “Advanced” tab)

So, actually, I may just steal some of your code to get me started, if that’s ok with you. I saw your Countdown plugin has exactly what I need in terms of Javascript drop-downs…

I may ping you for help if I get stuck though!

Hugh

[quote=“PurdueGuy, post:5, topic:172134”]Nice plugin, much easier than coding LUUP for different light levels based on the time of day!

Question: How do I delete a smart switch device?

I added a device for testing, and once I was satisfied, I added another for production, but I can’t get the testing device to delete. This is for the “SS: ” device (with all the levels, timeouts, etc). If I click the wrench, then trash can, and confirm, it will disappear, but then reappear when LUUP restarts.

*When I deleted it, it seems to have deleted the association with the motion sensor, so I don’t have the “test” light turning on and off, it is just taking up room on the dashboard.[/quote]

Sorry for the late response, Google’s started sending all my forum email to Spam in the last day or so, and I didn’t realize anyone had even responded to this!

Anyway, deletion is a, cough, missing feature from the UI in current version. However, you can still delete a smart switch device by manually editing the “SwitchIds” variable on the “Advanced” tab, which is where the plugin stores the list of switches it manages. If you edit the variable to remove the switch id, and then restart / reload Luup, the SS device will be deleted.

Hope that helps!

Hugh

Update: Ah, I see @Brientim beat me to it on the response. Thanks Brientim!

[quote=“Aaron, post:7, topic:172134”]hugheaves
great plugin! I think “Timer Switch” is a more accurate name… just like the physical switches you can get at the DIY stores.

also, are you going to expand this to work with other devices… X10, Alsteon, etc… Maybe it already does?[/quote]

It should already support these, just as long as the devices implement the standard SwitchPower:1, Dimming:1, and/or SecuritySensor:1 services.

[quote=“j0ergensen, post:8, topic:172134”]I dont think i fully understand how this works. I added a switch and a motion sensor, but how do you activate the smart switch?
My motion sensor keeps turn off the light after 5min even if i turn on the light manually. I think its a very nice plugin you made :)[/quote]

One of the limitations (currently) of the plug-in is that it won’t detect manual changes unless your devices support instant status reporting to Vera. I can around this somewhat with some polling tricks, but haven’t had chance to implement those.

Do you know if your switch supports instant status?

Hugh

[quote=“Aaron, post:7, topic:172134”]hugheaves
great plugin! I think “Timer Switch” is a more accurate name… just like the physical switches you can get at the DIY stores.[/quote]

Yeah, that’s probably true. I’d like to think, though, that as I add more features to the plug-in that it will become a little “smarter” than a normal DIY timer switch. (i.e. I’m working on code to “learn” your lighting preferences - which will function kind of like an automatic scene generator :slight_smile:

Hugh

Can I use this to command an all off scene from a switch on a schedule so at night when I turn off my dining room light it shuts off my entire first floor but only turns off my dining room light during the day? I don’t have any motions hope to get one soon and maybe there’s another way to do this sorry I’m new to Vera

[quote=“hugheaves, post:13, topic:172134”][quote=“Aaron, post:7, topic:172134”]hugheaves
great plugin! I think “Timer Switch” is a more accurate name… just like the physical switches you can get at the DIY stores.[/quote]

Yeah, that’s probably true. I’d like to think, though, that as I add more features to the plug-in that it will become a little “smarter” than a normal DIY timer switch. (i.e. I’m working on code to “learn” your lighting preferences - which will function kind of like an automatic scene generator :slight_smile:

Hugh[/quote]

I think that is a great idea. I can see the possibility of your plugin replacing both the Combination Switch and Virtual Switch plugins

I have one thought for a feature that you should already have the base for…
“Security Mode” - the user could set a trigger (specific time of day, X mins after sunset, etc) and it would launch a lighting ‘sequence’ to simulate your normal home lighting (or other devices) as if you were in the house.

Example:
Create a regular Vera Scene with a Schedule for Sunset.
Use your plugin to create the device which has the lighting sequence

Right now, I can accomplish with but it is WAY more complex… I need to use a Vera Scene + a Virtual Switch + your plugin … but since each light comes on/off t different times, the # of scenes and devices gets out of hand. If your plugin could have one Smart Switch hold multiple devices, each with their own timers, this would solve the whole problem… I think :slight_smile:

My light it going in-to a on off loop. i added the ss to control my dining light with the foscam motion sensor. so when the camera motion sensor sense a motion it turn on the light and when there is not motion it turn off the light which is work fine but then 10 second after it turn the light off (when no motion) the sensor tripped again thus cause the light to turn on. i post this in another forum from a user suggest using the motion to control the light and having the same affect. When i found this plug in i was all hype but i got the same problem. It either cause by the IR cut from the camera or something. When the light turn off it cause the IR from the camera to turn on so the camera think that there is motion so the motion sensor act as tripped. and the light turn on again. and it keep repeating on and off on and off.

i tried to created a scenes and add a 10 second to it which when there is no motion run the scene (turn off the light) this cause the motion to turn on the light again then 10 second later turn off the light so the motion is still tripped when the 10secon light off happen so by the time the motion time out the light is off and not trigger the motion again. But this never really work because after this it need to click on reload form Miso for it to work again . Motion light on is always work it just that motion light off never really work

you said create a scene for only turn on the light by motion during the night and not during the day would you please explain a little more on how to do that please. Im new so bear with me please

Hi

I would love to see this work with the “Virtual switch”, so this can turn on/off the Virtual Switch.

I have a setup, with a TV and home entertainment system/xbox/etc. so using the combination switch and a TV plugin, I would like to only turn the xbox/entertaintment system, when there are movement AND the TV is on.

/Cokeman

Could you mayb explain how your plugin recognizes if a switch has been turned on manually? I need this for a scene I am creating and I somehow need luup code which detects if a light has been turned on manually.

is it possible to use smartswich without motion sensor
when a light switch turn on and the smartswitch detect and set as threshold 50% dimming and auto time out for 30 min?

I test worked and not work. can we put as option for future release? Thanks

I would like if you could insert the is_night function.

This would be great to avoid to switch on lights during day.

Thanks
Matteo