We have moved at community.getvera.com

Author Topic: ThingSpeak  (Read 29752 times)

Offline DaveL17

  • Full Member
  • ***
  • Posts: 186
  • Karma: +0/-2
ThingSpeak
« on: February 22, 2013, 11:04:16 pm »
Thanks to help from @a-lurker, I've been able to successfully pass Vera data to ThingSpeak.  I'm only just starting to play with this, but I think that it has serious potential.

www.thingspeak.com/

Dave

Offline DaveL17

  • Full Member
  • ***
  • Posts: 186
  • Karma: +0/-2
Re: ThingSpeak
« Reply #1 on: March 04, 2013, 10:37:03 pm »
For those that might want to try this out, here is the code that I'm using presently to send Vera data to ThingSpeak.  I run the code within a scene that (presently) fires every 5 minutes. 

Code: [Select]
-- Upstairs Thermostat
local UP_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 51)
local UP_HEAT = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Heat", "CurrentSetpoint", 51)
local UP_COOL = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint", 51)

-- Weather Plugin
local OUT_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 41)
local OUT_HUM = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel", 44)
local WIND = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "WindSpeed", 40)

--Devices
local FOYER_ONOFF = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 37)

-- Send data to channel 1
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=MY_API_KEY_1&field1="..UP_TEMP.."&field2="..OUT_TEMP.."&field3="..OUT_HUM.."&field4="..WIND.."&field5="..UP_HEAT.."&field6="..UP_COOL.."", "run=run")

-- Send data to channel 2
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=MY_API_KEY_2&field1="..FOYER_ONOFF.."", "run=run")

Just now starting to play with the idea of including binary device state--hence the Foyer On/Off variable. Still a work in progress...


Offline m0jon

  • Full Member
  • ***
  • Posts: 113
  • Karma: +0/-0
  • @m0jon
Re: ThingSpeak
« Reply #2 on: March 12, 2013, 06:01:17 pm »
Hi DaveL17

Have you worked out how to clear the graph, say every 24hrs. Just one mine to have data for one day and then clear automatically at mid night

Cheers

m0jon

Offline DaveL17

  • Full Member
  • ***
  • Posts: 186
  • Karma: +0/-2
Re: ThingSpeak
« Reply #3 on: March 13, 2013, 05:16:23 am »
Hi m0jon:

If I'm reading the Thingspeak documentation correctly, it's not possible to clear the channel data via an API call.  That said, you can limit the data that's drawn to create a chart via the channels API. See here:
http://community.thingspeak.com/documentation/api/#thingspeak_api

I think that it's actually better that we're not able to clear the channel via the API.  If someone gets hold of your Write Key, for example, they could delete all your data.

Offline DaveL17

  • Full Member
  • ***
  • Posts: 186
  • Karma: +0/-2
Re: ThingSpeak
« Reply #4 on: April 12, 2013, 12:09:31 pm »
Update on my progress with ThingSpeak.  I've upped my reporting to every 15 minutes (was at 5 min), and have added a few more devices.  Here is my latest code:

Code: [Select]
-- Sends data from Vera to Thingspeak.

-- Load data from downstairs thermostat
local DOWN_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 55)
local DOWN_HEAT = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Heat", "CurrentSetpoint", 55)
local DOWN_COOL = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint", 55)
local DOWN_HUM = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel", 56)

-- Load data from upstairs thermostat
local UP_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 51)
local UP_HEAT = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Heat", "CurrentSetpoint", 51)
local UP_COOL = luup.variable_get("urn:upnp-org:serviceId:TemperatureSetpoint1_Cool", "CurrentSetpoint", 51)

-- Load data from weather plugin
local OUT_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 41)
local OUT_HUM = luup.variable_get("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel", 44)
local WIND = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "WindSpeed", 40)
local FOYER_ON_OFF = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 37)

-- Load data from other devices
local OUT_LIGHT_LEVEL = luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1", "CurrentLevel", 60)

-- Send data to channel 1
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=API_Key1_Value&field1="..UP_TEMP.."&field2="..OUT_TEMP.."&field3="..OUT_HUM.."&field4="..WIND.."&field5="..UP_HEAT.."&field6="..UP_COOL.."", "run=run")

-- Send data to channel 2
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=API_Key2_Value&field1="..FOYER_ON_OFF.."&field2="..DOWN_TEMP.."&field3="..DOWN_HEAT.."&field4="..DOWN_COOL.."&field5="..DOWN_HUM.."&field6="..OUT_LIGHT_LEVEL.."", "run=run")

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: ThingSpeak
« Reply #5 on: April 12, 2013, 03:42:30 pm »
hello Davel17

do you install some plugin on your vera3 ?

how vera connects with thingspeak ?


thanks

Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline DaveL17

  • Full Member
  • ***
  • Posts: 186
  • Karma: +0/-2
Re: ThingSpeak
« Reply #6 on: April 12, 2013, 03:51:20 pm »
how vera connects with thingspeak ?

Hello Piwtorak -

It's actually pretty simple. The hardest part was figuring out the syntax of the http post method--but fortunately, there were others here to help me out. 
  • Create a new scene called "Thingspeak" (or named whatever you prefer).
  • Insert the Luup code above into the scene (yours will vary based on your devices, etc.)
  • Have the scene on a timer to run every so often (mine runs every 15 minutes).

Good luck, and post here if you're having trouble.
Dave

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: ThingSpeak
« Reply #7 on: April 12, 2013, 04:01:53 pm »
OK Davel is clear for me.

the only thing I do not understans is like this message will connects with thingspeak...I can not see any account login or another.

or what settings I must put in my account on thingspeak ...

please be patient.

thanks !
« Last Edit: April 12, 2013, 04:06:03 pm by Piwtorak »
Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline DaveL17

  • Full Member
  • ***
  • Posts: 186
  • Karma: +0/-2
Re: ThingSpeak
« Reply #8 on: April 12, 2013, 04:11:34 pm »
OK Davel is clear for me.

the only thing I do not understans is like this message will connects with thingspeak...I can not see any account login or another.

or what settings I must put in my account on thingspeak ...

please be patient.

thanks !

Of course, I'll be patient!

The connection to Thingspeak is through the API key of the channel (look to the bottom of my Luup code).  You obtain the API key from your account on the Thingspeak website. Each Thingspeak channel has it's own API key.

-- Send data to channel 1
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=API_Key1_Value&field1="..UP_TEMP.."&field2="..OUT_TEMP.."&field3="..OUT_HUM.."&field4="..WIND.."&field5="..UP_HEAT.."&field6="..UP_COOL.."", "run=run")

-- Send data to channel 2
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=API_Key2_Value&field1="..FOYER_ON_OFF.."&field2="..DOWN_TEMP.."&field3="..DOWN_HEAT.."&field4="..DOWN_COOL.."&field5="..DOWN_HUM.."&field6="..OUT_LIGHT_LEVEL.."", "run=run")

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: ThingSpeak
« Reply #9 on: April 12, 2013, 05:13:39 pm »
what can be wrong on my code ?
the device id is 30.

but I don'nt know if urn address is correct..this address was the unique record with urn on my device.

I want record how many time this device is turned on during the day.
thanks




local USAGE_LEVEL = luup.variable_get("urn:schemas-upnp-org:device:DimmableLight:1", "LoadLevelStatus", 30)

-- Send data to channel 1
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=RECWNP1QXT8C3CMJ&field1="..USAGE_LEVEL..", "run=run")




Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: ThingSpeak
« Reply #10 on: April 12, 2013, 06:02:08 pm »
I don'nt know if urn address is correct..this address was the unique record with urn on my device.

It's not correct. Hover the mouse over the variable name in the Advanced tab of device 30 and you will see the correct string. Hint: service ids never contain the word "schemas".

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: ThingSpeak
« Reply #11 on: April 12, 2013, 06:38:46 pm »
look now:

local USAGE_LEVEL = luup.variable_get("urn:upnp-org:serviceId:Dimming1", "LoadLevelStatus", 30)

local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=RECWNP1QXT8C3CMJ&field1="USAGE_LEVEL"", "run=run")

Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.

Offline DaveL17

  • Full Member
  • ***
  • Posts: 186
  • Karma: +0/-2
Re: ThingSpeak
« Reply #12 on: April 12, 2013, 06:43:54 pm »
What futzle said.  You should also need to add some 'dots' to the variable name in the url, thusly:

&field1="..USAGE_LEVEL.."

Plus, you will also want to generate a new API key at some point--if you haven't masked it--it's not a good idea to post it on the boards for all to see.

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: ThingSpeak
« Reply #13 on: April 12, 2013, 06:45:52 pm »
result, status = http.request("http://api.thingspeak.com/update?key=RECWNP1QXT8C3CMJ&field1="USAGE_LEVEL"", "run=run")

This looks dodgy. The string concatenation operator in Lua is .. so perhaps you mean:

"http://api.thingspeak.com/update?key=RECWNP1QXT8C3CMJ&field1=" .. USAGE_LEVEL .. "&run=run"

Offline Piwtorak

  • Hero Member
  • *****
  • Posts: 988
  • Karma: +4/-0
Re: ThingSpeak
« Reply #14 on: April 12, 2013, 07:20:08 pm »
no success with this line:

 result, status = http.request("http://api.thingspeak.com/update?key=RECWNP1QXT8C3CMJ&field1="..USAGE_LEVEL..", "&run=run")
Vera3 (1), Airport Extreme (2), Apple TV (3), Sqblaster (1), GE Switch (3), GE Dimmer (1), Leviton VRCSZ2 (2), GE 45601 (1), Intermatic HA03 (2), GE Zwave Outlet (1), Remote Control Curtain (1) and growing.