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:
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.
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
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:
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.
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?
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.
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.
@h0ckeysk8er
I did create a profile, as you can see in the image above (temperature.yaml).
@orangebucket
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.
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?
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?