Author Topic: help with a Static JSON file  (Read 294 times)

Offline BulldogLowell

  • Hero Member
  • *****
  • Posts: 1571
  • Karma: +190/-85
help with a Static JSON file
« on: August 25, 2017, 04:26:53 pm »
So I'm having difficulty editing a static json file so that I get it to render properly.  I am looking to have the toggle button appear to the right of the image, like it does on a motion sensor (example attached).

but mine renders like the 2nd photo.

here is my JSON:
Code: [Select]

   "default_icon":"http://www.konektedplay.com/threegee/assets/threegee-default.png",
   "state_icons":[ 
      { 
         "img":"http://www.konektedplay.com/threegee/assets/threegee-default.png",
         "conditions":[ 
            { 
               "service":"urn:konektedplay-com:serviceId:ThreeGeeBridge1",
               "variable":"Failed",
               "operator":"==",
               "value":1,
               "subcategory_num":0
            }
         ]
      },
      { 
         "img":"http://www.konektedplay.com/threegee/assets/threegee-default.png",
         "conditions":[ 
            { 
               "service":"urn:micasaverde-com:serviceId:SecuritySensor1",
               "variable":"Tripped",
               "operator":"==",
               "value":1,
               "subcategory_num":0
            }
         ]
      },
      { 
         "img":"http://www.konektedplay.com/threegee/assets/threegee-default.png",
         "conditions":[ 
            { 
               "service":"urn:micasaverde-com:serviceId:SecuritySensor1",
               "variable":"Armed",
               "operator":"==",
               "value":1,
               "subcategory_num":0
            }
         ]
      }
   ],
   "x":"2",
   "y":"4",
   "inScene":"1",
   "Tabs":[ 
      { 
         "Label":{ 
            "lang_tag":"ui7_tabname_control",
            "text":"Control"
         },
         "Position":"0",
         "TabType":"flash",
         "top_navigation_tab":1,
         "TopNavigationTab":1,
         "ControlGroup":[ 
            { 
               "id":"1",
               "isSingle":"1",
               "scenegroup":"1"
            }
         ],
         "SceneGroup":[ 
            { 
               "id":"1",
               "top":"0",
               "left":"1",
               "x":"2",
               "y":"1"
            }
         ],
         "Control":[{ 
               "ControlGroup":"1",

               "ControlType":"multi_state_button",
               "top":"0",
               "left":"1",
               "states":[ 
                  { 
                     "Label":{ 
                        "lang_tag":"ui7_cmd_arm",
                        "text":"Arm"
                     },
                     "Display":{ 
                        "Service":"urn:micasaverde-com:serviceId:SecuritySensor1",
                        "Variable":"Armed",
                        "Value":"1"
                     },
                     "Command":{ 
                        "Service":"urn:micasaverde-com:serviceId:SecuritySensor1",
                        "Action":"SetArmed",
                        "Parameters":[ 
                           { 
                              "Name":"newArmedValue",
                              "Value":"1"
                           }
                        ]
                     },
                     "ControlCode":"arm-armed"
                  },
                  { 
                     "Label":{ 
                        "lang_tag":"ui7_cmd_bypass",
                        "text":"Bypass"
                     },
                     "Display":{ 
                        "Service":"urn:micasaverde-com:serviceId:SecuritySensor1",
                        "Variable":"Armed",
                        "Value":"0"
                     },
                     "Command":{ 
                        "Service":"urn:micasaverde-com:serviceId:SecuritySensor1",
                        "Action":"SetArmed",
                        "Parameters":[ 
                           { 
                              "Name":"newArmedValue",
                              "Value":"0"
                           }
                        ]
                     },
                     "ControlCode":"arm_disarmed"
                  }
               ]
            },
            { 
               "ControlGroup":1,
               "ControlType":"line_break"
            },
            {
               "ControlGroup":"1",
               "ControlHeader":"1",
               "ControlType":"label",
               "Label":{ 
                  "lang_tag":"label_received",
                  "text":"Received:"
               },
               "Display":{ 
                  "Top":50,
                  "Left":50,
                  "Width":50
               }
            },
            { 
               "ControlGroup":"1",
               "ControlHeader":"1",
               "ControlType":"variable",
               "Display":{ 
                  "Service":"urn:micasaverde-com:serviceId:SimpleSerial1",
                  "Variable":"Received",
                  "Top":50,
                  "Left":100,
                  "Width":150
               }
            },
            { 
               "ControlGroup":1,
               "ControlType":"line_break"
            },
            { 
               "ControlGroup":"1",
               "ControlHeader":"1",
               "ControlType":"label",
               "Label":{ 
                  "lang_tag":"label_message_send",
                  "text":"Message to send:"
               },
               "Display":{ 
                  "Top":150,
                  "Left":50,
                  "Width":100
               }
            },
            { 
               "ControlGroup":"1",
               "ControlPair":"1",
               "ControlType":"input",
               "ID":"Message",
               "Display":{ 
                  "Top":150,
                  "Left":165,
                  "Width":80
               }
            },
            { 
               "ControlGroup":"1",
               "ControlPair":"1",
               "ControlType":"button",
               "Label":{ 
                  "lang_tag":"button_send",
                  "text":"Send"
               },
               "Display":{ 
                  "Top":150,
                  "Left":270,
                  "Width":50
               },
               "Command":{ 
                  "Service":"urn:micasaverde-com:serviceId:SimpleSerial1",
                  "Action":"Send",
                  "Parameters":[ 
                     { 
                        "Name":"Message",
                        "ID":"Message"
                     }
                  ]
               }
            }
         ]
      },
      { 
         "Label":{ 
            "lang_tag":"advanced",
            "text":"Advanced"
         },
         "Position":"1",
         "TabType":"javascript",
         "ScriptName":"shared.js",
         "Function":"advanced_device"
      }
   ],
   "DeviceType":"urn:schemas-micasaverde-com:device:SimpleSerial:1",
   "device_type":"urn:schemas-micasaverde-com:device:SimpleSerial:1"


for the life of me (despite the excellent documentation) I cannot determine how to position these objects to render the way I want them!

Offline rigpapa

  • Full Member
  • ***
  • Posts: 112
  • Karma: +18/-0
Re: help with a Static JSON file
« Reply #1 on: August 25, 2017, 05:53:37 pm »
As far as I know, this only works for Vera's known, implemented device types, and not for plugins. I've semi-confirmed this by reverse engineering the JavaScript for their UI code, where you find specific code for presentation of various types.

That said, I'd love to be proven wrong, because like you, I sure haven't found any combination of settings that makes it work. In fact, I feel like I'm only just beginning to understand how it really works, and much of it doesn't work as expected, and works very differently from the legacy documentation found online.

Just so I've said it, I find it equally frustrating that while you can at least get some controls somewhat orderly on the Dashboard display of a device, they do not appear in the Vera Android app's display of those devices.
Author of Rachio, Deus Ex Machina II, SiteSensor, and Auto Virtual Thermostat plugins. Using Vera Plus (1.7.3015), Vera3 (1.7.855), 50 dimmers and 40 switches (mostly Leviton, some Linear and GE), a dozen sensors, a truckload of PLEG, and of course, my own plugins.

Offline rstrouse

  • Hero Member
  • *****
  • Posts: 781
  • Karma: +27/-9
Re: help with a Static JSON file
« Reply #2 on: August 25, 2017, 06:46:37 pm »
As far as I know, this only works for Vera's known, implemented device types, and not for plugins. I've semi-confirmed this by reverse engineering the JavaScript for their UI code, where you find specific code for presentation of various types.

That said, I'd love to be proven wrong, because like you, I sure haven't found any combination of settings that makes it work. In fact, I feel like I'm only just beginning to understand how it really works, and much of it doesn't work as expected, and works very differently from the legacy documentation found online.

Just so I've said it, I find it equally frustrating that while you can at least get some controls somewhat orderly on the Dashboard display of a device, they do not appear in the Vera Android app's display of those devices.
This is not true.  If you download the VirtualPanel, plugin this actually creates static JSON files on the fly for the new device panels you create.  Each with their own positioning, icons, and displays.  Granted it took forever to decipher the static JSON.

The Android app is another matter.  When they were going through the last beta for it, the initial versions worked pretty well with custom device types.  Then some genius decided that they would focus on the device types as opposed to the JSON definition and made it display nothing but an icon when it didn't recognize the device type.  Plugins immediately became second class... again.  I find myself using the url and Chrome on my mobile since that seems to work better.  The IOS version is actually better and it does display some custom device types although I don't use an iTurd.
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 rigpapa

  • Full Member
  • ***
  • Posts: 112
  • Karma: +18/-0
Re: help with a Static JSON file
« Reply #3 on: August 25, 2017, 07:15:34 pm »
To be clear, are you saying that Virtual Panel can generate a static JSON file where a control appears immediately to the left of the arrow icon (Settings button)?
Author of Rachio, Deus Ex Machina II, SiteSensor, and Auto Virtual Thermostat plugins. Using Vera Plus (1.7.3015), Vera3 (1.7.855), 50 dimmers and 40 switches (mostly Leviton, some Linear and GE), a dozen sensors, a truckload of PLEG, and of course, my own plugins.

Offline BulldogLowell

  • Hero Member
  • *****
  • Posts: 1571
  • Karma: +190/-85
Re: help with a Static JSON file
« Reply #4 on: August 26, 2017, 07:01:21 am »
This is not true.  If you download the VirtualPanel, plugin this actually creates static JSON files on the fly for the new device panels you create.  Each with their own positioning, icons, and displays.  Granted it took forever to decipher the static JSON.

Interesting, I had not seen your plugin.

So (before I download and install your plugin) are you saying that as you create the virtual panel, it is rebuilding the static JSON associated with the plugin?

I would then use that example to copy/create the format I wish to use for my plugin?
« Last Edit: August 26, 2017, 07:58:17 am by BulldogLowell »

Offline rigpapa

  • Full Member
  • ***
  • Posts: 112
  • Karma: +18/-0
Re: help with a Static JSON file
« Reply #5 on: August 26, 2017, 10:40:17 am »
@rstrouse I'm trying VirtualPanel right now... VERY cool. But, I'm not able to get a button on the dashboard up between the device icon and the settings button. What's the trick? Also, I'm testing on fairly old firmware (1.7.855, Vera3)... does it require something newer?
Author of Rachio, Deus Ex Machina II, SiteSensor, and Auto Virtual Thermostat plugins. Using Vera Plus (1.7.3015), Vera3 (1.7.855), 50 dimmers and 40 switches (mostly Leviton, some Linear and GE), a dozen sensors, a truckload of PLEG, and of course, my own plugins.

Offline BulldogLowell

  • Hero Member
  • *****
  • Posts: 1571
  • Karma: +190/-85
Re: help with a Static JSON file
« Reply #6 on: August 26, 2017, 10:45:45 am »
@rstrouse I'm trying VirtualPanel right now... VERY cool. But, I'm not able to get a button on the dashboard up between the device icon and the settings button. What's the trick? Also, I'm testing on fairly old firmware (1.7.855, Vera3)... does it require something newer?

Likewise, I cannot figure out how to do it...

1.7.902

Offline rstrouse

  • Hero Member
  • *****
  • Posts: 781
  • Karma: +27/-9
Re: help with a Static JSON file
« Reply #7 on: August 26, 2017, 02:15:10 pm »
papa & bulldog,

I took another look and realize that they added an overflow to the CSS on the container for the user control area.  This used to allow you to set negative margins to trick the positioning on the panel.  There is a whole dissertation in the VP thread about positioning and the decision to head toward a responsive design.  This occurred ~v7.05  All that would have been ok if MCV continued down that track.  However, they decided to recreate the interface in the mobile apps.  That would have been the advantage as it would have been simple to scale, position, and arrange the flow.  Albeit a bit more complicated since there is no way to inject your own CSS or script without editing the core js files.

Anyhow all is not lost as you can fake the positioning as I did below by wrapping the control in an absolutely positioned div tag.  This is painful and there is some trickery that has to take place.  Basically, you let Vera create the outer control then wrap the inner with your own absolutely positioned block element containing the offset from the top/left of the panel.  This doesn't work with every control because they sanitize the HTML before setting it to the document.

Pre-7.05 you could place any related control anywhere in the browser window easily.  I'd welcome all this if they simply rendered the Android app like it is rendered on the web.
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 rigpapa

  • Full Member
  • ***
  • Posts: 112
  • Karma: +18/-0
Re: help with a Static JSON file
« Reply #8 on: August 26, 2017, 03:09:40 pm »
@rstrouse All good. I was hoping you discovered something native to the static JSON that would do it. But for the plugins I support, I don't want to pull too many tricks, because given the scope of changes we've seen before in MiOS/UIx, it may end up being impractical to support. It's disappointing, but I'm resigned to let Vera take the blame for the mediocre aesthetics of the dashboard.  ;D My hope is that whatever their thinking on future UIs, they've taken note of some of the good ideas in ALTUI.

And again, nice work on VirtualPanel. I know it's not exactly your intended purpose for it, but I've already used it to redesign a plugin I'm working on right out of the gate.
Author of Rachio, Deus Ex Machina II, SiteSensor, and Auto Virtual Thermostat plugins. Using Vera Plus (1.7.3015), Vera3 (1.7.855), 50 dimmers and 40 switches (mostly Leviton, some Linear and GE), a dozen sensors, a truckload of PLEG, and of course, my own plugins.

Offline rstrouse

  • Hero Member
  • *****
  • Posts: 781
  • Karma: +27/-9
Re: help with a Static JSON file
« Reply #9 on: August 26, 2017, 03:56:33 pm »
And again, nice work on VirtualPanel. I know it's not exactly your intended purpose for it, but I've already used it to redesign a plugin I'm working on right out of the gate.
Thanks for the vote of confidence and actually the core of it was written so that I could quickly make changes to the static JSON and see what effect it had on the rendering.  Believe it or not there was even less info back then than there is now.  From there it just evolved so I didn't have to write a custom plugin each time I wanted a custom interface. 

AltUI is definitely a step in the right direction.  If I had the time to when amg was first starting I would have offered to help.

Funny how every time I mention design decisions that I would have done differently I get smited.
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 RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9572
  • Karma: +729/-136
    • RTS Services Plugins
Re: help with a Static JSON file
« Reply #10 on: August 26, 2017, 05:44:59 pm »
I have not looked at Virtual Panel ... might need to ... I am mostly driven by automation ... i.e. NO user interface.
And try to let my Google Home handle non automation related requests.

But I think Virtual Panel might be a good User Interface for PLEG controlled logic.
Mostly people right now use Virtual Switch or Multi-Switch.

Offline rstrouse

  • Hero Member
  • *****
  • Posts: 781
  • Karma: +27/-9
Re: help with a Static JSON file
« Reply #11 on: August 26, 2017, 06:44:12 pm »
The one thing about it is that there is virtually (pun intended) an unlimited amount of state data you can put on the panel.  If you want to test out your plegs, or simulate conditions you can simply assign the state via lua or scenes, I think you would find some use.  If there is some dev out there (with a first name of Richard) who thinks its a good idea to integrate with theirs I'm game.  No strings attached of course.  Perhaps an action to execute a pleg from the controls?  If you see anything in the code that you find of value right now in fact, have at it.

As far as I see it, all the functionality for Multistring and Multi-switch and a few others exist in this plugin as well as some key things that don't exist elsewhere.  The key thing is that it doesn't just have to be on-off.  There are sliders, temp controls, spinners, and a few others.  Reporting your pleg states with indicator lights are in there too.  I have all my security zones as indicators.  These flash red when they are tripped.
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 RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9572
  • Karma: +729/-136
    • RTS Services Plugins
Re: help with a Static JSON file
« Reply #12 on: August 26, 2017, 08:33:31 pm »
I need to review ...
PLEG can read/write/create device variables ... and can react to an external change of device variables.
So I am thinking it just needs to be a HOW TO ...