Logic Machine Forum
Samsung Fridge / Smartthing Rest API - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Samsung Fridge / Smartthing Rest API (/showthread.php?tid=3121)



Samsung Fridge / Smartthing Rest API - DarthPaul - 22.01.2021

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



RE: Samsung Fridge / Smartthing Rest API - CristianAgata - 28.01.2023

Hi Admin and DarthPaul,
I'm working across SmartThings with Samsung TV, I've read the device, I can understand how get the command.
Anyone can help me?
Best regards Cristian


RE: Samsung Fridge / Smartthing Rest API - admin - 30.01.2023

First you need to get the list of devices (/v1/devices). This way you will know the unique ID for each device. Then you can use this ID to get the device status and control it.


RE: Samsung Fridge / Smartthing Rest API - CristianAgata - 30.01.2023

(30.01.2023, 06:46)admin Wrote: First you need to get the list of devices (/v1/devices). This way you will know the unique ID for each device. Then you can use this ID to get the device status and control it.

Hi admin,
Thanks and it works.
Best regards Cristian


RE: Samsung Fridge / Smartthing Rest API - AlexLV - 04.02.2023

Hi,

I trying to see my device capabilities, but as I see, there is too many info - in capabilities table is written "nesting too deep".

How is possible to see hidden info?

Alex


RE: Samsung Fridge / Smartthing Rest API - admin - 06.02.2023

See this: https://forum.logicmachine.net/showthread.php?tid=4334
You can also use a third-party tool (like Postman) to send this request and check the full JSON response.