ThingSpeak

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

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.

-- 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…

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

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:

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.

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]
– 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”)[/code]

hello Davel17

do you install some plugin on your vera3 ?

how vera connects with thingspeak ?

thanks

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.

[ol][li]Create a new scene called “Thingspeak” (or named whatever you prefer).[/li]
[li]Insert the Luup code above into the scene (yours will vary based on your devices, etc.)[/li]
[li]Have the scene on a timer to run every so often (mine runs every 15 minutes).[/li][/ol]

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

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 !

[quote=“Piwtorak, post:8, topic:174415”]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 ![/quote]

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=[b]API_Key1_Value[/b]&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=[b]API_Key2_Value[/b]&field1=“..FOYER_ON_OFF..”&field2=“..DOWN_TEMP..”&field3=“..DOWN_HEAT..”&field4=“..DOWN_COOL..”&field5=“..DOWN_HUM..”&field6=“..OUT_LIGHT_LEVEL..””, “run=run”)

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”)

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”.

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”)

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.

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”

no success with this line:

result, status = http.request("http://api.thingspeak.com/update?key=RECWNP1QXT8C3CMJ&field1=“..USAGE_LEVEL..”, “&run=run”)

What is the most reliable way to have the scene run every X minutes to report to ThingSpeak? Timer plugin, schedule …???

[quote=“Piwtorak, post:15, topic:174415”]no success with this line:

result, status = http.request("http://api.thingspeak.com/update?key=RECWNP1QXT8C3CMJ&field1=“..USAGE_LEVEL..”, “&run=run”)[/quote]

You’re getting close.

result, status = http.request(“http://api.thingspeak.com/update?key=RECWNP1QXT8C3CMJ&field1=“..USAGE_LEVEL..””, “run=run”)

Note that there’s two double-quotes after the last variable in the URL, and there is no ampersand ‘&’ before ‘run’.

Think of it this way… There are double quotes around each variable name, and there are double quotes around the entire URL.

I have found that using a scene is very solid.

ok Guys !

is working fine !!

the code is:

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”)

and is registering the usage in percent of one light.

thanks for help !!!

[quote=“Piwtorak”]ok Guys !

is working fine !!

[snip]

thanks for help !!![/quote]

Great news. Congratulations! Don’t forget to change your API key. Your existing one is now in the open.