This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Gardena smart
#1
Anyone already linked a Gardena Smart gateway?

Here my first code to read a Sensor and write the moisturelevel and batterylevel.

Code:
function getData()   https = require 'ssl.https'   require('json')   socket.http.TIMEOUT = 5    local cUsername = 'email@abc.com'  local cPassword = 'password'     -- get session info   local cBody = '{"sessions":{"email":"' .. cUsername .. '","password":"' .. cPassword ..'"}}'   local cReq = {}   local cUrl = 'https://sg-api.dss.husqvarnagroup.net/sg-1/sessions'   result1 = https.request({       url = cUrl,       method = 'POST',       headers = {         ['content-length'] = #cBody,         ['content-type'] = 'application/json'       },       source = ltn12.source.string(cBody),       sink = ltn12.sink.table(cReq)   })   if result1 then     --log(cReq)     cReq = table.concat(cReq)     cReq = json.pdecode(cReq)     if cReq then       --log(cReq)       token = cReq.sessions.token       user_id = cReq.sessions.user_id     end   end   -- get location info   local cUrl = 'https://sg-api.dss.husqvarnagroup.net/sg-1/locations/?user_id=' .. user_id   result2 = https.request({       url = cUrl,       method = 'GET',       headers = {         ['content-type'] = 'application/json',         ['X-Session'] = token       },       sink = ltn12.sink.table(cReq)   })   if result2 then     --log(cReq)     cReq = table.concat(cReq)     cReq = json.pdecode(cReq)     if cReq then       --log(cReq)       local loc_name = cReq.locations[1].name       loc_id = cReq.locations[1].id     end   end   -- get device info   local cUrl = 'https://sg-api.dss.husqvarnagroup.net/sg-1/devices?locationId=' .. loc_id   result3 = https.request({       url = cUrl,       method = 'GET',       headers = {         ['content-type'] = 'application/json',         ['X-Session'] = token       },       sink = ltn12.sink.table(cReq)   })   if result3 then     --log(cReq)     cReq = table.concat(cReq)     cReq = json.pdecode(cReq)     if cReq then       --log(cReq)       local dName = cReq.devices[1].name       for k,v in pairs(cReq.devices) do         --log(v)         --log("Found the following GARDENA "..v.category)         --log("Name: "..v.name)          --log("Identifier: "..v.id)         -- gateway         if (v.category == "gateway") then          -- sensor         elseif (v.category == "sensor") then           for a, b in pairs(v.abilities) do             for c, d in pairs(b.properties) do               --log(d.name)               --log(d.value)               if (d.name == 'last_time_online') then                 --check = tostring(d.value)               elseif (d.name == 'humidity') then                 grp.write('1/1/1', tonumber(d.value))               elseif (d.name == 'level') then                  grp.write('1/1/2', tonumber(d.value))               end             end           end         -- onbekend apparaat         else           log('onbekend gardena apparaat: '..v.category)         end       end     end   end end
Reply


Messages In This Thread
Gardena smart - by gjniewenhuijse - 23.04.2018, 07:12
RE: Gardena smart - by admin - 25.04.2018, 06:45
RE: Gardena smart - by gjniewenhuijse - 26.04.2018, 06:24
RE: Gardena smart - by Firechief - 24.05.2020, 16:22
RE: Gardena smart - by Joep - 31.07.2023, 15:01

Forum Jump: