Combination Virtual switch plugin (UI5)

Update June 2018: While this plugin still (just) works, you may want to try Reactor or Program Logic (PLEG) if you are setting up new logic on your Vera.

I’ve put a plugin onto apps.mios.com that should remove the need for Luup programming for a whole range of common scenarios.

The Combination Switch looks like a binary light. Instead of you turning it on and off manually, the plugin watches the state of other devices on Vera. You set conditions (“This dimmer is between 10% and 70%”, “That light is off”), and a threshold number. The plugin counts how many conditions are true, and when the count equals or exceeds the threshold, the Combination Switch turns on. When the count goes below the threshold, the Combination Switch turns off.

If you set the threshold to 1, you have the equivalent to a Boolean OR. If you set the threshold to the number of conditions, you have the equivalent to a Boolean AND. You can also use thresholds in between to get a kind of consensus sensing.

The Combination Switch fires events when the threshold is met and when it is lost. You can use these in notifications or you can use them as triggers for other scenes.

More in the following posts.

Here are the states that can be listed in a condition:

[ul][li]Switch Power Status: Tests binary switches (and things that pretend to be binary switches, including Combination Switches). Two options: true when the switch is on; true when the switch is off.[/li]
[li]Dimmer Level: Tests dimmers (and things that pretend to be dimmers, like blinds). True when the dimmer level is in the range x to y inclusive.[/li]
[li]Virtual Switch Status: Tests the Virtual Switch device from apps.mios.com. Two options: true when the switch is on; true when the switch is off.[/li]
[li]Variable Container: Tests the Variable Container device from apps.mios.com. Tests one of the five variable slots for string equality to a supplied constant value.[/li]
[li]Security Sensor: Tests any security sensor (door, motion, temp leak, smoke). Tests armed-or-bypassed, tripped-or-not-tripped, and combinations of the two.[/li]
[li]Power Consumption: Tests any energy metering device that produces instantaneous power measurements. True when the power consumption is in range x to y inclusive. Negative power is allowed. Leave a box blank for an open-ended comparison (±∞).[/li]
[li]Temperature: Tests any temperature sensor device. True when the temperature is in range x to y inclusive. Negative temperatures are allowed. Fractional temperatures, too, if your sensor can convince Vera to report it. Leave a box blank for an open-ended comparison (absolute zero, +∞).[/li]
[li]Weather conditions: Tests the main device of the Google Weather plugin from apps.mios.com. True when the current weather condition matches the one selected.[/li]
[li]Sun Position: Tests sun position as provided by the Heliotrope plugin from apps.mios.com. Can test altitude, azimuth, declination and right ascension. True when the selected variable is in the range x to y inclusive. Azimuth and right ascension wrap around so you can refer to west as azimuth -90 or 270.[/li]
[li]Door lock status: Tests any door lock. Tests door-is-locked, or door-is-unlocked.[/li]
[li]Alarm partition armed status: Tests a partition of a security system. Two options: true when partition is armed; true when partition is disarmed. (For more detailed tests, see the next entry.)[/li]
[li]Alarm partition detailed state: Tests a partition of a security system. There are about a dozen states of armed-ness that can be tested, including ready-to-arm, entry/exit delay, stay/away mode. Not all states are supported by all brands of security system.[/li]
[li]Humidity: Tests humidity sensors (physical and virtual). True when the humidity is in the range x to y inclusive.[/li]
[li]Day or Night: Tests the state of devices using the Day or Night plugin from apps.mios.com. True when this plugin reports day, or night.[/ul]

Watch this space. More to come.

Example scenarios:

[ul][li]Be notified when switch status of two switches change (Switch Power Status)[/li]
[li]Prevent motion from turning on a light while on vacation (Virtual Switch)[/li]
[li]Evaporative cooling shutoff when too many windows closed (Security Sensor)[/li]
[li]Turn on a light when a door is opened, only during evening hours (Security Sensor, Virtual Switch)[/li]
[li]Use one scene controller button to toggle a light (Switch Power Status, Virtual Switch)[/li]
[li]Prevent a door lock from operating if the door is open (Security Sensor, Door Lock)[/li]
[li]Make a switch do different things based on how dimmed a light is (Dimmer level, Switch status)[/li][/ul]

In this scenario, imagine that you have two energy-metering switches which you leave on all the time (one on a fridge and another on an aquarium heater). If the power to either one turns off, you need to be notified.

[ol][li]Create a Combination Switch. Rename it to All Switches On.[/li]
[li]Go to the Configure tab. Add two conditions: Switch Power Status of Fridge is On; Switch Power Status of Aquarium Heater is On. Set the Threshold to 2.[/li]
[li]Go to the Notifications tab. Add a notification for Virtual Switch Status Changes > Switch turns off. Choose a user to notify.[/li][/ol]

In this scenario, you have a light and motion sensor outside your front door. When not on vacation, you want motion to turn on the light. When on vacation, motion doesn’t turn on the light. You are using a Virtual Switch called Vacation to indicate your vacation state.

[ol][li]Create a Combination Switch. Rename it to Motion Vacation Filter. [/li]
[li]Go to the Configure tab, and add a condition Virtual Switch device Vacation is On.[/li]
[li]Create a scene. Rename it to Unfiltered motion detection. Make the scene activate the Trigger Poke button on the Motion Vacation Filter. Add a trigger to the scene: An Armed Sensor is tripped.[/li]
[li]Create a second scene. Rename it to Filtered motion detection. Make the scene turn on the light. Add a trigger to the scene: Device Motion Vacation Filter, event Triggered Poked while virtual switch is off.[/li][/ol]

I have installed the version 2 and I have the error ‘Combination Switch: Startup Lua Faiiled’

Is it due to the bugged version 2?

Should the version 3 fix this problem?
I have a Vera 3 with 1.5.346.

Thank you

[quote=“teonebello, post:6, topic:171904”]I have installed the version 2 and I have the error ‘Combination Switch: Startup Lua Faiiled’
Is it due to the bugged version 2?
Should the version 3 fix this problem?[/quote]

Yes, and yes. Version 3 has been awaiting approval [edit] approved.

The bug in Version 2 can be avoided by ensuring that you have at least one of each of the four device types that the plugin monitors. You’ve probably already got a binary switch and dimmer, so create a dummy Virtual Switch and a dummy Variable Container.

thanks for your plugin :wink:

i have a problem with my sensor sp103

i make a scene for my alarm and i would be like use your plugin for watch the status to my sp103
if tripped l’alarm don’t turn on and notify me a door is open and it’s ok my alrm turn on with my plugin calendar

it’s possible to make a status tripped or not tripped ?

thanks

@futzle, that kind of plugin should be integrated ASAP in the Vera Core application! Great! :wink:

Version 3 doesn’t do this, but a future version will definitely have sensor conditions. Version 4 up has this support.

Version 3 doesn’t do this, but a future version will definitely have sensor conditions.[/quote]

thanks very cool job :wink:

Version 4 has been submitted with support for security sensors.

I suggest that you don’t use the tripped/not tripped states for transient sensors like motion sensors. Such instantaneous events are better tied to the Trigger Poke button. Door sensors, of course, are a different beast.

In this scenario, imagine that you have an evaporative cooling system and several door/window sensors. Evaporative cooling works best when the doors/windows are left open, so you want the system to shut down when fewer than two door/windows are open.

[ol][li]Create a Combination Switch. Rename it Too many closed windows.[/li]
[li]Go to the Configure tab and add one condition for each of your door/window sensors, with the test Not tripped while armed. Set the threshold to the number of doors/windows, minus 1.[/li]
[li]Create a scene. Rename it Evaporative cooling shutoff. Add a trigger: Too many closed windows, condition Virtual Switch Status changes > Switch turns on. Make the scene turn off the evaporative cooling.[/li][/ol]

Bypass a sensor to pretend its door/window is open.

Tip: You can add the same condition twice, say, a big door that “counts” as two windows.

[quote=“futzle, post:12, topic:171904”]Version 4 has been submitted with support for security sensors.

I suggest that you don’t use the tripped/not tripped states for transient sensors like motion sensors. Such instantaneous events are better tied to the Trigger button. Door sensors, of course, are a different beast.[/quote]

a beta for version 4 is possible ?

That functionality for apps.mios.com is not yet present. For bleeding edge use, you can find the plugin at code.mios.com, browse the source, and download the files yourself. In Version 4, only the new file (obviously the one with SecuritySensor in its name) changed.

If that is too daunting, you will have to wait until an MCV staff member approves the new version.

very very good job

my alarm work is charm with doorsensor
:slight_smile:
thanks very much :wink:

In this scenario, imagine that you have a door sensor and a nearby light. When the door is opened during the evening, turn on the light. When the door is closed, turn off the light.

[ol][li]Create a Virtual Switch. Rename it Evening.[/li]
[li]Create a scene. Rename it Evening start. Add a schedule. Make the schedule Day of Week based, every day at sunset (or whenever you consider “evening” to begin). Add an action to the schedule to turn On the Evening virtual switch.[/li]
[li]Create another scene. Rename it Evening end. Add a schedule. Make the schedule Day of Week based, every day at midnight (or whenever you consider “evening” to end). Add an action to the schedule to turn Off the Evening virtual switch.[/li]
[li]Optional: add more schedules and triggers to these two scenes. You may have differing definitions of “evening” based on the day of the week, or you may want to add dawn times too.[/li]
[li]Create a Combination Switch. Rename it Door open during evening. Go to the Configure tab[/li]
[li]Add a condition to test Virtual Switch when the Evening device is On.[/li]
[li]Add a condition to test Security Sensor the door sensor is Tripped while Armed.[/li]
[li]Set the threshold count to 2.[/li]
[li]Create a third scene. Rename it Door is opened during evening. Add a trigger on the Combination Door open during evening > Virtual Switch Status changes > Switch turns off. Add an action to the scene that turns on the light.[/li]
[li]Create a fourth scene. Rename it Door is closed. Add a trigger on the door sensor device being An Armed Sensor is Tripped > Device Armed is not tripped. Add an action to the scene that turns off the light[/li][/ol]

Bypass the door sensor to stop it from controlling the light.

Tip: The asymmetry of the door-open and door-closed scenes is deliberate: the light is turned on by the combination switch, but turning off is governed by the door alone. This is to provide better behaviour if the door is still open at the end of the evening. The light stays on even after the end of the evening, until the door is finally closed.

This is very cool @futzle. I’m very glad to have Combintaion Switch in our toolbox. I’ll just point out, though, that the scenario ‘Turn on a light when a door is opened, during certain hours’, can be done with stock objects. The arming/disarming of the door sensor could be done with scheduled scenes, and the light can just be triggered with the armed door sensor.

Haha, yes, if all you have is a hammer, everything starts to look like a nail.

It should be easy to alter the scenario so that it can’t be done with stock scenes. I’ll give it some thought.

For instance: you are already using the door’s Armed/Bypassed status for something else in your house. Or you want to combine this with the Not-on-Vacation scenario, and test a second Virtual Switch.

@futzle

First of all - thanks for the great and useful plugin!

I’ve got a feature request though ;)…

I’m using several modules around my home that have power metering capability and I would like to switch them off based on their power usage (e.g. standby killer). So far I haven’t found a good and easy to configure way - I think that your combination switch might come in handy.

Is there any way you could add a parameter that checks current power usage from a device? Or is there perhaps another easy way to accomplish what I’m trying to do?

Again, thanks for the great work so far!