We have moved at community.getvera.com

Author Topic: MultiSwitch Plugin  (Read 111603 times)

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
MultiSwitch Plugin
« on: April 12, 2013, 08:46:11 pm »
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.
« Last Edit: March 11, 2015, 08:25:17 pm by RexBeckett »

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: MultiSwitch Plugin
« Reply #1 on: April 12, 2013, 09:19:57 pm »
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)

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: MultiSwitch Plugin
« Reply #2 on: April 13, 2013, 06:16:55 am »
@RichardTSchaefer,

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?

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: MultiSwitch Plugin
« Reply #3 on: April 13, 2013, 07:17:40 am »
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.

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.

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: MultiSwitch Plugin
« Reply #4 on: April 13, 2013, 08:01:51 am »
Quote
Stop looking;
Thank you, sir. I shall take your advice and waste no more of my time on this.

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: MultiSwitch Plugin
« Reply #5 on: April 13, 2013, 09:18:04 am »
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:
Code: [Select]
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
Code: [Select]
8) turned into a smiley.

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: MultiSwitch Plugin
« Reply #6 on: April 13, 2013, 09:27:37 am »
Thanks, Richard. That's a good way to specify the radio-button logic. I shall give it a whirl.
 

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: MultiSwitch Plugin
« Reply #7 on: April 13, 2013, 05:26:29 pm »
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:

(123)                  Buttons 1,2 and 3 are a group. When one turns on, the others will turn off
(12)(34)(678)  Buttons 1 and 2 are a group, so are buttons 3 and 4, so are buttons 6, 7 and 8.
(12345678)       All eight buttons are in a single radio group.
(12)(71)            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
 
« Last Edit: April 13, 2013, 08:14:40 pm by RexBeckett »

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: MultiSwitch Plugin
« Reply #8 on: April 21, 2013, 06:36:40 pm »
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
« Last Edit: May 02, 2013, 05:37:06 pm by RexBeckett »

Offline Da_JoJo

  • Hero Member
  • *****
  • Posts: 1380
  • Karma: +16/-78
  • If something aint work, we can allways try n make
Re: MultiSwitch Plugin
« Reply #9 on: June 07, 2013, 06:57:45 am »
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 ?
Vera lite (1.5.622), 2x an-158/2, dead usb pl2302 rs-232, 2x greenwave 6 port, 4x Fibaro FGD211 v1.6, FGBS001, few FGS - 221, etc. AuthomationHD 3 for android :-)
Dutch & German translator http://wiki.micasaverde.com/index.php/Special:AllPages http://support.micasaverde.com http://domotica-shop.nl

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: MultiSwitch Plugin
« Reply #10 on: June 08, 2013, 06:41:02 am »
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.

Offline Da_JoJo

  • Hero Member
  • *****
  • Posts: 1380
  • Karma: +16/-78
  • If something aint work, we can allways try n make
Re: MultiSwitch Plugin
« Reply #11 on: June 09, 2013, 07:29:34 am »
thats an idea.. but i was thinking more of a direct switch device instead of a workaround with scenes.
Vera lite (1.5.622), 2x an-158/2, dead usb pl2302 rs-232, 2x greenwave 6 port, 4x Fibaro FGD211 v1.6, FGBS001, few FGS - 221, etc. AuthomationHD 3 for android :-)
Dutch & German translator http://wiki.micasaverde.com/index.php/Special:AllPages http://support.micasaverde.com http://domotica-shop.nl

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: MultiSwitch Plugin
« Reply #12 on: June 09, 2013, 09:31:00 am »
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?

Offline Da_JoJo

  • Hero Member
  • *****
  • Posts: 1380
  • Karma: +16/-78
  • If something aint work, we can allways try n make
Re: MultiSwitch Plugin
« Reply #13 on: June 09, 2013, 10:07:37 am »
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 :-)
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.
« Last Edit: June 09, 2013, 10:22:11 am by Da_JoJo »
Vera lite (1.5.622), 2x an-158/2, dead usb pl2302 rs-232, 2x greenwave 6 port, 4x Fibaro FGD211 v1.6, FGBS001, few FGS - 221, etc. AuthomationHD 3 for android :-)
Dutch & German translator http://wiki.micasaverde.com/index.php/Special:AllPages http://support.micasaverde.com http://domotica-shop.nl

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: MultiSwitch Plugin
« Reply #14 on: June 09, 2013, 01:26:42 pm »
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.