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.

Samsung Fridge / Smartthing Rest API
#1
With some help fom Admin, I have finally succsessfully Set up a API to fetch Data from Smartthings Cloud.

I have a Samsung fridge, with a Smartthings VLAN Dongle innstalled.
You need an Smatphone, Smartthings-APP and account, and set ut the Fridge to communicate to the Cloud.

Thereafter you can with your account credentials access the Cloud and set up a PersonalAccessToken
link to get new token:
https://account.smartthings.com/tokens

--Script under was placed in Resident, sleep 20sek

Code:
https = require('ssl.https') json = require('json') ltn12 = require('ltn12') token = 'Secret-number-from-weblink-above' tbl = {} res, code = https.request({   url = 'https://api.smartthings.com/v1/devices/--Device-number--/status',   method = 'GET',   headers = {     ['authorization'] = 'Bearer ' .. token,     ['content-type']  = 'application/json',   },   sink = ltn12.sink.table(tbl), }) if res and code == 200 then   resp = table.concat(tbl)   resp = json.pdecode(resp)   -- Found a value in table with setpoint here:   FridgeSetp = resp["components"].cooler.thermostatCoolingSetpoint.coolingSetpoint.value -- Found a value in table with temperature here:   FridgeTemp = resp["components"].cooler.temperatureMeasurement.temperature.value -- My goal - the Door contact sensor information was found here   Door = resp["components"].main.contactSensor.contact.value -- Found a value in table telling if rapid-coolmode is enabled here:   RapidFreeze = resp["components"].main.refrigeration.rapidCooling.value    -- Updating With response   grp.update('13/4/1',FridgeSetp)   grp.update('13/4/2',FridgeTemp)   grp.update('13/4/7',RapidFreeze) -- Check if door already is open, if so check when it was opened.. and if over 8 seconds - Set alarmTag   if grp.getvalue('13/4/6') == 'open' and Door == 'open' then             if os.time() - grp.find('13/4/6').updatetime > 8 then               -- set alarmTag               grp.update('13/4/9', 1)             else               -- ReSet Alarmtag               grp.update('13/4/9', 0)       end     else     grp.update('13/4/6',Door)          -- ReSet Alarmtag         grp.update('13/4/9', 0)   end   --  log(resp) else   log(res, code) end


Now the thing here is to search the table and log the response actively, Smartthings returs a huge Table with a lot of unndeeded data. For my fridge table above was OK, but I guess other SmartThings do look quite different.
Also did not check for Put commands, while I do not see any commands I want to give my fridge..

To find the Device Number to use in Script above, just run this once, and check the log.
This lists all your devices in Smartthings - cloud

Code:
https = require('ssl.https') json = require('json') ltn12 = require('ltn12') token = 'Get your number from WEB-page' tbl = {} res, code = https.request({   url = 'https://api.smartthings.com/v1/devices',   method = 'GET',   headers = {     ['authorization'] = 'Bearer ' .. token,     ['content-type']  = 'application/json',   },   sink = ltn12.sink.table(tbl), }) if res and code == 200 then   resp = table.concat(tbl)   resp = json.pdecode(resp)   -- This lists a Table with all your information:     log(resp) else   log(res, code) end
Reply


Messages In This Thread
Samsung Fridge / Smartthing Rest API - by DarthPaul - 22.01.2021, 17:20

Forum Jump: