Accessing an API within a Samsung Edge Driver?

Hi all!

I want to see the outside temperature of my heating system in SmartThings. The heating system is not supported out of the box by SmartThings, but offers an API. I´ve already accessed the API with Postman and also were able to read out the outside temperature.

Now I´m struggling a little bit with Lua and SmartThings Edge drivers. I´ve already set up my development environment and read threw the documentation. I believe my config.yaml and profile.yaml are already finished. My init.lua is in progress:

For me it is at the moment unclear, where I set the temperature in the device? And how can I access a REST API within Lua? Any help is appreciated :slight_smile:

Thank you

It might be easier to use an existing Edge driver that can do HTTP requests. See [ST Edge] Web Requestor: a driver to issue local POST and GET HTTP requests. Also note, since Edge drivers are running on your hub, they can only connect to private IP addresses. Connecting outside your local LAN requires a proxy device.

If you would like to continue on the path of creating your own Edge driver, you can use Todd’s repo for his driver as a reference for how to do HTTP requests in Lua.


Hi h0ckeysk8er!

Thanky for your reply! I did a research on existing drivers, but missed this one… Did learn a lot from it regarding requests, but I only need one fixed GET request and in SmartThings it should show as an temperature device. So, i will continue on my own driver.

What I still dont get is how to set the shown temperature in the device. In my attached example it must happen somewhere in do_refresh(). Could you give me maybe an example to set it to an constant temperature, lets say 20 degrees? That would be a great help for me :slight_smile:

Thank you and best regards

I think you are asking how to set the value of the temperature capability so that it displays in the mobile app. To set that, you need to generate an event so that the mobile app will know that the value has been updated. Here is an example:

  event["data"] = { codeId = code_id, codeName = code_name, method = event["data"].method}
1 Like

Hi, @LordDeSith. Welcome to the SmartThings Community!

So, you already got the value of the temperature but you’re wondering how to send that value?

To update a capability status, you need to send a capability event, in the case of the temperatureMeasurement, the event should look like:

device:emit_event(capabilities.temperatureMeasurement.temperature({value=12, unit="C"}))

By the way, in the pictures you shared in the first post, your init.lua has an extra i on its name.
Also, in LAN drivers, the default handlers are not effective because they only work for Zigbee, Z-Wave and Matter devices.



thanks for your hints and feedback. I think I have reduced the driver to the absolute minimum for now:

I now have uploaded (via smartthings CLI and channels) to my hub and I´m possible to see my driver in the hub driver list. But I am not able to add my driver as a device to my home? Any hints on that one? :slight_smile:

Thanks and best regards

Did you define a device profile and presentation? Those define “what” the device is and how it should be displayed in the mobile app. Review this documentation for the process of creating/defining devices.

1 Like

Yes, read about ‘discovery’.

You are creating a LAN driver. When you ‘Add device’ in SmartThings the hub runs the discovery handlers of the LAN drivers so they can probe the network to see if there is a device on the network that they need to support. If they find a new one they then create a device for it. There is also a simplified approach where the driver only ever creates a single device in discovery with already known details.


thanks for your answers :slight_smile:

I did create a profile, as you can see in the image above (temperature.yaml).

You mean if I implement the discovery handler of the lan capability, the device will show up? There is actually no physical device on LAN, because I´d like to emulate a temperature sensor, which shows 12°C at the moment. Later, I will gather the actually temperature via REST calls.

Made some progress today. This are the versions of my files at the moment:

When I run the driver discovery in SmartThings, I get the following error in the logs:
2024-04-22T12:21:30.346465973Z ERROR Temperature discovery thread encountered error: [string “st/driver.lua”]:502: assertion failed!
I log the type of the variable metadata and it says table, but why is the assertion failing in driver line 502?

Thankful for any hints on that one :slight_smile:

I used the same configuration you did and I didn’t get that error. The only difference I see are the extra spaces in the imports, see my sample:

Also, please verify the structure of your driver is correct:

Hi @nayelyz

Thanks for your effort rebuilding my driver.

I removed the additional spaces and checked the structure of the driver, should be okey:

Furthermore, I logged the assertion of driver.lua line 502, which is true inside my function… I dont get, where the problem is…

Sorry for the late reply.
I found the error, you’re using driver.try_create_device(metadata) and it should be driver:try_create_device(metadata) or driver.try_create_device(driver, metadata).
Either of the last two lines allows the device creation, this is because using : includes the self parameter (of the object driver) in the call which is the same as driver.try_create_device(driver, metadata).


Omg, thanks on that one. Didnt recognize I used the dot there… And didnt know, that its possible to use both operators in Lua and whats the difference… Thank you!

Now its working fine, can find the device, shows the temperature. All okey.

I am wondering how often is SmartThings calling refresh of my device? I only see that it is called, when I do it manually in the app. Is there no automatic refresh?

Best regards