We have moved at community.getvera.com

Author Topic: ThingSpeak  (Read 29754 times)

Offline cderibas

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: ThingSpeak
« Reply #30 on: September 03, 2015, 11:19:20 am »
Hi,
I think need to put code on "startup lua" but i didn't find it on the web..

Thanks for your help.
Ch.

Offline cderibas

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: ThingSpeak
« Reply #31 on: October 06, 2015, 10:16:28 am »
Hi,
me again.. ;D
i didn't find the code to put in 'Edit Startup Lua" on my vera.....  :'(
Someone help me ?
Thanks
Ch.

Offline cderibas

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Re: ThingSpeak
« Reply #32 on: October 09, 2015, 03:57:51 pm »
up up !!

Please, any help ?
Merci......

Offline Viruta57

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-0
Re: ThingSpeak
« Reply #33 on: October 10, 2015, 11:21:16 am »
Here...
« Last Edit: October 10, 2015, 11:24:25 am by Viruta57 »

Offline myhomeserver

  • Hero Member
  • *****
  • Posts: 874
  • Karma: +3/-5
  • http://www.MyZwave.net
Re: ThingSpeak
« Reply #34 on: November 10, 2015, 06:05:44 pm »
I had Thingspeak working a while back but its not working, here is my code

Any ideas how we can get ThingSpeak working again so it updates my channel?  I handcraft the URL and put it in my browser and it updates the values....But won't work in a scene in Vera anymore????







Code: [Select]
-- Weather Plugin and temps

local 1_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 565)
local 2_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 674)
local 3_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 620)
local 4_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 513)
local 5_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 81)
local 6_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 668)
local 7_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 445)
local 8_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 282)

--local WIND = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "WindSpeed", 84)
-- Send data to channel 1
local http = require("socket.http")
http.TIMEOUT = 30
result, status = http.request("http://api.thingspeak.com/update?key=xxxxxxxxxxxxxxx&field1="..1_TEMP.."&field2="..2_TEMP.."&field3="..3_TEMP.."&field4="..4_TEMP.."&field5="..5_TEMP.."&field6="..6_TEMP.."&field7="..7_TEMP.."&field8="..8_TEMP.."", "run=run")
MyZWave.net - See Our Z-Wave product Reviews
(formerly MyHomeServer)

Offline simonclark

  • Full Member
  • ***
  • Posts: 147
  • Karma: +6/-9
Re: ThingSpeak
« Reply #35 on: November 10, 2015, 07:41:44 pm »
You can send to thingspeak from altui plugin.

Offline kulfsson

  • Jr. Member
  • **
  • Posts: 59
  • Karma: +2/-0
Re: ThingSpeak
« Reply #36 on: December 16, 2015, 05:17:34 am »
I have been using Thingspeak with AltUI for a while now but the problem is that it reports "zero" values so the Scene route seems to be the better way, for now.
For reference, look here: http://forum.micasaverde.com/index.php/topic,34343.msg259918.html#msg259918

If you get the zero values in the data stream, it will mean that visualizing the data via f.x. the excellent Highstock graphing will result in "broken" lines on the feeds.

I did initially get the reporting to work with the scenes 1 time only, but then I went back and stripped out unnecessary comments and other and the code ran fine after that. 


Offline tedp

  • Sr. Member
  • ****
  • Posts: 288
  • Karma: +6/-2
Re: ThingSpeak
« Reply #37 on: December 16, 2015, 11:24:11 am »
This "scene" method never crossed my mind!!! I'll give it a shot. The nice thing about using the scene is that theoretically, it could fire whenever a temperature variable changes and write ALL the channel's data at that time, and I can put in a time trigger to update the chart every so often even if there are no changes with any of the variables.

Offline tedp

  • Sr. Member
  • ****
  • Posts: 288
  • Karma: +6/-2
Re: ThingSpeak
« Reply #38 on: December 16, 2015, 01:45:49 pm »
I got this to work really nicely using this concept. I had to toggle between AltUI and the regular UI5 to get it done (for some reason, AltUI would not accept the LUA code and return "could not edit scene).

I now trigger the scene using variable watches on all of my temperature monitors which cause ALL the Thingspeak variables to be updated. I also added an update every 20 minutes for good measure.

I'm not a LUA coder, so for anyone else who copies/paste the code in posted by "myhomeserver" -- you can't start a variable name with a number.

Offline liko

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: ThingSpeak
« Reply #39 on: January 03, 2016, 01:49:50 am »
Is anyone having success using the Scene method in UI7?  Here's my code (with my write API for my channel - originally I had my overall API key):

-- Get Temps
local MBR_TEMP = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "CurrentTemperature", 121)
local BR1_TEMP = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "CurrentTemperature", 116)
local OFC_TEMP = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "CurrentTemperature", 106)
local IN_TEMP = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "CurrentTemperature", 53)
local OUT_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 47)

-- Send data to ThingSpeak.com
local http = require("socket.http")
result, status = http.request("http://api.thingspeak.com/update?key=MASKED&field1="..MBR_TEMP.."&field2="..BR1_TEMP.."&field3="..OFC_TEMP.."&field4="..IN_TEMP.."&field5="..OUT_TEMP.."", "run=run")

Offline tedp

  • Sr. Member
  • ****
  • Posts: 288
  • Karma: +6/-2
Re: ThingSpeak
« Reply #40 on: January 04, 2016, 12:53:40 am »
Is anyone having success using the Scene method in UI7?  Here's my code (with my write API for my channel - originally I had my overall API key):

-- Get Temps
local MBR_TEMP = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "CurrentTemperature", 121)
local BR1_TEMP = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "CurrentTemperature", 116)
local OFC_TEMP = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "CurrentTemperature", 106)
local IN_TEMP = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "CurrentTemperature", 53)
local OUT_TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 47)

-- Send data to ThingSpeak.com
local http = require("socket.http")
result, status = http.request("http://api.thingspeak.com/update?key=MASKED&field1="..MBR_TEMP.."&field2="..BR1_TEMP.."&field3="..OFC_TEMP.."&field4="..IN_TEMP.."&field5="..OUT_TEMP.."", "run=run")

Mine looks like
local F1_GUEST_CURRENT = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 34)
which looks like the last one of yours (OUT_TEMP). I'm not sure why your other variables look different (I'm not an expert in this), but perhaps you can try only one temperature at a time to see if there is an offender. All it takes is one of the temperature readings to fail, and the whole scene will fail.


Offline bluefox

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: ThingSpeak
« Reply #41 on: January 15, 2016, 08:19:09 am »
This is my code:

-- Load data
local TEMP = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 213)
local WATT = luup.variable_get("urn:upnp-org:serviceId:EnergyMetering1", "Watts",261)
local KWH = luup.variable_get("urn:upnp-org:serviceId:EnergyMetering1", "KWH",261)

-- Send data to channel
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=xxx&field1="..TEMP.."&field2="..WATT.."&field3="..KWH.."", "run=run")

Vera says me it's incorrect, but if i delete only this part: &field2="..WATT.."&field3="..KWH.." then all is right.

Where is the mistake?

Thank.

Offline gerardosamara

  • Full Member
  • ***
  • Posts: 200
  • Karma: +5/-2
Re: ThingSpeak
« Reply #42 on: January 15, 2016, 11:20:24 am »
@bluefox,

What do you mean by "Vera says me it's incorrect" ?
Which error in the log when the scene is executed ?

 My guess is that the URN fild is not correct for WATTS and KWH , the correct value is "micasaverde-com"
« Last Edit: January 18, 2016, 01:01:57 pm by gerardosamara »
VeraLite+VeraEdge/EnOcean version US en UI7.1.17 + Vera Mobile UI7 V7.15.17.40 + Imperihome pro V2.8.3
Wall switch : Leviton VRS15 , Smart switch : Aeotec DSC24 , Motion sensor : Aeotec 4in1 DSB05 + Everspring HSP02 , Cameras Dlink 742L + Foscam 8910 + Foscam 9853EP

Offline Johan71

  • Newbie
  • *
  • Posts: 13
  • Karma: +0/-0
Re: ThingSpeak
« Reply #43 on: January 14, 2017, 07:45:24 am »
I use this but it don't works can anyone give me a tip

-Report to Thingspeak
--Fetch data
Temp = luup.variable_get("urn:schemas-micasaverde-com:device:TemperatureSensor:1", "Temp", 37)

-- Send data
local http = require("socket.http")
http.TIMEOUT = 5
result, status = http.request("http://api.thingspeak.com/update?key=my_keyfield1="..Temp.."", "run=run")

Offline a-lurker

  • Hero Member
  • *****
  • Posts: 872
  • Karma: +66/-8
Re: ThingSpeak
« Reply #44 on: January 14, 2017, 07:26:24 pm »
Just a few pointers here:

@dave17 You only need to do this once:

Code: [Select]
local http = require("socket.http")
http.TIMEOUT = 5

@myhomeserver - have a look at what is regarded as a valid identifier, here in section 2.1
https://www.lua.org/manual/5.1/manual.html

@Johan71 Comments begin with two dashes, not one. See also next point.

Most posters are doing this:
Code: [Select]
result, status = http.request( etc etc
Local variables need to be declared as local. If it's local, declare it as local:
Code: [Select]
local result, status = http.request( etc etc
Most posters are also adding on an empty string to their URL - it's not needed:

Code: [Select]
result, status = http.request(etc, etc .."", "run=run")
As noted previously, concatenating a whole lot of strings inefficient. Using this post as an example:
http://forum.micasaverde.com/index.php/topic,13790.msg104865.html#msg104865
You can do this or similar. It's more efficient and easier to understand or change but be careful with the commas and curly brackets:

Code: [Select]
    local API_KEY = "insertKeyHere"

    local urlTable = {
        "http://api.thingspeak.com/update?key=", API_KEY,
        "&field1=", UP_TEMP,
        "&field2=", OUT_TEMP,
        "&field3=", OUT_HUM,
        "&field4=", WIND,
        "&field5=", UP_HEAT,
        "&field6=", UP_COOL
    }

    local urlStr = table.concat(urlTable)
    local result, status = http.request(urlStr, "run=run")

Quote
simonclark You can send to thingspeak from altui plugin.
Exactly right and if you are not using altUI then definately try it out.
« Last Edit: January 14, 2017, 07:32:22 pm by a-lurker »