Author Topic: Create a multi_state_button in html?  (Read 379 times)

Offline tinman

  • Full Member
  • ***
  • Posts: 184
  • Karma: +10/-0
Create a multi_state_button in html?
« on: March 09, 2018, 10:46:42 am »
I'd like to be able to create a multi state button in html. I'm already using them in JSON files (which is really tedious) but I need to create them depending upon a device property. For some characteristics of my device there will be more or less of these buttons displayed. I'm hoping to be able to create the desired html in javascript.

Offline rstrouse

  • Hero Member
  • *****
  • Posts: 836
  • Karma: +30/-9
Re: Create a multi_state_button in html?
« Reply #1 on: March 09, 2018, 10:59:17 am »
Try this.

http://forum.micasaverde.com/index.php/topic,31128.msg317903.html#msg317903

It generates the tedious json via draq & drop, includes a multi-state button as well as other controls.
1xVera3 1.7.619, 4xLinear WT00Z, 3xLinear WS15Z, 1xLeviton VRCZ4, 10xCooper RF9540, 1xLeviton VRFI10, 1xLeviton VP00R, 2xLinear GD00Z-4, 1xGE/Jasco 45612, 1xGE/Jasco 45610,  4xGE/Jasco 45605, 2xYale YRD220-ZW-619, 1xCaddx NX584, Autelis Intellitouch Pool Control, OpenSprinkler

Offline tinman

  • Full Member
  • ***
  • Posts: 184
  • Karma: +10/-0
Re: Create a multi_state_button in html?
« Reply #2 on: March 13, 2018, 10:34:34 am »
I did some online searching and I'm still learning more about HTML, CSS and Javascript. Looking at the Virtual Panel plugin was very informative. I've succeeded in creating a tab for a device that has 20 toggle type buttons. The main reason I need this is that the buttons needed on this tab depend upon the firmware version installed on the device. I don't think that a JSON provides any conditional objects (i.e. if-then-else logic) which is easily done in Javascript. I'm also hesitant to add many plugins to the Vera hub. Sadly, so much of the Vera hub software feels like so many hacks. Since there's no reliable source of information about the correct way to create plugins, those doing so try things until something works, hoping that the next firmware release won't break anything. Currently on my Vera Plus every time I load the dashboard page it jumps to the Firmware Upgrade page of the Settings tab just to tell me I'm already running the latest version.

Offline rstrouse

  • Hero Member
  • *****
  • Posts: 836
  • Karma: +30/-9
Re: Create a multi_state_button in html?
« Reply #3 on: March 13, 2018, 12:51:06 pm »
You are correct in that the "static" json does not allow you to inject your own script or css into the dashboard page.  All of the values are "sanitized" even the labels otherwise you could simply show or hide the buttons based upon the fw version.  Or even create your own widgets for the dashboard.  However, on the detail tabs you have complete control of the display. Virtual Panel injects its own css and script to control the layout functions.  The only rub is that service callbacks to the vera require a local connection as these are http gets.  Without a local connection you have a CORS issue and there is no proxy that I am aware of to get back to the local Vera.

The only other way to do this is to generate the static json file when the plugin is first initialized or on a fw mismatch, then use the generated json and device xml for your dashboard buttons.  This is what virtual panel does when you edit a panel.  It's also what my pool control plugins use for differences in installed equipment.  Feel free to swipe whatever you need from it.
1xVera3 1.7.619, 4xLinear WT00Z, 3xLinear WS15Z, 1xLeviton VRCZ4, 10xCooper RF9540, 1xLeviton VRFI10, 1xLeviton VP00R, 2xLinear GD00Z-4, 1xGE/Jasco 45612, 1xGE/Jasco 45610,  4xGE/Jasco 45605, 2xYale YRD220-ZW-619, 1xCaddx NX584, Autelis Intellitouch Pool Control, OpenSprinkler