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]