Thingspeak Plugin

Posted on
Sun Mar 09, 2014 2:21 pm
DaveL17 offline
User avatar
Posts: 3423
Joined: Aug 20, 2013

Thingspeak Plugin

Available Now:

Overview:
The Thingspeak plugin is designed to allow users to upload device states and variable values to Thingspeak.

Installation and Configuration:
Before you can use the plugin, you need to have an active Thingspeak account.

There are only a couple of settings for the plugin. The first is to set how often you would like the plugin to upload data and the second is how long you would like to wait for a response from the Thingspeak servers. To use the plugin, you must create Thingspeak devices. Each device represents one Thingspeak Channel. It's under the 'Edit Device Settings' where the bulk of the configuration takes place. Each Thingspeak device can support up to eight values (a limit for individual Thingspeak channels.) To upload more values, add additional Thingspeak devices. Right now, Thingspeak only supports numeric values and the Thingspeak plugin supports numeric and boolean values (it coverts boolean values to numerics). The device configuration settings are pretty self explanatory.

The chart below is a sample of a Thingspeak chart--these are created via the Thingspeak website--not the plugin itself. However, Thingspeak charts can be placed into HTML iFrames and used in conjunction with Indigo Control Pages.

Other Plugin Features:
- reports device health to the main Indigo UI. When the plugin is successfully reporting, the UI will display a green indicator.
- tries to strip non-numeric characters from the value before attempting upload (leaves the source variable unchanged.)
- attempts to overcome adverse conditions like variable deletions, etc.

Please post any bugs or questions about the plugin to this forum.
Attachments
thing.png
Example of a Thingspeak chart.
thing.png (26.04 KiB) Viewed 4856 times
Last edited by DaveL17 on Mon Mar 31, 2014 10:40 am, edited 4 times in total.

Posted on
Sun Mar 09, 2014 3:25 pm
matt (support) offline
Site Admin
User avatar
Posts: 18063
Joined: Jan 27, 2003
Location: Texas

Re: Thingspeak Plugin

Hi Dave,

Great contribution -- I approved the submission to the user contribution library here:

http://www.perceptiveautomation.com/fil ... php?id=276

And the direct link to the plugin download is:

http://www.perceptiveautomation.com/ind ... Plugin.zip

Thanks for sharing this with folks!

Image

Posted on
Sun Mar 09, 2014 4:32 pm
DaveL17 offline
User avatar
Posts: 3423
Joined: Aug 20, 2013

Re: Thingspeak Plugin

matt (support) wrote:
Hi Dave,

Great contribution -- I approved the submission to the user contribution library...


Thanks Matt. My pleasure!

Posted on
Sun Mar 09, 2014 4:42 pm
durosity offline
User avatar
Posts: 3105
Joined: May 10, 2012
Location: Newcastle Upon Tyne, Ye Ol' England.

Re: Thingspeak Plugin

Great plugin.. looking forward to seeing it support devices!

I’ve found a couple of minor issues.. one is that updated preferences on upload times don’t seem to make any difference until you reload the plugin. The second, and i’m not sure if this might be what you mean by "Thingspeak only supports numeric values” but if i have a value of say 20.3 it’ll upload that as 203.

Computer says no.

Posted on
Sun Mar 09, 2014 5:10 pm
DaveL17 offline
User avatar
Posts: 3423
Joined: Aug 20, 2013

Re: Thingspeak Plugin

durosity wrote:
Great plugin.. looking forward to seeing it support devices!

I’ve found a couple of minor issues.. one is that updated preferences on upload times don’t seem to make any difference until you reload the plugin. The second, and i’m not sure if this might be what you mean by "Thingspeak only supports numeric values” but if i have a value of say 20.3 it’ll upload that as 203.


Thanks for letting me know about the bugs.

Devices are a little trickier because it's tough to generate a dynamic list of device states--especially only the numeric ones.

UPDATE: I've fixed both bugs for the next update:
- Going forward, the upload interval will update itself on the next cycle (it's either that or force an upload with a config save.)
- The numeric thing was me getting a little too aggressive. What I'm trying to do is convert values such as "20.3 °F" into "20.3" but wound up stripping the decimal point too.

Thanks again.

Posted on
Sun Mar 09, 2014 7:56 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: Thingspeak Plugin

Dave,
great plugin!! and so simple..

as for stripping letters from text:

varValue= "the voltage is 13.7 V!"
number = ''.join(i for i in varValue if (i.isdigit() or i=="."))
number = 13.7

For selecting properties from a device, look at the python code in indigoplot.
I have spend MANY hours making that work.
The trick is to reduce the number of things presented to the user, some devices have a LOT of properties and most are just text.

Karl

Posted on
Sun Mar 09, 2014 8:13 pm
DaveL17 offline
User avatar
Posts: 3423
Joined: Aug 20, 2013

Re: Thingspeak Plugin

Thanks so much Karl. Still a work in progress (I suppose they are never done...) I have landed on the following which is effectively the same thing as what you've suggested.

Code: Select all
seq = ''.join([c for c in seq if c in '1234567890.'])

I will definitely take a look at indigoplot. I had something working but it was basically a dump of all device states which, while it would work, could be hundreds of choices long in no time.

Thanks again and any ideas for improvements would be most welcome.

Dave

Posted on
Sun Mar 09, 2014 8:41 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: Thingspeak Plugin

One way to do it is:
preselect devices (i.e. that have a prop with a number)
present that filtered device list, user picks a device
after device is selected then present the props that have a number.

it took me some time to figure that out and you will need to understand the hierarchy of several dynamic lists and which one will get updated when..

there are 19 in the config screen

one way to do it is to have check buttons that enabled and disable certain sections

its fun once it works..

Karl

Posted on
Sun Mar 09, 2014 8:51 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: Thingspeak Plugin

text --> number:

Code: Select all
accept = -999999991.1
try:
   x = float(''.join([c for c in val if c in '1234567890.']))
   accept =x
except:
  if val.upper()  =="TRUE"  or val.upper() =="ON":  accept = 1.
  if val.upper()  =="FALSE" or val.upper() == "OFF":  accept = 0.


reject if accept == -999999991.1

otherwise it can be used as floating point number or 1/0

True and false can be plotted as 1 / 0 i.e. on /off i.e. AC is on/off

Karl

Posted on
Sun Mar 09, 2014 9:39 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: Thingspeak Plugin

this should core all(?) possibilities:
Code: Select all
   def getNumber(self,val):
      x = ""
      try:
         x = float(val)
         return x
      except:
         xx = ''.join([c for c in val if c in '1234567890.'])
         if len( ''.join([c for c in xx if c in '1234567890']) ) !=0: return xx  # remove strings that have leters and dots eg "abc.xyz"
            val = str(val).upper()
            if val== "TRUE"  or val =="ON"  :  x= 1.                                                      # true --> 1,  false --> 0
            if val== "FALSE" or val =="OFF" :  x= 0.
      return x


returnNumber = self.getNumber("theString") or number
this one will handle:
1.0 --> 1.0
0.0 --> 0.0
a.b --> ""
"" --> ""
"the value is 12.7v" --> 12.7
"a is better than b." --> ""
True --> 1.0
"true" --> 0.0
False --> 0.0
"false" --> 0.0
"on" "ON" "oN" --> 1.0
"off" "OFF" "oFF"--> 0.0

"" if none of above

Posted on
Sun Mar 09, 2014 9:43 pm
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: Thingspeak Plugin

The attached will make a list of devices / variables that satisfy the "number" criteria as variable value or have a property with a "number"

Code: Select all
   def preSelectDevices(self):            # Select only device/properties that are supported:  numbers, bool, but not props that have "words"
      self.listOfPreselectedDevices=[]
      self.devIdToTypeandName={}
      self.logMessage(u" listOfPreselectedDevices 1 "+ str(self.listOfPreselectedDevices))

      for dev in indigo.devices.iter():
         theStates = dev.states.keys()
         count =0
         for test in theStates:
            try:
               if "Mode" in test or "All" in test:
                  skip= True
               else:
                  skip= False
            except:
               skip=False
            if not skip:   
               val= dev.states[test]
               x = self.getNumber(val)
            if x !="":
               count +=1
         if count>0:                                       # add to the selection list
            try:
               self.listOfPreselectedDevices.append((dev.id, dev.name))            ## give all id's and names of  devices that have at least one of the keys we can track
               self.devIdToTypeandName[dev.id]="Dev-",dev.name
            except:
               self.logMessage(u" listOfPreselectedDevices 2-1 error id, name "+ str(dev.id) + " " +str(dev.id)+" " + str(self.listOfPreselectedDevices),0)


      for theVar in indigo.variables:
         val = theVar.value
         x = self.getNumber(val)
         if x!="":
            try:
               self.listOfPreselectedDevices.append((theVar.id, "Var-"+str(theVar.name)))
               self.devIdToTypeandName[theVar.id]= "Var-",theVar.name
            except:
               self.logMessage(u" listOfPreselectedDevices 2-2 error id, name "+ str(theVar.id) + " " +str(theVar.id)+" " +  str(self.listOfPreselectedDevices),0)

      return

Posted on
Mon Mar 10, 2014 6:16 am
DaveL17 offline
User avatar
Posts: 3423
Joined: Aug 20, 2013

Re: Thingspeak Plugin

kw123 wrote:
def getNumber(self,val):

Thanks Karl. This method seems to be working well. I had to play with the indents a bit to get it to work, but that's to be expected. Will now take a look at the device state code you provided.

Thanks very much!
Dave

Posted on
Mon Mar 10, 2014 9:29 am
jay (support) offline
Site Admin
User avatar
Posts: 13352
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Thingspeak Plugin

I believe the SDK contains an example of a dynamic list that gets rebuilt based on a selection change in another list - I believe it's the custom device example plugin. It's actually pretty simple - just implement a dynamic list of states where you get the device from a menu field. Mark the menu with the devices to reload dynamic fields:

Code: Select all
<Field id="sourceDeviceMenu" type="menu">
   <Label>Device to add to scene:</Label>
   <List class="self" method="sourceDevices" dynamicReload="true"/>
</Field>


and whenever the user selects something different in that menu all dynamic fields will get reloaded - and your states list dynamic method can get the value of sourceDeviceMenu (in the above example), build the state list, and return that.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Mar 10, 2014 10:46 am
kw123 offline
User avatar
Posts: 4970
Joined: May 12, 2013
Location: dallas, tx

Re: Thingspeak Plugin

Jay,
the challenge is: if you just do it linear (device+property) you get e.g. 50 devices * 10 states =500 as the selection list.

would be good if the menu structure would allow for a hierarchical selection list: first you select the device and AFTER you have done that, the second list picks up the device id and creates the list of properties for that device. Right now they are all at the same level, no priority and the second one goes before the first one and and so on, they get called many times.

If you implement that the next time I could have saved ~ 10 days of fiddling with 16 dynamic lists

but thats the fun .. at least for me..

Karl

ps if you have not seen the movie "Tim's Vermeer" I highly recommend it.
It is about technology, art, and a 5 year commitment proving that the first color copy machine was invented by a Dutch painter in the 16 hundreds - one copy takes 1 year though, and the pixels size is 1mmx1mm, but still..

Posted on
Mon Mar 10, 2014 11:38 am
RogueProeliator offline
User avatar
Posts: 1816
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Thingspeak Plugin

would be good if the menu structure would allow for a hierarchical selection list: first you select the device and AFTER you have done that, the second list picks up the device id and creates the list of properties for that device. Right now they are all at the same level, no priority and the second one goes before the first one and and so on, they get called many times.

I am pretty sure you can do this now... and I am assuming (I know, dangerous) this is what Jay was getting at, so maybe an alternative explanation would help.

Your first drop down is a list of the devices (all or an allowable subset or whatever) and the second (properties) box is initially an empty list; in your code if there is no current device selection you return an empty list.

When the user makes a selection, the properties drop down, being a dynamic list, could react to the change in the selected device. If you can't get it reacting then you could have a button that, when clicked, "selects" the device and loads the properties for it. However, as per Jay's post, I am thinking that you can indeed react to the device selection box having been changed.

Hopefully I understood both of you or I could just be talking for no reason here ;-)

Adam

Who is online

Users browsing this forum: No registered users and 0 guests