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
#2
You need to check the result of https.request call instead of cReq variable. Since it's defined as a table first if cReq then... will evaluate as true.
Reply
#3
(25.04.2018, 06:45)admin Wrote: You need to check the result of https.request call instead of cReq variable. Since it's defined as a table first if cReq then... will evaluate as true.

thanks for the comment.
Reply
#4
gjniewenhuijse,

I'm interested in this project as i'm installing a Smart Sileno Life 750 robotic mower this week and planning to extend this with Smart Water Control + Sensor and Smart Pressure Pump and maybe some Smart Power Plugs to control lights.
I'm a novice on scripting and things and would like to learn and understand more of this. It's not always clear where things go and steps to follow to get things working.
Can you, or anyone, explain me what to do and where to do it? I have a HL, wich is similar to the LM.

Thx in advance

I found this page with API for all Gardena Smart products:

https://developer.husqvarnagroup.cloud/a...I#/general

Kind regards,
Novice DIY with a HL and KNX basics trying to ...
Reply
#5
"This API has moved to the official developer portal. Please follow the instructions at https://developer.husqvarnagroup.cloud"
Reply


Forum Jump: