MultiSwitch Plugin

I have written a simple plugin called MultiSwitch which contains eight binary switches. My objective was to have a device that would help with testing and debug of new logic and also function as a scene controller.

MultiSwitch is just eight switches. If you click one of the eight buttons, the switch will toggle - i.e. on becomes off, off becomes on. The switch states can be used as triggers for scenes or PLxx devices. You can also target the switches with scenes and PLxx actions. The default action - when selected by clicking on the buttons in the GUI - is to toggle the switch. You can convert this to a forced off or on by clicking on the scene/action Advanced tab and changing the newStatus? value to 0 or 1 respectively.

To help in the development of new logic, use a MultiSwitch device to simulate up to eight input triggers. Use a second MultiSwitch as an indicator for up to eight actions. One row in the dashboard GUI can include a PLEG, eight trigger inputs, a VariableContainer (to simulate properties) and eight outputs.

For use as a scene controller, trigger up to eight scenes from the MultiSwitch On states. If you set the buttons to Pulse, they will turn back off automatically.

This is a very simple plugin. It doesn’t do anything complicated. It is really only eight VirtualSwitch devices in a single panel but I am finding it really useful as a debugging aid and as a compact set of scene triggers.

See MultiSwitch Instructions for detailed description of features. You can install the plugin from the App Store.

@chixxi, if some bits of the UI seem familiar it will be because I stole chunks of your code. Many thanks for the helping hand. ;D

Edit: 08/01/2014 19:43 New version uploaded. Added pulse feature. Replace all plugin files.
Edit: 16/01/2014 11:40 New version uploaded. Now uses Job processing. Only I_MSwitch.xml changed.
Edit: 17/02/2014 15:30 Now released in App Store as plugin 5836. Download link removed.
Edit: 18/04/2014 11:15 Version 1.2 released in App Store. Added Options variable. See: MultiSwitch V1.2
Edit: 24/04/2014 08:30 Version 1.3 released in App Store. Fixed update of BtnNames for use by remote apps.
Edit: 26/08/2014 19:42 Version 1.4 released in App Store. Improves display on UI7. No change for UI5/6.
Edit: 18/09/2014 19:14 Version 1.5 released in App Store. Improves support for UI7 without breaking UI5!
Edit: 17/02/2015 10:42 Version 1.6 released in App Store. Tidied-up UI7 display. No change for UI5.
Edit: 12/03/2015 00:25 Version 1.7 released in App Store. Fixed for firmware 7.0.5.

If you can talk the 3rd party mobile apps to support this … I think this would make a great tool for building and controlling automation logic.

Some options:
Button Names (and associated variable names)
Maybe a way to group a subset of buttons into a Radio Button Behavior.
A single property like groups: (1 2 3) (4 5 6) (7 8)


I would love to be able to change the UI button text at run-time but it doesn’t seem to be possible with json. Is this something that I could do with javascript? Is it even possible to manipulate the device’s front page with js? I have been trawling through my installed Luup files looking for inspiration but no joy so far. I would really appreciate any suggestions.

I do plan to add radio-button functionality. Json supports it but doesn’t seem to have the ability to alter the groups at run-time so I think I shall have to handle it in the Implementation code.

Could you expand on your single property idea? Do you mean something like a get-property action with a mask to indicate the switches to be checked?

Stop looking; what you want doesn’t exist. Plugins don’t have access to the UI’s DOM*, and static JSON files are cached by LuaUPnP anyway, so even if you managed to edit the D_*.json file you wouldn’t see any change until you did a Luup restart.

  • Plugins can’t even be certain that there is a UI.
Stop looking;
Thank you, sir. I shall take your advice and waste no more of my time on this.

MCV went part way to JavaScript in UI5 when they introduced JavaScript Button.
To bad they do not let you format the entire Control Box in JavaScript. (Or I have not seen it yet).

I assumed you would have to handle groups in your implementation.
Having a device property something like:

Groups: (1 2 3)(4 5 6) (7 8)    

Would instruct your implementation to create 3 groups of radio buttons.
(Sorry about the previous post … I did not preview and notice that the un-escaped 8) turned into a smiley.

Thanks, Richard. That’s a good way to specify the radio-button logic. I shall give it a whirl.

MultiSwitch now has radio-button capability. Following a good suggestion by RichardTSchaefer, there is now a variable in the Advanced tab named RadioBtns where you can specify groups of buttons where only one can be on at a time. For example:

b[/b] Buttons 1,2 and 3 are a group. When one turns on, the others will turn off
b(34)(678)[/b] Buttons 1 and 2 are a group, so are buttons 3 and 4, so are buttons 6, 7 and 8.
b[/b] All eight buttons are in a single radio group.
b(71)[/b] Buttons 1 and 2 are a group, so are buttons 1 and 7.
12345678 There are no radio groups.
There are no radio groups.

As shown in the last example, a button may be in more than one radio group if required. To give you the opportunity to totally confuse yourself, the RadioBtns variable may be set with a scene, PLxx actions or luup code.

You can download the plugin files from: MSwitch

I have uploaded a new version of MultiSwitch that allows you to customise the button text. This is done on the Control tab by entering the new text for each button and clicking the SetNames button. If a button label field is left blank, the existing text will not be changed. After clicking SetNames, following a short period for processing, you will be prompted to reload Vera and refresh the browser page to complete the changes.

The first time you change the button text for an instance of MultiSwitch, it will recreate itself as device type MSwitchxxx where xxx is the device ID (which does not change). This is to allow it to have a unique json file where the button text is defined. Subsequent changes are simply applied to the new json file.

The recreation process involves generating new D_MSwitchxxx.xml and D_MSwitchxxx.json files and then changing the existing device to use D_MSwitchxxx.xml as its device_file. This all happens automatically. All you do is enter the text you want to see on the buttons and hit Save/Reload. The device could be reset to the initial state, if required, by simply changing device_file back to D_MSwitch.xml in the Advanced tab.

I owe the concept of the self-modifying plugin to @Ap15e and I also purloined some of his code. ;D

it would be a cool idea to make the greenwave 6-port have all 7 buttons on 1 tab. there is 1 button to switch on/off the whole device and 6 slave to switch the ports. Is this possible with this plugin ?

This plugin is just a set of simple switches but, using a scene with Luup or a PLEG device, it may be possible to link the switches to your Greenwave device.

thats an idea… but i was thinking more of a direct switch device instead of a workaround with scenes.

I don’t have a Greenwave device but, from what I read in another topic, it is supported by Vera as six separate switches. To control these via Multiswitch would require one of:

Create a scene with twelve triggers. Each trigger is fired from a Multiswitch button on or off and contains Luup to set/clear the required Greenwave switch - so just one line of Luup per trigger. This is simple to implement and can have additional functionality if required. An additional button and triggers could be used for all-on and all-off if required.

Create a new plugin based on Multiswitch’s json that addresses the switches directly. Would require parameters for the Greenwave device IDs. I’m not convinced this is worth the effort.

Add functionality to Multiswitch to allow a device ID to be set for each button so that it could control any type of switch directly. This is certainly possible but is it so much better than the scene-based approach?

What do you think?

i think for ease of use by not-so-techsavvy people it would be a great idea to incorporate the device ID into your plugin, didnt even thought of that. if you would be so kind :slight_smile:
the greenwave powernode has 7 devices. 1 is main device and 6 are the ports of the powernode. each having a separate ID. the main device should provide all on/all off for the whole powernode but in reality it just switches port 1 due to lack of implementation in vera for it. it would be nice to have direct control for ID instead of having 12 scenes with stuff which is cluttering the UI.
you think its possible to incorporate that in your plugin ? like filling in the ID and being able to switch on/off per ID and status like button lit or not lit.

I’ll take a look at it. The switching should be straightforward but providing a convenient way to manage the device IDs will take a bit longer. As usual with software, the user interface takes the most effort.

I would want to do this so that it would work with any Powerswitch device - not dedicated to Greenwave. I think this means that an all-on function would not be possible if it is not supported by the existing parent device. It may be possible to achieve an all-off function by using multiple radio-button groups, though.

thank you in advance for your efforts to do this. maybe this needs to be a separate plugin ???
the all on/all off i mentioned i was assuming this would be connected to the ID of the devices. like in pressing all on would set all set device ID to on . the grouping of ID would be a very handy addon also to this. best way to archieve this is to have a page for settings in the device tab.
names taken from every device set in ID for buttons and in settings page


Button 1 Button 2 Button 3

Button 4 Button 5 Button 6

All On All Off


control ID Devicenumber | Name of device | All On/All Off

set ID 1: " " X
set ID 2: " " X
set ID 3: " " X
set ID 4: " " X
set ID 5: " " X
set ID 6: " " X

Group(s) : (1,2,3),(4,5),(6)

maybe this needs to be a separate plugin
You may be right. One issue is that the plugin will need to set variable_watch for all the Greenwave switch status state-variables so that it displays the correct states regardless of how state changes are triggered. This is a significant difference to Multiswitch's original intent as a virtual switch/scene controller. With this and the all-on/all-off requirement, it probably does justify a specific plugin rather than a kludge to Multiswitch.

It isn’t that the functionality for Greenwave is difficult - it is just that it doesn’t share much with Multiswtch.

i understand ur point. perhaps someone can chime in on the idea. i miss the knowledge to write such plugin but eager to learn how to.

Any plans to put this on the app store or whatever they call it? I’m just now experimenting with it in high hopes.

8 Hours later:

Wow. This plugin is fantastic! 8 virtual switches in 1 convenient place!

Two requests though. It would be nice to have the status of a button be able to trigger a scene. I have some situations where the status of the switch is changed when certain conditions are met. It would be great to have various events fire form the status change. Also when setting the status in a scene you can’t specify if you are turning the button on or off, which could get messy if the button was in the incorrect state to begin with.