Telldus Live API connection in LUUP

Hi, I’m very new to the Vera and lua/luup scripting. The last few days I have tried to achieve a connection to the Telldus Live API (http://api.telldus.com) to be able to read temperatures and control switches connected to my Tellstick NET.

The thing is that I got a lua script connecting to the Telldus API when running it on webscript.io, but it seems that the luup in Vera does not recognize the oauth handling in the same way as webscript.io.

Anyone that can help me to sort out how this should be done in a Vera luup script?

My script that works on webscript.io:
############
local public_key = ‘xxx’
local private_key = ‘xxx’
local token = ‘xxx’
local token_secret = ‘xxx’

local response = http.request {
method = “GET”,
url = ‘http://api.telldus.com/json/sensor/info’,
params={id=‘xxx’},
auth={oauth={consumertoken=public_key, consumersecret=private_key, accesstoken=token, tokensecret= token_secret}}
}

return response.content

############

Found some code regarding dropbox webcam uploader and rewrote my script. Now the code test in Vera seems to accept this…

##########
local http=require(“socket.http”)
local https = require (“ssl.https”)

local public_key = “xxx”
local private_key = “xxx”
local token = “xxx”
local token_secret = “xxx”

local telldus_url=“http://api.telldus.com/json/sensor/info
local now=os.time()
local nonce = now
local post_headers=“realm="”…telldus_url…“", oauth_timestamp="”…now…“", oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="”…public_key…“", oauth_token="”…token…“", oauth_signature="”…private_key…“%26”…token_secret…“", oauth_nonce="”…nonce…“"”

local response = http.request {
method = “GET”;
url = telldus_url;
headers =
{
[“Authorization”] = "OAuth "…post_headers;
};
}

OK, now that seems I got the http oauth thing working…
So now I need to figure out how to get the temperature data out of the response???

In webscript.io i get the following printout in the web browser:

{“id”:“2440019”,“clientName”:“Huset”,“name”:“Akvarium”,“lastUpdated”:1442232457,“ignored”:0,“editable”:1,“data”:[{“name”:“temp”,“value”:“24.1”,“scale”:“0”}],“protocol”:“fineoffset”,“sensorId”:“151”,“timezoneoffset”:7200,“battery”:“254”,“keepHistory”:“0”}

How do I filter out the temperature (in bold above) so that I can send it to a virtual temperature sensor in my Vera Edge?

OK,
made a little progress in pulling out the temperature value from the son string.
This I got working in web script.io:

local Temperature=json.parse(json.stringify(json.parse(json.stringify(json.parse(response.content).data[1])).value))
return json.stringify(Temperature)

this prints out the temperature value in bold in my previous post here.
But it will not work in my Vera Edge even if I try the dkjson encode/decode…
Any ideas???

How are you getting along with this? I would very much like to get you plugins :slight_smile: I would also like to control my Tellstick.net from vera, including on/off switches and reading temperature sensors.

I got a step futher;

local http=require(“socket.http”)
local https = require (“ssl.https”)
local ltn12 = require(“ltn12”)
local JSON = require(“dkjson”)

local public_key = “xxx”
local private_key = “xxx”
local token = “xxx”
local token_secret = “xxx”

local telldus_url=“http://api.telldus.com/json/sensor/info?id=2148973
local now=os.time()
local nonce = now
local post_headers=“realm="”…telldus_url…“", oauth_timestamp="”…now…“", oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="”…public_key…“", oauth_token="”…token…“", oauth_signature="”…private_key…“%26”…token_secret…“", oauth_nonce="”…nonce…“"”

local response_body = {}

local content, status = http.request {
method = “GET”;
url = telldus_url;
headers =
{
[“Authorization”] = "OAuth "…post_headers;
};
sink = ltn12.sink.table(response_body);
}

luup.log(“Telldus status=”…status)
luup.log(“Telldus response=”…response_body[1])
local sensor=JSON.decode(response_body[1])
local data = sensor.data
local temp = data[1]
local value = temp.value
local humidity = data[2]
local hvalue = humidity.value
luup.log(“Temp=”…value)
luup.log(“Humidity=”…hvalue)

This is code developt with inspiration of this code. I have got it working in a scheduler.
The sensors are currently made with an app called “MultiString” that displays the sensors walues.

[code]
–local MultistringID = 19
–local SensorID = 862652
–Inne ersatt
–telldussensor(13, 523943)
–Inne
–telldussensor(13,5381585)
–Ute
–telldussensor(18, 862648)
–Vinden
–telldussensor(19, 862652)
function telldussensor(MultistringID, SensorID)
luup.log(“Scene4: LUA test”)

local public_key = “PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP”
local private_key = “RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR”
local token = “tttttttttttttttttttttttttttttttttttttttttt”
local token_secret = “sssssssssssssssssssssssssssssss”

local http=require(“socket.http”)
local https = require (“ssl.https”)
local ltn12 = require(“ltn12”)
local JSON = require(“dkjson”)

local telldus_url=“http://api.telldus.com/json/sensor/info?id=”…SensorID
local now=os.time()
local nonce = now
local post_headers=“realm="”…telldus_url…“", oauth_timestamp="”…now…“", oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="”…public_key…“", oauth_token="”…token…“", oauth_signature="”…private_key…“%26”…token_secret…“", oauth_nonce="”…nonce…“"”

local response_body = {}

local content, status = http.request {
method = “GET”;
url = telldus_url;
headers =
{
[“Authorization”] = "OAuth "…post_headers;
};
sink = ltn12.sink.table(response_body);
}

luup.log(“Telldus status=”…status)
luup.log(“Telldus response=”…response_body[1])
local sensor=JSON.decode(response_body[1])
local data = sensor.data
local temp = data[1]
local value = temp.value
local humidity = data[2]
local hvalue = humidity.value
luup.log(“Temp=”…value)
luup.log(“Humidity=”…hvalue)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “VariableName1”, “Namn”, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable1”, sensor.name, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “VariableName2”, “Temp”, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable2”, value, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “VariableName3”, “Humid”, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable3”, hvalue, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “VariableName4”, “Batteri”, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable4”, sensor.battery, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “VariableName5”, “Uppdaterad”, MultistringID)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”, “Variable5”, os.date(“%Y-%m-%d %H:%M”,sensor.lastUpdated), MultistringID)
end

telldussensor(13, 5381585)
telldussensor(18, 862648)
telldussensor(19, 862652)[/code]

Wow! This is awesome. Thanks! Got it to work in minutes with the help of your example.

Im new to both Vera and LUUP but want to try to control my “Nexa lights” via the telldus live API aswell. Have you tried that? I guess it possible?

Why not try my plugin GitHub - JuliusOnGitHub/Vera-Telldus-Live: Control Telldus devices and get sensor values..