We have moved at community.getvera.com

Author Topic: Building Plug-in, Where to start?  (Read 3065 times)

Offline copekyle

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +1/-5
Building Plug-in, Where to start?
« on: April 27, 2015, 03:48:59 pm »
So I'm a little out of my world when it comes to the Luup environment and vera coding in general.  I know C# and .net pretty well but I'm so confused with how to write a simple plug in for my vera.

I have a device (Cr6 Campbell Scientific Datalogger) that is controlling my sprinkler system.  I basically have flags that need to be set high in order to turn on a zone.  This can be done using and html command:

http://user:pass@ipaddress/?command=setflag:zone1

If successful, it returns in json format this :   {"outcome": 1,"description": "success"}   I can also return in xml or html.

I want to integrate this into a simple vera control so I can do it from my phone.  All timing and everything is in the Datalogger I just need to set the flag high and then read the flag status from vera every 30 seconds or so using this command.

http://user:pass@ipaddress/?command=getflag:zone1

This returns a parameter in html, json, or xml.  I know I'll need to parse it but I can get to that later.

I looked through the OpenSprinkler Plug in and I couldn't make out how that works enough to even start this project.  Do any developers have a good starting point or anything I can look at?

Offline DeltaNu1142

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +40/-67
Re: Building Plug-in, Where to start?
« Reply #1 on: April 27, 2015, 03:49:51 pm »
Vera 3 @ UI5 | HomeWave | PLEG

Offline copekyle

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +1/-5
Re: Building Plug-in, Where to start?
« Reply #2 on: April 27, 2015, 03:52:34 pm »
Ah... you caught me before I could delete the other one.  I posted there first but then realized that this was a more appropriate place for my question. Sorry about that...

Offline DeltaNu1142

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +40/-67
Re: Building Plug-in, Where to start?
« Reply #3 on: April 27, 2015, 04:08:18 pm »
Just giving you a hard time. Thanks for cleaning it up. I don't have any advice on creating a plug-in, I'm just a lowly user. GL!
Vera 3 @ UI5 | HomeWave | PLEG

Offline rstrouse

  • Hero Member
  • *****
  • Posts: 842
  • Karma: +30/-9
Re: Building Plug-in, Where to start?
« Reply #4 on: April 27, 2015, 05:22:57 pm »
As a C# .net guy myself I found the most challenging thing about creating a plugin was the static JSON files since it is not very well documented.  Although the documentation has improved a bit.

You can download the Virtual Panel plugin and use that to create a static JSON and device XML file.  If you browse through the LUA file you will find many examples of processing JSON.  You can also try out the Http command until you get it right using the plugin and setting the action to Http get/post.
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 copekyle

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +1/-5
Re: Building Plug-in, Where to start?
« Reply #5 on: April 27, 2015, 05:25:37 pm »
As a C# .net guy myself I found the most challenging thing about creating a plugin was the static JSON files since it is not very well documented.  Although the documentation has improved a bit.

You can download the Virtual Panel plugin and use that to create a static JSON and device XML file.  If you browse through the LUA file you will find many examples of processing JSON.  You can also try out the Http command until you get it right using the plugin and setting the action to Http get/post.

When you say "Virtual Panel" plug in, do you mean "Virtual ON/OFF Switch"?  I don't see a virtual panel plugin in the app store.  (UI5)

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-13
Re: Building Plug-in, Where to start?
« Reply #6 on: April 27, 2015, 05:34:57 pm »
Start by reading Luup Plugins by Hand to get an overview of the required files and principles. Then pick an existing plugin that has similar functionality to your goal and study it until you understand what every line of code does.

Now create your own versions of each file - typically D_PluginName.xml, D_PluginName.json, S_PluginName.xml and I_PluginName.xml - changing the device-type, serviceID and variable names to suit your application. Upload the files to Vera, create your device specifying the D_PluginName.xml (device-file) and start debugging.

To get help with Lua, read Programming in Lua. There is an online version at http://www.lua.org/manual/5.1/. The luup library is documented at http://wiki.micasaverde.com/index.php/Luup_Lua_extensions.

Offline rstrouse

  • Hero Member
  • *****
  • Posts: 842
  • Karma: +30/-9
Re: Building Plug-in, Where to start?
« Reply #7 on: April 27, 2015, 05:36:46 pm »
As a C# .net guy myself I found the most challenging thing about creating a plugin was the static JSON files since it is not very well documented.  Although the documentation has improved a bit.

You can download the Virtual Panel plugin and use that to create a static JSON and device XML file.  If you browse through the LUA file you will find many examples of processing JSON.  You can also try out the Http command until you get it right using the plugin and setting the action to Http get/post.

When you say "Virtual Panel" plug in, do you mean "Virtual ON/OFF Switch"?  I don't see a virtual panel plugin in the app store.  (UI5)

No I mean this.
http://forum.micasaverde.com/index.php/topic,31128.0.html
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 copekyle

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +1/-5
Re: Building Plug-in, Where to start?
« Reply #8 on: April 27, 2015, 05:37:17 pm »
Start by reading Luup Plugins by Hand to get an overview of the required files and principles. Then pick an existing plugin that has similar functionality to your goal and study it until you understand what every line of code does.

Now create your own versions of each file - typically D_PluginName.xml, D_PluginName.json, S_PluginName.xml and I_PluginName.xml - changing the device-type, serviceID and variable names to suit your application. Upload the files to Vera, create your device specifying the D_PluginName.xml (device-file) and start debugging.

To get help with Lua, read Programming in Lua. There is an online version at http://www.lua.org/manual/5.1/. The luup library is documented at http://wiki.micasaverde.com/index.php/Luup_Lua_extensions.

Thanks for the reply.  I was just trying to find the code for your multiswitch plugin.  Seeing that it has 8 buttons and I have 7 irrigation zones, I might try and adapt your plugin to send the commands I need.

Offline copekyle

  • Jr. Member
  • **
  • Posts: 99
  • Karma: +1/-5
Re: Building Plug-in, Where to start?
« Reply #9 on: April 27, 2015, 05:39:31 pm »
No I mean this.
http://forum.micasaverde.com/index.php/topic,31128.0.html

ugh... looks like UI7 only... I'm not sure I'm ready to upgrade just yet.  Thanks though.

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-13
Re: Building Plug-in, Where to start?
« Reply #10 on: April 27, 2015, 06:36:28 pm »
Quote
I was just trying to find the code for your multiswitch plugin.  Seeing that it has 8 buttons and I have 7 irrigation zones, I might try and adapt your plugin to send the commands I need.

If you install the plugin you can download the files from Vera through APPS -> Develop Apps -> Luup files. The file names all contain MSwitch. MultiSwitch will give you the json and the implementation code for eight buttons (plus a bunch of stuff that you will not need) but it does not have any network I/O. You can probably find another plugin that will show you how to implement a HTTP command/response mechanism.
« Last Edit: April 27, 2015, 06:45:57 pm by RexBeckett »

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Building Plug-in, Where to start?
« Reply #11 on: April 27, 2015, 07:56:16 pm »

You can probably find another plugin that will show you how to implement a HTTP command/response mechanism.

The Philips Hue plugin might be a good place to start. It's got a RESTful interface with JSON response objects.