Filter
-
Content Type
-
Category
Mobile/Wearable
Visual Display
Digital Appliance
Platform
Recommendations
Filter
announcement iot
blogsince launching 10 years ago, smartthings has been at the forefront of the smart home space, providing delightful experiences that have allowed users to connect their homes and control a multitude of devices from a huge number of hardware manufacturers, growing to include unique features with samsung tvs and appliances. one of the most popular methods to integrate devices into the smartthings platform has been to connect directly to hubs in the home, using radio protocols such as zigbee and z-wave. to date, smartthings has used the groovy programming language to facilitate these device communications. while the groovy framework has allowed developers a great amount of flexibility, the connected home is fast outgrowing this technology and therefore smartthings has had to evolve. beginning september 30, 2022, groovy device dths, smartapps built on groovy, and the developer ide will be removed from the smartthings platform and will no longer be supported. edge drivers using lua have replaced the legacy groovy dths for controlling devices. as has been the topic of many communications throughout this transition, edge reduces the need to send device commands or automations to the smartthings cloud for processing and they are now processed right on the hub, reducing latency and increasing reliability across the connected home. a list of available edge drivers can be found here. as the door closes on groovy-based smartapps, a new door opens for developers with the rules api. developers can build simple or complex automations based on any number of triggers to customize experiences using common action, command, and operand semantics. additional processes and features, such as integrating a manual command, can be developed using the scenes api. smartthings is leading the development and launch of the matter industry standard along with ecosystem partners and members of the connectivity standards alliance. this common protocol will revolutionize the connected home for end users and developers alike. the journey so far has been an exciting one, and the launch of edge drivers and rules apis are the first steps toward taking smartthings and our developer community to more places than we could have imagined months ago when we first announced these updates. stay tuned for more matter announcements as we approach its launch this fall!
SmartThings Developers
Connect Samsung Developer Conference
webtech session platform innovation, iot, open source, developer program smartthings and matter matter is rapidly becoming the most popular iot protocol in the smart home, with support from over 300 industry-leading and innovative companies from across the world. matter is a universal ip-based communication protocol for smart home devices that makes them simple to buy and set up, interoperable, reliable, and secure. smartthings, as one of the first adopters of the matter standard, currently provides matter hub capabilities across samsung tvs, smart monitors, sound bars, family hub fridges, as well as the smartthings station. developers are welcomed to learn about new tools for building matter devices that connect with these hubs. learn about enhancements smartthings is making to our architecture, and how device partners can take advantage of them. in addition to supporting the core features of your matter devices, we’re announcing new tools and integrations to make it easier to develop innovative smart devices and apps, and integrate them with smartthings. these include our new developer center, smartthings home api, multi-hub support, hub-replacement, and our hub everywhere strategy. speakers charles kim samsung electronics zach michel smartthings back to list
tutorials iot
blogmatter is an open-source connectivity standard for smart home and internet of things (iot) devices. it is a secure, reliable, and seamless cross-platform protocol for connecting compatible devices and systems with one another. smartthings provides the matter virtual device application and the smartthings home apis to help you quickly develop matter devices and use the smartthings ecosystem without needing to build your own iot ecosystem. when matter was first introduced, because few devices supported it, platform companies struggled to test and optimize matter support on their own devices. to alleviate this issue, samsung smartthings developed the matter virtual device application, which can be used to test and optimize various device types, including those that have not yet been released. the matter virtual device is part of the matter open source project you can create and test matter devices virtually too. in this tutorial, you will learn how to create an occupancy sensor as a matter virtual device that you can control using the smartthings application. you will also gain an understanding of the concept of clusters on matter devices. for more information about smartthings matter, see matter in smartthings. prerequisites to follow along with this tutorial, you need the following hardware and software: host pc running windows 10 or higher or ubuntu 20.04 (x64) android studio (latest version recommended) java se development kit (jdk) 11 or higher devices connected to the same network: mobile device running android 8.0 oreo or higher mobile device with the smartthings application installed matter-enabled smartthings station onboarded with the same samsung account as the smartthings application ※ for ubuntu, to set up the development environment: step 1. turn on developer mode and enable usb debugging on your mobile device. step 2. install the required os-specific dependencies from your terminal: $ sudo apt-get install git gcc g++ pkg-config libssl-dev libdbus-1-dev \ libglib2.0-dev libavahi-client-dev ninja-build python3-venv python3-dev \ python3-pip unzip libgirepository1.0-dev libcairo2-dev libreadline-dev step 3. from the sdk manager in android studio, install sdk platform 26 and ndk version 22.1.7171670. step 4. register the ndk path to the path environment variable: export android_ndk_home=[ndk path] export path=$path:${android_ndk_home} step 5. install kotlin compiler (kotlinc) version 1.5.10. step 6. register the kotlinc path to the path environment variable. export kotlinc_home=[kotlinc path]/bin export path=$path:${kotlinc_home} implement the occupancy sensor device type to implement the occupancy sensor device type in the matter virtual device application: step 1. download the sample application project and open it in android studio. sample code - virtual device app (11.11mb) nov 21, 2023 step 2. build and run the sample application. the application implements an on/off switch device type as an example. step 3. go to the file path feature > main > java > com.matter.virtual.device.app.feature.main. step 4. to add the occupancy sensor device type to the application home screen, in the mainfragment.kt file, select the device type: notefor all code examples in this tutorial, look for "todo #' in the sample application to find the location where you need to add the code. // todo 1 mainuistate.start -> { val itemlist = listof( device.onoffswitch, // sample device type // todo 1 device.occupancysensor, // add the occupancy sensor ) retrieve cluster values clusters are the functional building block elements of the data model. a cluster can be an interface, a service, or an object class, and it is the lowest independent functional element in the data model. each matter device supports a defined set of relevant clusters that can interact with your preferred controller (such as smartthings). this allows for easy information retrieval, behavior setting, event notifications, and more. the following steps are implemented in the file occupancysensorviewmodel.kt at the path feature > sensor > java > com.matter.virtual.device.app.feature.sensor. to retrieve the relevant cluster values from the device through the viewmodel: step 1. retrieve the current occupancy status. the boolean value is used by occupancyfragment to update the ui. // todo 2 private val _occupancy: stateflow<boolean> = getoccupancyflowusecase() val occupancy: livedata<boolean> get() = _occupancy.aslivedata() step 2. retrieve the current battery status. the integer value is used by occupancyfragment to update the ui. //todo 3 private val _batterystatus: mutablestateflow<int> = getbatpercentremainingusecase() as mutablestateflow<int> val batterystatus: livedata<int> get() = _batterystatus.aslivedata() step 3. when the "occupancy" button in occupancyfragment is pressed, use the setoccupancyusecase() function to update the occupancy status boolean value. // todo 4 viewmodelscope.launch { timber.d("current value = ${_occupancy.value}") if (_occupancy.value) { timber.d("set value = false") setoccupancyusecase(false) } else { timber.d("set value = true") setoccupancyusecase(true) } } step 4. when the "battery" slider in occupancyfragment is moved, store the slider progress as the battery status. // todo 5 batterystatus.value = progress step 5. when the "battery" slider in occupancyfragment is moved, use the updatebatteryseekbarprogress() function to update the battery status value on the slider. use setbatpercentremainingusecase() to update the battery status integer value. // todo 6 viewmodelscope.launch { updatebatteryseekbarprogress(progress) setbatpercentremainingusecase(progress) } monitor cluster values the observe() function monitors for and reacts to changes in a cluster value. the following steps are implemented in the file occupancysensorfragment.kt at the path feature > sensor > java > com.matter.virtual.device.app.feature.sensor. to monitor changes in the virtual occupancy sensor’s cluster values: step 1. trigger updating the occupancy status of the virtual device when the ”occupancy” button is pressed. // todo 7 binding.occupancybutton.setonclicklistener { viewmodel.onclickbutton() } step 2. use the onprogresschanged() function to update the fragment ui through live data from the viewmodel. the onstoptrackingtouch() function triggers updating the battery status when touch tracking on the “battery” slider stops. // todo 8 binding.occupancysensorbatterylayout.titletext.text = getstring(r.string.battery) binding.occupancysensorbatterylayout.seekbardata = seekbardata(progress = viewmodel.batterystatus) binding.occupancysensorbatterylayout.seekbar.setonseekbarchangelistener( object : seekbar.onseekbarchangelistener { override fun onprogresschanged(seekbar: seekbar, progress: int, fromuser: boolean) { viewmodel.updatebatteryseekbarprogress(progress) } override fun onstarttrackingtouch(seekbar: seekbar) {} override fun onstoptrackingtouch(seekbar: seekbar) { viewmodel.updatebatterystatustocluster(seekbar.progress) } } ) step 3. monitor the occupancy status and update the fragment ui when it changes. // todo 9 viewmodel.occupancy.observe(viewlifecycleowner) { if (it) { binding.occupancyvaluetext.text = getstring(r.string.occupancy_state_occupied) binding.occupancybutton.setimageresource(r.drawable.ic_occupied) } else { binding.occupancyvaluetext.text = getstring(r.string.occupancy_state_unoccupied) binding.occupancybutton.setimageresource(r.drawable.ic_unoccupied) } } step 4. monitor the battery status and update the fragment ui when it changes. // todo 10 viewmodel.batterystatus.observe(viewlifecycleowner) { val text: string = getstring(r.string.battery_format, it) binding.occupancysensorbatterylayout.valuetext.text = html.fromhtml(text, html.from_html_mode_legacy) } test the virtual device to test the virtual occupancy sensor device: step 1. build and run the project on your android device. the application’s home screen shows the sample on/off switch device type and the occupancy sensor device type that you just implemented. step 2. to create a virtual occupancy sensor device, select occupancy sensor and follow the instructions to receive a qr code. step 3. within the smartthings application on the other mobile device, onboard the occupancy sensor by scanning the qr code. step 4. change the occupancy or battery status of the virtual occupancy sensor in the virtual device application. the values are synchronized to the smartthings application. conclusion this tutorial demonstrates how you can implement the occupancy sensor device type in the matter virtual device application and create a virtual occupancy sensor for testing purposes. to learn about implementing other device types, go to code lab (matter: create a virtual device and make an open source distribution). the code lab also describes how to contribute to the matter open source project.
HyoJung Lee
Connect Samsung Developer Conference
websmartthings matter/hub the most comprehensive iot platform for matter.the matter-compatible smartthings hub has been deeply integrated across samsung tvs, family hub refrigerators, smart monitors, and mobile chargers. working together, these hubs can form a multi-hub network for wider coverage and better reliability. setting up a new hub is also easier than ever with our new hub replacement tool. back to list
Learn Code Lab
codelabmatter build a matter iot app with smartthings home api objective learn how to create an iot app to onboard, control, remove, and share matter devices using smartthings home apis notesmartthings home apis are distributed only to authorized users if you want permission to use the apis, contact st matter@samsung com overview matter is an open-source connectivity standard for smart home and internet of things iot devices it is a secure, reliable, and seamless cross-platform protocol for connecting compatible devices and systems with one another smartthings provides the matter virtual device app and smartthings home apis to help you quickly develop matter devices and use the smartthings ecosystem without needing to build your own iot ecosystem you can use smartthings home apis to onboard, control, remove, and share all matter devices when building your application other iot ecosystems can use the matter devices onboarded on your iot app through the multi-admin function for detailed information, go to partners smartthings com/matter set up your environment you will need the following host pc running on windows 10 or higher or ubuntu 20 04 x64 android studio latest version recommended java se development kit jdk 11 or later devices connected on the same network mobile device with matter virtual device app installed mobile device with developer mode and usb debugging enabled matter-enabled smartthings station onboarded with samsung account used for smartthings app tipyou can create a virtual device as a third-party iot device sample code noteyou can request permission to access the sample project file for this code lab by sending an email to st matter@samsung com start your project after downloading the sample code containing the project files, open your android studio and click open to open an existing project locate the downloaded android project from the directory and click ok commission the device you can onboard a matter-compatible device to the iot app by calling the commissiondevice api, which can lay the groundwork to control, remove, and share the device go to app > java > com samsung android matter home sample > feature > main in the mainviewmodel kt file, call the commissiondevice api to launch the onboarding activity and join the device to the smarththings fabric // ================================================================================= // codelab // step 1 create an instance of matter commissioning client // step 2 call the commissiondevice api to launch the onboarding activity in home service // step 3 set _intentsender value from return value of commissiondevice api // todo 1 device commission and join a device to smartthings fabric // todo 1 uncomment the following code blocks // --------------------------------------------------------------------------------- //val commissioningclient = matter getcommissioningclient //val intentsender = commissioningclient commissiondevice context //_intentsender value = intentsender // ================================================================================= control the device capabilities are core to the smartthings architecture they abstract specific devices into their underlying functions, which allows the retrieval of the state of a device component or control of the device function each device has its own appropriate capabilities therefore, each device has a different control api, and the more functions it supports, the more apis it has to use in this step, select a device type that you want to onboard and control using necessary home apis the level of modification complexity is assigned per each device contact sensorlevel 1 3 mins file path app > java > com samsung android matter home sample > feature > device file name contactsensorviewmodel kt // ================================================================================= // codelab level 1 // step 1 get contactsensor capability from device instance // step 2 get stream openclose value from contactsensor capability // step 3 set _openclose value for ui updating // todo 1 uncomment the following code blocks // --------------------------------------------------------------------------------- //device readcapability contactsensor ? openclose? collect { openclose -> // _openclose value = openclose //} // ================================================================================= // ================================================================================= // codelab level 1 // step 1 get battery capability from device instance // step 2 get stream battery value from battery capability // step 3 set _batterystatus value for ui updating // todo 2 uncomment the following code blocks // --------------------------------------------------------------------------------- //device readcapability battery ? battery? collect { battery -> // _batterystatus value = battery //} // ================================================================================= motion sensorlevel 1 3 mins file path app > java > com samsung android matter home sample > feature > device file name motionsensorviewmodel kt // ================================================================================= // codelab level 1 // step 1 get motionsensor capability from device instance // step 2 get stream occupied value from motionsensor capability // step 3 set _motionoccupied value for ui updating // todo 1 uncomment the following code blocks // --------------------------------------------------------------------------------- //device readcapability motionsensor ? occupied? collect { motionoccupied -> // _motionoccupied value = motionoccupied // timber d "occupied= $motionoccupied" //} // ================================================================================= // ================================================================================= // codelab level 1 // step 1 get battery capability from device instance // step 2 get stream battery value from battery capability // step 3 set _batterystatus value for ui updating // todo 2 uncomment the following code blocks // --------------------------------------------------------------------------------- //device readcapability battery ? battery? collect { battery -> // _batterystatus value = battery // timber d "battery= $battery" //} // ================================================================================= on-off switchlevel 2 4 mins file path app > java > com samsung android matter home sample > feature > device file name switchviewmodel kt // ================================================================================= // codelab level 2 // step 1 get switch capability from device instance // step 2 get stream onoff value from switch capability // step 3 set _onoff value for ui updating // todo 1 uncomment the following code blocks // --------------------------------------------------------------------------------- //device readcapability switch ? onoff? collect { onoff -> // _onoff value = onoff //} // ================================================================================= // ================================================================================= // codelab level 2 // step 1 get switch capability from device instance // step 2 control the device using the apis that supported by switch capability // toggle switch state based on onoff value // onoff == true call switch off // onoff == false call switch on // todo 2 uncomment the following code blocks // --------------------------------------------------------------------------------- //device readcapability switch ? let { switch -> // if onoff == true { // switch off // } else { // switch on // } //} // ================================================================================= smart locklevel 3 8 mins file path app > java > com samsung android matter home sample > feature > device file name smartlockviewmodel kt // ================================================================================= // codelab level 3 // step 1 get lock capability from device instance // step 2 get stream lockunlock value from lock capability // step 3 set _lockstatus value for ui updating // --------------------------------------------------------------------------------- // todo 1 copy code below device readcapability lock ? lockunlock? collect { lockunlock -> _lockstatus value = lockunlock } // ================================================================================= // ================================================================================= // codelab level 3 // step 1 get tamperalert capability from device instance // step 2 get stream tamperalert value from tamperalert capability // step 3 set _tamperstatus value for ui updating // --------------------------------------------------------------------------------- // todo 2 copy code below device readcapability tamperalert ? tamperalert? collect { tamperalert -> _tamperstatus value = tamperalert } // ================================================================================= // ================================================================================= // codelab level 3 // step 1 get battery capability from device instance // step 2 get stream battery value from battery capability // step 3 set _batterystatus value for ui updating // --------------------------------------------------------------------------------- // todo 3 copy code below device readcapability battery ? battery? collect { battery -> _batterystatus value = battery } // ================================================================================= // ================================================================================= // codelab level 3 // step 1 get lock capability from device instance // step 2 control the device using the apis that supported by lock capability // toggle lock state based on lockunlock value // lockunlock == true call lock // lockunlock == false call unlock // --------------------------------------------------------------------------------- // todo 4 copy code below device readcapability lock ? let { lock -> if lockunlock == true { lock lock } else { lock unlock } } // ================================================================================= blindslevel 3 8 mins file path app > java > com samsung android matter home sample > feature > device file name blindviewmodel kt // ================================================================================= // codelab level 3 // step 1 get windowshade capability from device instance // step 2 get stream windowshademode value from windowshade capability // step 3 set _windowshademode value for ui updating // --------------------------------------------------------------------------------- // todo 1 copy code below device readcapability windowshade ? windowshademode? collect { windowshademode -> timber d "windowshademode $windowshademode" _windowshademode value = windowshademode } // ================================================================================= // ================================================================================= // codelab level 3 // step 1 get windowshadelevel capability from device instance // step 2 get stream shadelevel value from windowshadelevel capability // step 3 set _shadelevel value for ui updating // --------------------------------------------------------------------------------- // todo 2 copy code below device readcapability windowshadelevel ? shadelevel? collect { shadelevel -> timber d "shadelevel $shadelevel" _shadelevel value = shadelevel } // ================================================================================= // ================================================================================= // codelab level 3 // step 1 get battery capability from device instance // step 2 get stream battery value from battery capability // step 3 set _batterystatus value for ui updating // --------------------------------------------------------------------------------- // todo 3 copy code below device readcapability battery ? battery? collect { battery -> _batterystatus value = battery } // ================================================================================= // ================================================================================= // codelab level 3 // step 1 get windowshade capability from device instance // step 2 control the device using the apis that supported by windowshade capability // send windowshade open/close/pause command based on controlcommand value // "open" call windowshade open // "close" call windowshade close // "pause" call windowshade pause // --------------------------------------------------------------------------------- // todo 4 copy code below device readcapability windowshade ? let { windowshade -> when controlcommand { "open" -> windowshade open "close" -> windowshade close "pause" -> windowshade pause } } // ================================================================================= extended color lightlevel 4 10 mins file path app > java > com samsung android matter home sample > feature > device file name lightviewmodel kt // ================================================================================= // codelab level 4 // step 1 get switch capability from device instance // step 2 get stream onoff value from switch capability // step 3 set _onoff value for ui updating // --------------------------------------------------------------------------------- // todo 1 copy code below device readcapability switch ? onoff? collect { onoff -> _onoff value = onoff } // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get switchlevel capability from device instance // step 2 get stream level value from switchlevel capability // step 3 set _level value for ui updating // --------------------------------------------------------------------------------- // todo 2 copy code below device readcapability switchlevel ? level? collect { level -> _level value = level } // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get switch capability from device instance // step 2 control the device using the apis that supported by switch capability // toggle switch state based on onoff value // onoff == true call switch off // onoff == false call switch on // --------------------------------------------------------------------------------- // todo 3 copy code below device readcapability switch ? let { switch -> if onoff == true { switch off } else { switch on } } // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get switchlevel capability from device instance // step 2 control the device using the apis that supported by switchlevel capability // call switchlevel setlevel with percentage value // --------------------------------------------------------------------------------- // todo 4 copy code below timber d "target position = $percentage" device readcapability switchlevel ? setlevel percentage // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get colorcontrol capability from device instance // step 2 control the device using the apis that supported by colorcontrol capability // call colorcontrol setcolor with hue,saturation value // --------------------------------------------------------------------------------- // todo 5 copy code below timber d "hue $hue,saturation $saturation" device readcapability colorcontrol ? setcolor hue todouble , saturation todouble // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get colortemperature capability from device instance // step 2 control the device using the apis that supported by colortemperature capability // call colortemperature setcolortemperature with temperature // --------------------------------------------------------------------------------- // todo 6 copy code below device readcapability colortemperature ? setcolortemperature temperature // ================================================================================= video playerlevel 4 10 mins file path app > java > com samsung android matter home sample > feature > device file name televisionviewmodel kt // ================================================================================= // codelab level 4 // step 1 get switch capability from device instance // step 2 get stream onoff value from switch capability // step 3 set _onoff value for ui updating // --------------------------------------------------------------------------------- // todo 1 copy code below device readcapability switch ? onoff? collect { onoff -> _onoff value = onoff } // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get mediaplayback capability from device instance // step 2 get stream mediaplaybackstate value from mediaplayback capability // step 3 set _mediaplaybackstate value for ui updating // --------------------------------------------------------------------------------- // todo 2 copy code below device readcapability mediaplayback ? mediaplaybackstate? collect { mediaplaybackstate -> _mediaplaybackstate value = mediaplaybackstate } // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get switch capability from device instance // step 2 control the device using the apis that supported by switch capability // toggle switch state based on onoff value // onoff == true call switch off // onoff == false call switch on // --------------------------------------------------------------------------------- // todo 3 copy code below device readcapability switch ? let { switch -> if onoff == true { switch off } else { switch on } } // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get mediaplayback capability from device instance // step 2 control the device using the apis that supported by mediaplayback capability // send mediaplayback play/pause/stop/rewind/fastforward command based on controlcommand value // "play" call mediaplayback play and setplaybackstatus with playbackstatus playing // "pause" call mediaplayback pause and setplaybackstatus with playbackstatus paused // "stop" call mediaplayback stop and setplaybackstatus with playbackstatus stopped // "rewind" call mediaplayback rewind and setplaybackstatus with playbackstatus rewinding // "fastforward" call mediaplayback fastforward and setplaybackstatus with playbackstatus fastforwarding // --------------------------------------------------------------------------------- // todo 4 copy code below device readcapability mediaplayback ? let { mediaplayback -> when controlcommand { "play" -> { mediaplayback play mediaplayback setplaybackstatus playbackstatus playing } "pause" -> { mediaplayback pause mediaplayback setplaybackstatus playbackstatus paused } "stop" -> { mediaplayback stop mediaplayback setplaybackstatus playbackstatus stopped } "rewind" -> { mediaplayback rewind mediaplayback setplaybackstatus playbackstatus rewinding } "fastforward" -> { mediaplayback fastforward mediaplayback setplaybackstatus playbackstatus fastforwarding } } } // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get mediatrackcontrol capability from device instance // step 2 control the device using the apis that supported by mediatrackcontrol capability // send mediatrack nexttrack/previoustrack command based on controlcommand value // "nexttrack" call mediatrack nexttrack // "previoustrack" call mediatrack previoustrack // --------------------------------------------------------------------------------- // todo 5 copy code below device readcapability mediatrackcontrol ? let { mediatrack -> when controlcommand { "nexttrack" -> mediatrack nexttrack "previoustrack" -> mediatrack previoustrack } } // ================================================================================= // ================================================================================= // codelab level 4 // step 1 get keypadinput capability from device instance // step 2 control the device using the apis that supported by keypadinput capability // call keypadinput sendkey with key value // --------------------------------------------------------------------------------- // todo 6 copy code below device readcapability keypadinput ? sendkey key // ================================================================================= thermostatlevel 5 13 mins file path app > java > com samsung android matter home sample > feature > device file name thermostatviewmodel kt // ================================================================================= // codelab level 5 // step 1 get thermostatmode capability from device instance // step 2 get stream thermostatmode value from thermostatmode capability // step 3 set _systemmode value for ui updating // --------------------------------------------------------------------------------- // todo 1 copy code below device readcapability thermostatmode ? thermostatmode? collect { thermostatmode -> timber d "viewmodel thermostatmode $thermostatmode" _systemmode value = thermostatmode } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get thermostatfanmode capability from device instance // step 2 get stream thermostatfanmode value from thermostatfanmode capability // step 3 set _fanmode value for ui updating // --------------------------------------------------------------------------------- // todo 2 copy code below device readcapability thermostatfanmode ? thermostatfanmode? collect { fanmode -> _fanmode value = fanmode } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get temperaturemeasurement capability from device instance // step 2 get stream temperature value from temperaturemeasurement capability // step 3 set _temperature value for ui updating // --------------------------------------------------------------------------------- // todo 3 copy code below device readcapability temperaturemeasurement ? temperature? collect { temperature -> _temperature value = temperature } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get thermostatcoolingsetpointbattery capability from device instance // step 2 get stream coolingsetpoint value from thermostatcoolingsetpoint capability // step 3 set _occupiedcoolingsetpoint value for ui updating // --------------------------------------------------------------------------------- // todo 4 copy code below device readcapability thermostatcoolingsetpoint ? coolingsetpoint? collect { coolingsetpoint -> _occupiedcoolingsetpoint value = coolingsetpoint } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get thermostatheatingsetpoint capability from device instance // step 2 get stream heatingsetpoint value from thermostatheatingsetpoint capability // step 3 set _occupiedheatingsetpoint value for ui updating // --------------------------------------------------------------------------------- // todo 5 copy code below device readcapability thermostatheatingsetpoint ? heatingsetpoint? collect { heatingsetpoint -> _occupiedheatingsetpoint value = heatingsetpoint } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get relativehumiditymeasurement capability from device instance // step 2 get stream humidity value from relativehumiditymeasurement capability // step 3 set _humidity value for ui updating // --------------------------------------------------------------------------------- // todo 6 copy code below device readcapability relativehumiditymeasurement ? humidity? collect { humidity -> _humidity value = humidity } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get battery capability from device instance // step 2 get stream battery value from battery capability // step 3 set _batterystatus value for ui updating // --------------------------------------------------------------------------------- // todo 7 copy code below device readcapability battery ? battery? collect { battery -> _batterystatus value = battery } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get thermostatmode capability from device instance // step 2 control the device using the apis that supported by thermostatmode capability // change thermostatmode state based on systemmode value // thermostatsystemmode off call thermostatmode off // thermostatsystemmode cool call thermostatmode cool // thermostatsystemmode heat call thermostatmode heat // thermostatsystemmode auto call thermostatmode auto // --------------------------------------------------------------------------------- // todo 8 copy code below device readcapability thermostatmode ? let { thermostatmode -> when systemmode { thermostatsystemmode off -> thermostatmode off thermostatsystemmode cool -> thermostatmode cool thermostatsystemmode heat -> thermostatmode heat thermostatsystemmode auto -> thermostatmode auto } } // ================================================================================= // ================================================================================= // step 1 get thermostatfanmode capability from device instance // step 2 control the device using the apis that supported by thermostatfanmode capability // change thermostatfanmode state based on fanmode value // thermostatfanmodeenum auto call thermostatfanmode fanauto // thermostatfanmodeenum circulate call thermostatfanmode fancirculate // thermostatfanmodeenum followschedule call thermostatfanmode setthermostatfanmode with followschedule // thermostatfanmodeenum on call thermostatfanmode fanon // --------------------------------------------------------------------------------- // todo 9 copy code below device readcapability thermostatfanmode ? let { thermostatfanmode -> when fanmode { thermostatfanmodeenum auto -> thermostatfanmode fanauto thermostatfanmodeenum circulate -> thermostatfanmode fancirculate thermostatfanmodeenum followschedule -> thermostatfanmode setthermostatfanmode "followschedule" thermostatfanmodeenum on -> thermostatfanmode fanon } } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get thermostatheatingsetpoint capability value from device instance // step 2 increase _occupiedheatingsetpoint value that have current heating value // step 3 if new increased value is under value_max 104 , // call setheatingsetpoint of thermostatheatingsetpoint capability with new increased value // --------------------------------------------------------------------------------- // todo 10 copy code below device readcapability thermostatheatingsetpoint ? let { heatingsetpoint -> val nextvalue = _occupiedheatingsetpoint value!! + 1 if nextvalue < value_max { heatingsetpoint setheatingsetpoint nextvalue } } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get thermostatheatingsetpoint capability value from device instance // step 2 decrease _occupiedheatingsetpoint value that have current heating value // step 3 if new decreased value is over value_min 32 , // call setheatingsetpoint of thermostatheatingsetpoint capability with new decreased value // --------------------------------------------------------------------------------- // todo 11 copy code below device readcapability thermostatheatingsetpoint ? let { heatingsetpoint -> val nextvalue = _occupiedheatingsetpoint value!! - 1 if nextvalue > value_min { heatingsetpoint setheatingsetpoint nextvalue } } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get thermostatcoolingsetpoint capability value from device instance // step 2 increase _occupiedcoolingsetpoint value that have current cooling value // step 3 if new increased value is under value_max 104 , // call setcoolingsetpoint of thermostatcoolingsetpoint capability with new increased value // --------------------------------------------------------------------------------- // todo 12 copy code below device readcapability thermostatcoolingsetpoint ? let { coolingsetpoint -> val nextvalue = _occupiedcoolingsetpoint value!! + 1 if nextvalue < value_max { coolingsetpoint setcoolingsetpoint nextvalue } } // ================================================================================= // ================================================================================= // codelab level 5 // step 1 get thermostatcoolingsetpoint capability value from device instance // step 2 decrease _occupiedcoolingsetpoint value that have current cooling value // step 3 if new decreased value is over value_min 32 , // call setcoolingsetpoint of thermostatcoolingsetpoint capability with new decreased value // --------------------------------------------------------------------------------- // todo 13 copy code below device readcapability thermostatcoolingsetpoint ? let { coolingsetpoint -> val nextvalue = _occupiedcoolingsetpoint value!! - 1 if nextvalue > value_min { coolingsetpoint setcoolingsetpoint nextvalue } } // ================================================================================= noteyou can find related files in android studio by going to edit menu> find > find in files and entering the keyword "codelab" remove the device using removedevice api, you can remove the device from your iot app and the smartthings fabric go to app > java > com samsung android matter home sample > feature > device > base in the baseviewmodel kt file, call the removedevice api to launch the removedevice activity // ================================================================================= // [codelab] device remove from smartthings fabric // step 1 create an instance of matter commissioning client // step 2 call the removedevice api to launch the removedevice activity in home service // step 3 set _intentsender value from return value of removedevice api // todo 1 uncomment the following code blocks // --------------------------------------------------------------------------------- //val commissioningclient = matter getcommissioningclient //val intentsender = commissioningclient removedevice // context, // commissioningclient removedevicerequest deviceid // //_intentsenderforremovedevice value = intentsender // ================================================================================= share the device matter devices can be shared with other matter-compatible iot platforms, such as google home, using home apis without resetting the device while connected to smartthings to perform this operation, it is necessary to enter the commissioning mode without resetting the device in the baseviewmodel kt file, call the sharedevice api to launch the sharedevice activity // ================================================================================= // [codelab] device share to other platforms // step 1 create an instance of matter commissioning client // step 2 call the sharedevice api to launch the sharedevice activity in home service // step 3 set _intentsender value from return value of sharedevice api // todo 1 uncomment the following code blocks // --------------------------------------------------------------------------------- //val commissioningclient = matter getcommissioningclient //val intentsender = commissioningclient sharedevice // context, // commissioningclient sharedevicerequest deviceid // //_intentsenderforsharedevice value = intentsender // ================================================================================= build and run the iot app run the sample app to build and run your iot app, follow these steps using a usb cable, connect your mobile device select the sample iot app from the run configurations menu in the android studio then, select the connected device in the target device menu click run onboard to onboard the virtual device go to the matter virtual device app then, select and set up the virtual device type you want to control click save click start to show the qr code for onboarding go to the sample iot app and click the + button then, onboard the virtual device by scanning its qr code control by sample iot app in the sample iot app, control the virtual device by using its various functions such as on and off for switch you're done! congratulations! you have successfully achieved the goal of this code lab topic now, you can create a matter-compatible iot application with smartthings home apis by yourself! learn more by going to smartthings matter libraries
tutorials iot
blogmatter is an open-source connectivity standard for smart home and internet of things (iot) devices. it is a secure, reliable, and seamless cross-platform protocol for connecting compatible devices and systems with one another. smartthings provides the matter virtual device application and smartthings home apis to help you quickly develop matter devices and use the smartthings ecosystem without needing to build your own iot ecosystem. supporting iot devices that can be operated from outside the home requires significant infrastructure investment. a cloud server must be built and maintained to deliver commands to the home, and if the device uses a mesh network technology such as thread, the user needs to have a supported hub in the home. users are also typically uninterested in purchasing multiple hubs to support all the brands of iot devices that they own. the smartthings home api, announced at sdc 2023, allows you to leverage the smartthings infrastructure for your own matter and iot products. the api enables you to use the smartthings cloud, which means your application can support matter devices connected to any of the 1.7 million smartthings hubs worldwide. in this tutorial, you will learn how to use the smartthings home apis to develop an iot application that onboards, controls, shares, and removes a smart lock device. for more information about smartthings matter, see matter in smartthings. prerequisites to follow along with this tutorial, you need the following hardware and software: host pc running on windows 10 (or higher) or ubuntu 20.04 (x64) android studio (latest version recommended) java se development kit (jdk) 11 or later mobile devices & smartthings station connected on the same network: mobile device with matter virtual device application installed mobile device with developer mode and usb debugging enabled matter-enabled smartthings station onboarded with the samsung account used for smartthings notethe smartthings home api materials, including the sample application project for this tutorial, are distributed only to authorized users. if you want permission to use the apis, contact st.matter@samsung.com. commission the device to onboard a matter-compatible device to your iot application, you must commission the device, joining it to the smartthings fabric. download the sample application project and open it in android studio. the following steps are implemented in the mainviewmodel.kt file at the path app > java > com.samsung.android.matter.home.sample > feature > main. step 1. create an instance of the matter commissioning client. step 2. call the commissiondevice() function to launch the onboarding activity in home service. step 3. set the value of _intentsender.value to the returned value. // todo 1 val commissioningclient = matter.getcommissioningclient() val intentsender = commissioningclient.commissiondevice(context) _intentsender.value = intentsender notefor all code examples in this tutorial, look for "todo #' in the sample application to find the location where you need to add the code. control the device capabilities are the core of the smartthings architecture. they abstract devices into their underlying functionalities, which allows you to retrieve the state of a specific device component or control specific functionality. each device has its own set of appropriate capabilities, each controlled with its own api function. consequently, the more capabilities the device supports, the more application code is needed to implement it. the following steps demonstrate implementing the capabilities for a smart lock device. they are implemented in the smartlockviewmodel.kt file at the path app > java > com.samsung.android.matter.home.sample > feature > device. step 1. to retrieve lock, tamper and battery status of a device capability: a. retrieve the appropriate capability from the device instance. b. extract the stream value for the appropriate feature from the capability. c. store the retrieved value for updating the ui. // todo 2 device.readcapability(lock)?.lock?.collect { lockunlock -> _lockstatus.value = lockunlock } // todo 3 device.readcapability(tamperalert)?.tamper?.collect { tamperalert -> _tamperstatus.value = tamperalert } // todo 4 device.readcapability(battery)?.battery?.collect { battery -> _batterystatus.value = battery } step 2. to control the lock status: a. retrieve the lock capability from the device instance. b. if lockstatus is unlock, call lock() function to close it. c. if lockstatus is not unlock, call unlock() function to open it. // todo 5 device.readcapability(lock)?.let { lock -> when (_lockstatus.value) { lockstatus.unlocked.statusname -> lock.lock() else -> lock.unlock() } } share the device using the smartthings home api, you can share matter devices connected to smartthings with other matter-compatible iot platforms without resetting the device. this enables the user to control the same device through additional controller applications, such as google home. the following steps are implemented in the baseviewmodel.kt file at the path app > java > com.samsung.android.matter.home.sample > feature > device > base. step 1. create an instance of the matter commissioning client. step 2. to launch the sharedevice activity in home service, call the sharedevice() function. step 3. set the value of _intentsenderforsharedevice.value to the returned value. // todo 6 val commissioningclient = matter.getcommissioningclient() val intentsender = commissioningclient.sharedevice( context, commissioningclient.sharedevicerequest(deviceid) ) _intentsenderforsharedevice.value = intentsender remove the device you can remove the device from the iot application and the smartthings fabric. the following steps are implemented in the baseviewmodel.kt file at the path app > java > com.samsung.android.matter.home.sample > feature > device > base. step 1. create an instance of the matter commissioning client. step 2. to launch the removedevice activity in home service, call the removedevice() function. step 3. set the value of _intentsenderforremovedevice.value to the returned value. // todo 7 val commissioningclient = matter.getcommissioningclient() val intentsender = commissioningclient.removedevice( context, commissioningclient.removedevicerequest(deviceid) ) _intentsenderforremovedevice.value = intentsender test the application to test the sample iot application with a virtual smart lock device: step 1. build and run the project on your android device. when you launch the application, it is synced to the smartthings application and your connected matter devices and hubs are listed on the home screen. step 2. to create a virtual smart lock device: a. launch the matter virtual device application on your other mobile device. b. select “door lock,” then tap “save” and “start” to receive a qr code. step 3. within the sample iot application, to onboard the virtual smart lock, tap “+” and scan the qr code. step 4. to lock and unlock the virtual smart lock, tap the button in the iot application. conclusion this tutorial has demonstrated how you can create an application to onboard and control a smart lock using the smartthings home api. to learn about onboarding and controlling other device types, go to code lab (matter: build a matter iot app with smartthings home api). for more information about smartthings matter, see matter in smartthings.
HyoJung Lee
Learn Code Lab
codelabmatter create a virtual device and make an open source contribution objective learn how to create a matter virtual device, which you can control using the smartthings app also, know how to contribute your code to matter open source overview matter is an open-source connectivity standard for smart home and internet of things iot devices it is a secure, reliable, and seamless cross-platform protocol for connecting compatible devices and systems with one another smartthings provides the matter virtual device app and smartthings home apis to help you quickly develop matter devices and use the smartthings ecosystem without needing to build your own iot ecosystem you can use smartthings home apis to onboard, control, remove, and share all matter devices when building your application other iot ecosystems can use the matter devices onboarded on your iot app through the multi-admin function notethis code lab focuses only on creating a matter virtual device you can control using the smartthings app to learn how to make your controller app, see build a matter iot app with smartthings home apis for detailed information, go to partners smartthings com/matter set up your environment you will need the following host pc running on windows 10 or higher or ubuntu 20 04 x64 android studio latest version recommended java se development kit jdk 11 or later devices connected on the same network mobile device with android 8 0 oreo or higher operating system os mobile device with smartthings app installed matter-enabled smartthings station onboarded with samsung account used for smartthings app initial setup turn on developer mode and enable usb debugging option on your mobile device install a few os-specific dependencies by entering the below command in your terminal window $ sudo apt-get install git gcc g++ pkg-config libssl-dev libdbus-1-dev \ libglib2 0-dev libavahi-client-dev ninja-build python3-venv python3-dev \ python3-pip unzip libgirepository1 0-dev libcairo2-dev libreadline-dev to build the matter virtual device app, install sdk platform 26 and ndk version 22 1 7171670 using sdk manager in android studio after installing ndk, register the ndk path to the env path export android_ndk_home=[ndk path] export path=$path ${android_ndk_home} install kotlin compiler kotlinc version 1 5 10 after installing kotlinc, register the kotlinc path to the env path export kotlinc_home=[kotlinc path]/bin export path=$path ${kotlinc_home} sample code here is a sample code for you to start coding in this codelab download it and start your learning experience! matter virtual device sample code 11 42 mb start your project after downloading the sample code containing the project files, open your android studio and click open to open an existing project locate the downloaded android project from the directory and click ok select and create the device type when you build and run the sample matter virtual device app, you can see the already added on/off switch aside from the switch, other types of devices you can create are already prepared in the sample app noterefer to the matter device library specification for the list of matter devices you can create go to feature > main > java > com matter virtual device app feature main in the mainfragment kt file, select the device type you want to create mainuistate start -> { // =================================================================================== // codelab // todo uncomment the following lines to add your own device type // ----------------------------------------------------------------------------------- val itemlist = listof device onoffswitch, // sample // device occupancysensor, // level 1 8+ mins // device contactsensor, // level 2 8+ mins // device videoplayer, // level 2 10+ mins // device doorlock, // level 3 15+ mins // device extendedcolorlight, // level 3 15+ mins // device windowcovering, // level 4 17+ mins // device thermostat, // level 5 20+ mins // =================================================================================== depending on the device type you selected at this step, the part you need to modify at the next step will vary the level of modification complexity is assigned per each device get cluster value clusters are the functional building block elements of the data model a cluster can be an interface, a service, or an object class, and it is the lowest independent functional element in the data model a matter device supports a set of appropriate clusters, which can interact with your preferred controller such as smartthings this allows for easy information retrieval, behavior setting, event notifications, and more through the viewmodel, get the value of the cluster used in the device you created noteto learn more about clusters, see matter application cluster specification occupancy sensorlevel 1 file path feature > sensor > java > com matter virtual device app feature sensor file name occupancysensorviewmodel kt // =================================================================================== // codelab level 1 // the current status of the occupancy the boolean value is used by the [occupancyfragment] // to react to update ui // todo 1 uncomment the following code blocks // ----------------------------------------------------------------------------------- //private val _occupancy stateflow<boolean> = getoccupancyflowusecase //val occupancy livedata<boolean> // get = _occupancy aslivedata // =================================================================================== // =================================================================================== // codelab level 1 // the current status of the battery the int value is used by the [occupancyfragment] // to react to update fragment's ui // todo 2 uncomment the following code blocks // ----------------------------------------------------------------------------------- //private val _batterystatus mutablestateflow<int> = // getbatpercentremainingusecase as mutablestateflow<int> //val batterystatus livedata<int> // get = _batterystatus aslivedata // =================================================================================== // =================================================================================== // codelab level 1 // triggered by the "occupancy" button in the [occupancyfragment] // [setoccupancyusecase] will update the boolean value of the new occupancy status // todo 3 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodelscope launch { // timber d "current value = ${_occupancy value}" // if _occupancy value { // timber d "set value = false" // setoccupancyusecase false // } else { // timber d "set value = true" // setoccupancyusecase true // } //} // =================================================================================== // =================================================================================== // codelab level 1 // triggered by the "battery" seekbar in the [occupancyfragment] // [batterystatus] store the current status of the battery to indicate the progress // todo 4 uncomment the following code blocks // ----------------------------------------------------------------------------------- //_batterystatus value = progress // =================================================================================== // =================================================================================== // codelab level 1 // triggered by the "battery" seekbar in the [occupancyfragment] // [updatebatteryseekbarprogress] update the current status of the battery to indicate the // progress // [setbatpercentremainingusecase] will update the int value of the new battery status // todo 5 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodelscope launch { // updatebatteryseekbarprogress progress // setbatpercentremainingusecase progress //} // =================================================================================== contact sensorlevel 2 file path feature > sensor > java > com matter virtual device app feature sensor file name contactsensorviewmodel kt // =================================================================================== // codelab level 2 // the current status of the contact the boolean value is used by the [contactsensorfragment] // to react to update ui // todo 1 uncomment the following code blocks // ----------------------------------------------------------------------------------- //private val _statevalue stateflow<boolean> = getstatevalueflowusecase //val statevalue livedata<boolean> // get = _statevalue aslivedata // =================================================================================== // =================================================================================== // codelab level 2 // the current status of the battery the int value is used by the [contactsensorfragment] // to react to update fragment's ui // todo 2 uncomment the following code blocks // ----------------------------------------------------------------------------------- //private val _batterystatus mutablestateflow<int> = // getbatpercentremainingusecase as mutablestateflow<int> //val batterystatus livedata<int> // get = _batterystatus aslivedata // =================================================================================== // =================================================================================== // codelab level 2 // triggered by the "contact" button in the [contactsensorfragment] // [setstatevalueusecase] will update the boolean value of the new contact status // todo 3 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodelscope launch { // timber d "current value = ${_statevalue value}" // if _statevalue value { // timber d "set value = false" // setstatevalueusecase false // } else { // timber d "set value = true" // setstatevalueusecase true // } //} // =================================================================================== // =================================================================================== // codelab level 2 // triggered by the "battery" seekbar in the [contactsensorfragment] // [batterystatus] store the current status of the battery to indicate the progress // todo 4 uncomment the following code blocks // ----------------------------------------------------------------------------------- //_batterystatus value = progress // =================================================================================== // =================================================================================== // codelab level 2 // triggered by the "battery" seekbar in the [contactsensorfragment] // [updatebatteryseekbarprogress] update the current status of the battery to indicate the // progress // [setbatpercentremainingusecase] will update the int value of the new battery status // todo 5 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodelscope launch { // updatebatteryseekbarprogress progress // setbatpercentremainingusecase progress //} // =================================================================================== video playerlevel 2 file path feature > media > java > com matter virtual device app feature media file name videoplayerviewmodel kt // =================================================================================== // codelab level 2 // the current status of the on/off the boolean value is used by the [videoplayerfragment] // to react to update fragment's ui // todo 1 uncomment the following code blocks // ----------------------------------------------------------------------------------- //private val _onoff stateflow<boolean> = getonoffflowusecase //val onoff livedata<boolean> // get = _onoff aslivedata // =================================================================================== // =================================================================================== // codelab level 2 // the current status of the playback state the int value is used by the [videoplayerfragment] // to react to update fragment's ui // todo 2 uncomment the following code blocks // ----------------------------------------------------------------------------------- //private val _playbackstate stateflow<int> = getplaybackstateflowusecase //val playbackstate livedata<int> // get = _playbackstate aslivedata // =================================================================================== // =================================================================================== // codelab level 2 // the current status of the playback speed the int value is used by the [videoplayerfragment] // to react to update fragment's ui // todo 3 uncomment the following code blocks // ----------------------------------------------------------------------------------- //private val _playbackspeed stateflow<int> = getplaybackspeedflowusecase //val playbackspeed livedata<int> // get = _playbackspeed aslivedata // =================================================================================== // =================================================================================== // codelab level 2 // the current status of the key code the enum value is used by the [videoplayerfragment] // to react to update fragment's ui // todo 4 uncomment the following code blocks // ----------------------------------------------------------------------------------- //private val _keycode stateflow<keycode> = getkeycodestateflowusecase //val keycode livedata<keycode> // get = _keycode aslivedata // =================================================================================== // =================================================================================== // codelab level 2 // triggered by the "on/off" button in the [videoplayerfragment] // [setonoffusecase] will update the boolean value of the new on/off status // todo 5 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodelscope launch { // timber d "current value = ${_onoff value}" // if _onoff value { // timber d "set value = false" // setonoffusecase false // } else { // timber d "set value = true" // setonoffusecase true // } //} // =================================================================================== door locklevel 3 file path feature > closure > java > com matter virtual device app feature closure file name doorlockviewmodel kt // =================================================================================== // codelab level 3 // the current status of the lock the boolean value is used by the [doorlockfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 1 copy code below private val _lockstate stateflow<boolean> = getlockstateflowusecase val lockstate livedata<boolean> get = _lockstate aslivedata // ============================================================================== // =================================================================================== // codelab level 3 // the current status of the battery the int value is used by the [doorlockfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 2 copy code below private val _batterystatus mutablestateflow<int> = getbatpercentremainingusecase as mutablestateflow<int> val batterystatus livedata<int> get = _batterystatus aslivedata // ============================================================================== // =================================================================================== // codelab level 3 // triggered by the "lock" button in the [doorlockfragment] // [setlockstateusecase] will update the boolean value of the new lock status // ----------------------------------------------------------------------------------- // todo 3 copy code below viewmodelscope launch { timber d "current lockstate value = ${_lockstate value}" if _lockstate value == lock_state_locked { timber d "set value = unlocked" setlockstateusecase lock_state_unlocked } else { timber d "set value = locked" setlockstateusecase lock_state_locked } } // ============================================================================== // =================================================================================== // codelab level 3 // triggered by the "send alarm" button in the [doorlockfragment] // [sendlockalarmeventusecase] will send alarm event // [setlockstateusecase] will update the boolean value of the unlock status // ----------------------------------------------------------------------------------- // todo 4 copy code below viewmodelscope launch { if !_lockstate value { // if lockstate == locked, send alarm event and change the lockstate to unlocked sendlockalarmeventusecase setlockstateusecase lock_state_unlocked } } // ============================================================================== // =================================================================================== // codelab level 3 // triggered by the "battery" seekbar in the [doorlockfragment] // [batterystatus] store the current status of the battery to indicate the progress // ----------------------------------------------------------------------------------- // todo 5 copy code below _batterystatus value = progress // ============================================================================== // =================================================================================== // codelab level 3 // triggered by the "battery" seekbar in the [doorlockfragment] // [updatebatteryseekbarprogress] update the current status of the battery to indicate the // progress // [setbatpercentremainingusecase] will update the int value of the new battery status // ----------------------------------------------------------------------------------- // todo 6 copy code below viewmodelscope launch { updatebatteryseekbarprogress progress setbatpercentremainingusecase progress } // ============================================================================== extended color lightlevel 3 file path feature > lighting > java > com matter virtual device app feature lighting file name extendedcolorlightviewmodel kt // =================================================================================== // codelab level 3 // the current status of the on/off the boolean value is used by the [extendedcolorlightfragment] // to react to update ui // ----------------------------------------------------------------------------------- // todo 1 copy code below private val _onoff stateflow<boolean> = getonoffflowusecase val onoff livedata<boolean> get = _onoff aslivedata // =================================================================================== // =================================================================================== // codelab level 3 // the current status of the color level the int value is used by the // [extendedcolorlightfragment] // to react to update ui // ----------------------------------------------------------------------------------- // todo 2 copy code below private val _level stateflow<int> = getlevelflowusecase val level livedata<int> get = _level aslivedata // =================================================================================== // =================================================================================== // codelab level 3 // the current status of the color the enum value is used by the [extendedcolorlightfragment] // to react to update ui // ----------------------------------------------------------------------------------- // todo 3 copy code below private val _currenthue stateflow<int> = getcurrenthueflowusecase private val _currentsaturation stateflow<int> = getcurrentsaturationflowusecase val currentcolor livedata<hsvcolor> = combine _currenthue, _currentsaturation { currenthue, currentsaturation -> hsvcolor currenthue, currentsaturation } aslivedata // =================================================================================== // =================================================================================== // codelab level 3 // the current status of the color temperature the int value is used by the // [extendedcolorlightfragment] // to react to update ui // ----------------------------------------------------------------------------------- // todo 4 copy code below private val _colortemperature stateflow<int> = getcolortemperatureflowusecase val colortemperature livedata<int> get = _colortemperature aslivedata // =================================================================================== // =================================================================================== // codelab level 3 // triggered by the "on/off" button in the [extendedcolorlightfragment] // [setonoffusecase] will update the boolean value of the new on/off status // ----------------------------------------------------------------------------------- // todo 5 copy code below viewmodelscope launch { timber d "current value = ${_onoff value}" if _onoff value { timber d "set value = false" setonoffusecase false } else { timber d "set value = true" setonoffusecase true } } // =================================================================================== window coveringlevel 4 file path feature > closure > java > com matter virtual device app feature closure file name windowcoveringviewmodel kt // =================================================================================== // codelab level 4 // the current status of the position/operation the enum value is used by the // [windowcoveringfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 1 copy code below val windowcoveringstatus livedata<windowcoveringstatus> = combine _currentposition, _operationalstatus { currentposition, operationalstatus -> windowcoveringstatus currentposition, operationalstatus } aslivedata // =================================================================================== // =================================================================================== // codelab level 4 // the current status of the battery the int value is used by the [windowcoveringfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 2 copy code below private val _batterystatus mutablestateflow<int> = getbatpercentremainingusecase as mutablestateflow<int> val batterystatus livedata<int> get = _batterystatus aslivedata // =================================================================================== // =================================================================================== // codelab level 4 // triggered by the "windowshade" seekbar in the [windowcoveringfragment] // [settargetpositionusecase] will update the int value of the new target position status // ----------------------------------------------------------------------------------- // todo 3 copy code below viewmodelscope launch { timber d "target position = $percentage" settargetpositionusecase percentage } // =================================================================================== // =================================================================================== // codelab level 4 // triggered by the "open" button in the [fragment_window_covering xml] // [settargetpositionusecase] will update the int value of the open position 100 status // ----------------------------------------------------------------------------------- // todo 4 copy code below viewmodelscope launch { timber d "target position = 100" settargetpositionusecase 100 } // =================================================================================== // =================================================================================== // codelab level 4 // triggered by the "close" button in the [fragment_window_covering xml] // [settargetpositionusecase] will update the int value of the close position 0 status // ----------------------------------------------------------------------------------- // todo 5 copy code below viewmodelscope launch { settargetpositionusecase 0 } // =================================================================================== // =================================================================================== // codelab level 4 // triggered by the "pause" button in the [fragment_window_covering xml] // [settargetpositionusecase] will update the int value of the pause position status // ----------------------------------------------------------------------------------- // todo 6 copy code below viewmodelscope launch { timber d "current position = ${_currentposition value}, target position ${_targetposition value}" if _currentposition value != _targetposition value { settargetpositionusecase _currentposition value } } // =================================================================================== // =================================================================================== // codelab level 4 // triggered by the "battery" seekbar in the [windowcoveringfragment] // [batterystatus] store the current status of the battery to indicate the progress // ----------------------------------------------------------------------------------- // todo 7 copy code below _batterystatus value = progress // =================================================================================== // =================================================================================== // codelab level 4 // triggered by the "battery" seekbar in the [windowcoveringfragment] // [updatebatteryseekbarprogress] update the current status of the battery to indicate the // progress // [setbatpercentremainingusecase] will update the int value of the new battery status // ----------------------------------------------------------------------------------- // todo 8 copy code below viewmodelscope launch { updatebatteryseekbarprogress progress setbatpercentremainingusecase progress } // =================================================================================== thermostatlevel 5 file path feature > hvac > java > com matter virtual device app feature hvac file name thermostatviewmodel kt // =================================================================================== // codelab level 5 // the current status of the temperature the int value is used by the [thermostatfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 1 copy code below private val _temperature mutablestateflow<int> = getlocaltemperatureusecase as mutablestateflow<int> val temperature livedata<int> get = _temperature aslivedata // =================================================================================== // =================================================================================== // codelab level 5 // the current status of the humidity the int value is used by the [thermostatfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 2 copy code below private val _humidity mutablestateflow<int> = getrelativehumidityusecase as mutablestateflow<int> val humidity livedata<int> get = _humidity aslivedata // =================================================================================== // =================================================================================== // codelab level 5 // the current status of the system mode the enum value is used by the [thermostatfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 3 copy code below private val _systemmode stateflow<thermostatsystemmode> = getsystemmodeflowusecase val systemmode livedata<thermostatsystemmode> get = _systemmode aslivedata // =================================================================================== // =================================================================================== // codelab level 5 // the current status of the fan mode the enum value is used by the [thermostatfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 4 copy code below private val _fanmode stateflow<fancontrolfanmode> = getfanmodeflowusecase val fanmode livedata<fancontrolfanmode> get = _fanmode aslivedata // =================================================================================== // =================================================================================== // codelab level 5 // the current status of the cooling setpoint the int value is used by the [thermostatfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 5 copy code below private val _occupiedcoolingsetpoint stateflow<int> = getoccupiedcoolingsetpointflowusecase val occupiedcoolingsetpoint livedata<int> get = _occupiedcoolingsetpoint aslivedata // =================================================================================== // =================================================================================== // codelab level 5 // the current status of the heating setpoint the int value is used by the [thermostatfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 6 copy code below private val _occupiedheatingsetpoint stateflow<int> = getoccupiedheatingsetpointflowusecase val occupiedheatingsetpoint livedata<int> get = _occupiedheatingsetpoint aslivedata // =================================================================================== // =================================================================================== // codelab level 5 // the current status of the battery the int value is used by the [thermostatfragment] // to react to update fragment's ui // ----------------------------------------------------------------------------------- // todo 7 copy code below private val _batterystatus mutablestateflow<int> = getbatpercentremainingusecase as mutablestateflow<int> val batterystatus livedata<int> get = _batterystatus aslivedata // =================================================================================== // =================================================================================== // codelab level 5 // triggered by the "humidity" seekbar in the [thermostatfragment] // [humidity] store the current status of the humidity to indicate the progress // ----------------------------------------------------------------------------------- // todo 8 copy code below _humidity value = progress * 100 // =================================================================================== // =================================================================================== // codelab level 5 // triggered by the "humidity" seekbar in the [thermostatfragment] // [updatehumidityseekbarprogress] update the current status of the humidity to indicate the // progress // [setrelativehumidityusecase] will update the int value of the new humidity status [0 100] // * 100 // ----------------------------------------------------------------------------------- // todo 9 copy code below viewmodelscope launch { updatehumidityseekbarprogress progress setrelativehumidityusecase progress * 100 } // =================================================================================== // =================================================================================== // codelab level 5 // triggered by the "temperature" seekbar in the [thermostatfragment] // [temperature] store the current status of the temperature to indicate the progress // ----------------------------------------------------------------------------------- // todo 10 copy code below _temperature value = progress * 100 // =================================================================================== // =================================================================================== // codelab level 5 // triggered by the "temperature" seekbar in the [thermostatfragment] // [updatetemperatureseekbarprogress] update the current status of the temperature to indicate // the progress // [setlocaltemperatureusecase] will update the int value of the new temperature status // [value] * 100 // ----------------------------------------------------------------------------------- // todo 11 copy code below viewmodelscope launch { updatetemperatureseekbarprogress progress setlocaltemperatureusecase progress * 100 } // ==================================================================================== // =================================================================================== // codelab level 5 // triggered by the "battery" seekbar in the [thermostatfragment] // [batterystatus] store the current status of the battery to indicate the progress // ----------------------------------------------------------------------------------- // todo 12 copy code below _batterystatus value = progress // ==================================================================================== // =================================================================================== // codelab level 5 // triggered by the "battery" seekbar in the [thermostatfragment] // [updatebatteryseekbarprogress] update the current status of the battery to indicate the // progress // [setbatpercentremainingusecase] will update the int value of the new battery status // ----------------------------------------------------------------------------------- // todo 13 copy code below viewmodelscope launch { updatebatteryseekbarprogress progress setbatpercentremainingusecase progress } // ==================================================================================== // =================================================================================== // codelab level 5 // triggered by the "systemmode" popup in the [thermostatfragment] // [setsystemmodeusecase] will update the enum value of the new system mode status // ----------------------------------------------------------------------------------- // todo 14 copy code below viewmodelscope launch { setsystemmodeusecase systemmode } // ==================================================================================== // =================================================================================== // codelab level 5 // triggered by the "fanmode" popup in the [thermostatfragment] // [setfanmodeusecase] will update the enum value of the new fan mode status // ----------------------------------------------------------------------------------- // todo 15 copy code below viewmodelscope launch { setfanmodeusecase fanmode } // ==================================================================================== // =================================================================================== // codelab level 5 // triggered by the "heating plus" button in the [fragment_thermostat xml] // [setoccupiedheatingsetpointusecase] will update the int value of the +1 degree [degree] * // 100 // ----------------------------------------------------------------------------------- // todo 16 copy code below viewmodelscope launch { val nextvalue = _occupiedheatingsetpoint value + 100 timber d "current value = ${_occupiedheatingsetpoint value} set value = $nextvalue" setoccupiedheatingsetpointusecase nextvalue } // ==================================================================================== // =================================================================================== // codelab level 5 // triggered by the "heating minus" button in the [fragment_thermostat xml] // [setoccupiedheatingsetpointusecase] will update the int value of the -1 degree [degree] * // 100 // ----------------------------------------------------------------------------------- // todo 17 copy code below viewmodelscope launch { val nextvalue = _occupiedheatingsetpoint value - 100 timber d "current value = ${_occupiedheatingsetpoint value} set value = $nextvalue" setoccupiedheatingsetpointusecase nextvalue } // ==================================================================================== // =================================================================================== // codelab level 5 // triggered by the "cooling plus" button in the [fragment_thermostat xml] // [setoccupiedcoolingsetpointusecase] will update the int value of the +1 degree [degree] * // 100 // ----------------------------------------------------------------------------------- // todo 18 copy code below viewmodelscope launch { val nextvalue = _occupiedcoolingsetpoint value + 100 timber d "current value = ${_occupiedcoolingsetpoint value} set value = $nextvalue" setoccupiedcoolingsetpointusecase nextvalue } // ==================================================================================== // =================================================================================== // codelab level 5 // triggered by the "cooling minus" button in the [fragment_thermostat xml] // [setoccupiedcoolingsetpointusecase] will update the int value of the -1 degree [degree] * // 100 // ----------------------------------------------------------------------------------- // todo 19 copy code below viewmodelscope launch { val nextvalue = _occupiedcoolingsetpoint value - 100 timber d "current value = ${_occupiedcoolingsetpoint value} set value = $nextvalue" setoccupiedcoolingsetpointusecase nextvalue } // ==================================================================================== noteyou can find related files in android studio by going to edit menu> find > find in files and entering the keyword "codelab" observe cluster value next, use the observe function to keep track whenever there is a change in the cluster value occupancy sensorlevel 1 file path feature > sensor > java > com matter virtual device app feature sensor file name occupancysensorfragment kt // =================================================================================== // codelab level 1 // trigger the processing for updating new occupancy state of the virtual device // todo 1 uncomment the following code blocks // ----------------------------------------------------------------------------------- //binding occupancybutton setonclicklistener { viewmodel onclickbutton } // =================================================================================== // =================================================================================== // codelab level 1 // [onprogresschanged] will update the fragment's ui via viewmodel livedata // [onstoptrackingtouch] will trigger the processing for updating new battery state of the // virtual device // todo 2 uncomment the following code blocks // ----------------------------------------------------------------------------------- //binding occupancysensorbatterylayout titletext text = getstring r string battery //binding occupancysensorbatterylayout seekbardata = // seekbardata progress = viewmodel batterystatus //binding occupancysensorbatterylayout seekbar setonseekbarchangelistener // object seekbar onseekbarchangelistener { // override fun onprogresschanged seekbar seekbar, progress int, fromuser boolean { // viewmodel updatebatteryseekbarprogress progress // } // // override fun onstarttrackingtouch seekbar seekbar {} // // override fun onstoptrackingtouch seekbar seekbar { // viewmodel updatebatterystatustocluster seekbar progress // } // } // // =================================================================================== // =================================================================================== // codelab level 1 // observer on the current occupancy status and react on the fragment's ui // todo 3 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodel occupancy observe viewlifecycleowner { // if it { // binding occupancyvaluetext text = getstring r string occupancy_state_occupied // binding occupancybutton setimageresource r drawable ic_occupied // } else { // binding occupancyvaluetext text = getstring r string occupancy_state_unoccupied // binding occupancybutton setimageresource r drawable ic_unoccupied // } //} // =================================================================================== // =================================================================================== // codelab level 1 // observer on the current battery status and react on the fragment's ui // todo 4 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodel batterystatus observe viewlifecycleowner { // val text string = getstring r string battery_format, it // binding occupancysensorbatterylayout valuetext text = // html fromhtml text, html from_html_mode_legacy //} // =================================================================================== contact sensorlevel 2 file path feature > sensor > java > com matter virtual device app feature sensor file name contactsensorfragment kt // =================================================================================== // codelab level 2 // trigger the processing for updating new contact state of the virtual device // todo 1 uncomment the following code blocks // ----------------------------------------------------------------------------------- //binding contactbutton setonclicklistener { viewmodel onclickbutton } // =================================================================================== /** battery layout */ // =================================================================================== // codelab level 2 // [onprogresschanged] will update the fragment's ui via viewmodel livedata // [onstoptrackingtouch] will trigger the processing for updating new battery state of the // virtual device // todo 2 uncomment the following code blocks // ----------------------------------------------------------------------------------- //binding contactsensorbatterylayout titletext text = getstring r string battery //binding contactsensorbatterylayout seekbardata = seekbardata progress = viewmodel batterystatus //binding contactsensorbatterylayout seekbar setonseekbarchangelistener // object seekbar onseekbarchangelistener { // override fun onprogresschanged seekbar seekbar, progress int, fromuser boolean { // viewmodel updatebatteryseekbarprogress progress // } // // override fun onstarttrackingtouch seekbar seekbar {} // // override fun onstoptrackingtouch seekbar seekbar { // viewmodel updatebatterystatustocluster seekbar progress // } // } // // =================================================================================== // =================================================================================== // codelab level 2 // observer on the current contact status and react on the fragment's ui // todo 3 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodel statevalue observe viewlifecycleowner { // if it { // binding contactvaluetext text = getstring r string contact_state_close // binding contactbutton setimageresource r drawable ic_unoccupied // } else { // binding contactvaluetext text = getstring r string contact_state_open // binding contactbutton setimageresource r drawable ic_occupied // } //} // =================================================================================== // =================================================================================== // codelab level 2 // observer on the current battery status and react on the fragment's ui // todo 4 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodel batterystatus observe viewlifecycleowner { // val text string = getstring r string battery_format, it // binding contactsensorbatterylayout valuetext text = // html fromhtml text, html from_html_mode_legacy } // =================================================================================== video playerlevel 2 file path feature > media > java > com matter virtual device app feature media file name videoplayerfragment kt // =================================================================================== // codelab level 2 // [buttondata] observer on the current on/off status and react on the fragment's ui // [onclicklistener] trigger the processing for updating new on/off state of the virtual device // todo 1 uncomment the following code blocks // ----------------------------------------------------------------------------------- //binding videoplayeronofflayout buttondata = // buttondata // onoff = viewmodel onoff, // ontext = r string on_off_switch_power_on, // offtext = r string on_off_switch_power_off // //binding videoplayeronofflayout button setonclicklistener { viewmodel onclickbutton } // =================================================================================== // =================================================================================== // codelab level 2 // observer on the current playback status and react on the fragment's ui // todo 2 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodel playbackstate observe viewlifecycleowner { state -> // val statetext = convertplaybackstatetostring state // timber d "playbackstate $state $statetext " // binding videoplayerstatelayout valuetext text = statetext //} // =================================================================================== // =================================================================================== // codelab level 2 // observer on the current playback speed and react on the fragment's ui // todo 3 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodel playbackspeed observe viewlifecycleowner { speed -> // binding videoplayerspeedlayout valuetext text = speed tostring //} // =================================================================================== // =================================================================================== // codelab level 2 // observer on the current key code and react on the fragment's ui // todo 4 uncomment the following code blocks // ----------------------------------------------------------------------------------- //viewmodel keycode observe viewlifecycleowner { keycode -> // binding videoplayerkeypadlayout valuetext text = keycode value //} // =================================================================================== door locklevel 3 file path feature > closure > java > com matter virtual device app feature closure file name doorlockfragment kt // =================================================================================== // codelab level 3 // [buttondata] observer on the current lock status and react on the fragment's ui // [onclicklistener] trigger the processing for updating new lock state of the virtual device // ----------------------------------------------------------------------------------- // todo 1 copy code below binding doorlockonofflayout buttondata = buttondata onoff = viewmodel lockstate, ontext = r string door_lock_unlocked, offtext = r string door_lock_locked binding doorlockonofflayout button setonclicklistener { viewmodel onclickbutton } // =================================================================================== // =================================================================================== // codelab level 3 // trigger the processing for sending alarm event // ----------------------------------------------------------------------------------- // todo 2 copy code below binding doorlocksendalarmlayout button setonclicklistener { viewmodel onclicksendlockalarmeventbutton } // =================================================================================== // =================================================================================== // codelab level 3 // [onprogresschanged] will update the fragment's ui via viewmodel livedata // [onstoptrackingtouch] will trigger the processing for updating new battery state of the // virtual device // ----------------------------------------------------------------------------------- // todo 3 copy code below binding doorlockbatterylayout titletext text = getstring r string battery binding doorlockbatterylayout seekbardata = seekbardata progress = viewmodel batterystatus binding doorlockbatterylayout seekbar setonseekbarchangelistener object seekbar onseekbarchangelistener { override fun onprogresschanged seekbar seekbar, progress int, fromuser boolean { viewmodel updatebatteryseekbarprogress progress } override fun onstarttrackingtouch seekbar seekbar {} override fun onstoptrackingtouch seekbar seekbar { viewmodel updatebatterystatustocluster seekbar progress } } // =================================================================================== // =================================================================================== // codelab level 3 // observer on the current battery status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 4 copy code below viewmodel batterystatus observe viewlifecycleowner { val text string = getstring r string battery_format, it binding doorlockbatterylayout valuetext text = html fromhtml text, html from_html_mode_legacy } // =================================================================================== extended color lightlevel 3 file path feature > lighting > java > com matter virtual device app feature lighting file name extendedcolorlightfragment kt // =================================================================================== // codelab level 3 // [buttondata] observer on the current on/off status and react on the fragment's ui // [onclicklistener] trigger the processing for updating new on/off state of the virtual device // ----------------------------------------------------------------------------------- // todo 1 copy code below binding extendedcolorlightonofflayout buttondata = buttondata onoff = viewmodel onoff, ontext = r string on_off_switch_power_on, offtext = r string on_off_switch_power_off binding extendedcolorlightonofflayout button setonclicklistener { viewmodel onclickbutton } // =================================================================================== // =================================================================================== // codelab level 3 // observer on the current color level status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 2 copy code below viewmodel level observe viewlifecycleowner { // min 2 1% , max 255 100% val level int = it tofloat / 100 * 255 toint timber d "level $it" // if level value is 0, user can't distinguish the color // so, set it to half value + half of max binding extendedcolorlightcolorlayout colorboard drawable? alpha = level / 2 + 127 } // =================================================================================== // =================================================================================== // codelab level 3 // observer on the current color status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 3 copy code below viewmodel currentcolor observe viewlifecycleowner { hsvcolor -> val rgbcolor int = colorcontrolutil hue2rgb hsvcolor currenthue tofloat , hsvcolor currentsaturation tofloat timber d "currenthue ${hsvcolor currenthue},currentsaturation ${hsvcolor currentsaturation}" timber d "color #${integer tohexstring rgbcolor }" var level int? = binding extendedcolorlightcolorlayout colorboard drawable? alpha if level == null level = 255 timber d "level $level" binding extendedcolorlightcolorlayout colorboard setimagedrawable bitmapdrawable resources, colorcontrolutil colorboard rgbcolor } // =================================================================================== // =================================================================================== // codelab level 3 // observer on the current color temperature status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 4 copy code below viewmodel colortemperature observe viewlifecycleowner { // min 2580k 2577k , max 7050k 7042k val colortemperature int = 1000000 / it val rgbcolor int = colorcontrolutil kelvin2rgb colortemperature timber d "color temperature $colortemperature $it" timber d "color #${integer tohexstring rgbcolor }" binding extendedcolorlightcolorlayout colorboard setimagedrawable bitmapdrawable resources, colorcontrolutil colorboard rgbcolor } // =================================================================================== window coveringlevel 4 file path feature > closure > java > com matter virtual device app feature closure file name windowcoveringfragment kt // =================================================================================== // codelab level 4 // [onprogresschanged] will update the fragment's ui via viewmodel livedata // [onstoptrackingtouch] will trigger the processing for updating new windowshade state of the // virtual device // ----------------------------------------------------------------------------------- // todo 1 copy code below binding windowcoveringwindowshadeseekbar setonseekbarchangelistener object seekbar onseekbarchangelistener { override fun onprogresschanged seekbar seekbar, progress int, fromuser boolean { val targetpercentage = seekbar progress val text string = getstring r string window_covering_window_shade_format, targetpercentage val percentagetextview = binding windowcoveringwindowshadevaluetext percentagetextview text = html fromhtml text, html from_html_mode_legacy } override fun onstarttrackingtouch seekbar seekbar {} override fun onstoptrackingtouch seekbar seekbar { viewmodel stopmotion seekbar progress } } // ======================================================================================================= // =================================================================================== // codelab level 4 // [onprogresschanged] will update the fragment's ui via viewmodel livedata // [onstoptrackingtouch] will trigger the processing for updating new battery state of the // virtual device // ----------------------------------------------------------------------------------- // todo 2 copy code below binding windowcoveringbatterylayout titletext text = getstring r string battery binding windowcoveringbatterylayout seekbardata = seekbardata progress = viewmodel batterystatus binding windowcoveringbatterylayout seekbar setonseekbarchangelistener object seekbar onseekbarchangelistener { override fun onprogresschanged seekbar seekbar, progress int, fromuser boolean { viewmodel updatebatteryseekbarprogress progress } override fun onstarttrackingtouch seekbar seekbar {} override fun onstoptrackingtouch seekbar seekbar { viewmodel updatebatterystatustocluster seekbar progress } } // ======================================================================================================= // =================================================================================== // codelab level 4 // observer on the current position/operation status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 3 copy code below viewmodel windowcoveringstatus observe viewlifecycleowner { status -> timber d "currentposition ${status currentposition},operationalstatus ${status operationalstatus}" binding windowcoveringwindowshadeseekbar progress = status currentposition val text string = getstring r string window_covering_window_shade_format, status currentposition binding windowcoveringwindowshadevaluetext text = html fromhtml text, html from_html_mode_legacy when status operationalstatus { 0 -> { when status currentposition { 0 -> { binding windowcoveringoperationalstatustext settext r string window_covering_closed } 100 -> { binding windowcoveringoperationalstatustext settext r string window_covering_open } else -> { binding windowcoveringoperationalstatustext settext r string window_covering_partially_open } } } 1 -> { binding windowcoveringoperationalstatustext settext r string window_covering_opening } 2 -> { binding windowcoveringoperationalstatustext settext r string window_covering_closing } else -> {} } } // ======================================================================================================= // =================================================================================== // codelab level 4 // observer on the current battery status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 4 copy code below viewmodel batterystatus observe viewlifecycleowner { val text string = getstring r string battery_format, it binding windowcoveringbatterylayout valuetext text = html fromhtml text, html from_html_mode_legacy } // ======================================================================================================= thermostatlevel 5 file path feature > hvac > java > com matter virtual device app feature hvac file name themostatfragment kt // =================================================================================== // codelab level 5 // [onprogresschanged] will update the fragment's ui via viewmodel livedata // [onstoptrackingtouch] will trigger the processing for updating new temperature state of the // virtual device // ----------------------------------------------------------------------------------- // todo 1 copy code below binding thermostattemperatureseekbar setonseekbarchangelistener object seekbar onseekbarchangelistener { override fun onprogresschanged seekbar seekbar, progress int, fromuser boolean { viewmodel updatetemperatureseekbarprogress progress } override fun onstarttrackingtouch seekbar seekbar {} override fun onstoptrackingtouch seekbar seekbar { viewmodel updatetemperaturetocluster seekbar progress } } // =================================================================================== // =================================================================================== // codelab level 5 // [onprogresschanged] will update the fragment's ui via viewmodel livedata // [onstoptrackingtouch] will trigger the processing for updating new humidity state of the // virtual device // ----------------------------------------------------------------------------------- // todo 2 copy code below binding humiditysensorhumidityseekbar setonseekbarchangelistener object seekbar onseekbarchangelistener { override fun onprogresschanged seekbar seekbar, progress int, fromuser boolean { viewmodel updatehumidityseekbarprogress progress } override fun onstarttrackingtouch seekbar seekbar {} override fun onstoptrackingtouch seekbar seekbar { viewmodel updatehumiditytocluster seekbar progress } } // =================================================================================== // =================================================================================== // codelab level 5 // [onprogresschanged] will update the fragment's ui via viewmodel livedata // [onstoptrackingtouch] will trigger the processing for updating new battery state of the // virtual device // ----------------------------------------------------------------------------------- // todo 3 copy code below binding thermostatbatterylayout titletext text = getstring r string battery binding thermostatbatterylayout seekbardata = seekbardata progress = viewmodel batterystatus binding thermostatbatterylayout seekbar setonseekbarchangelistener object seekbar onseekbarchangelistener { override fun onprogresschanged seekbar seekbar, progress int, fromuser boolean { viewmodel updatebatteryseekbarprogress progress } override fun onstarttrackingtouch seekbar seekbar {} override fun onstoptrackingtouch seekbar seekbar { viewmodel updatebatterystatustocluster seekbar progress } } // =================================================================================== // =================================================================================== // codelab level 5 // observer on the current temperature status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 4 copy code below viewmodel temperature observe viewlifecycleowner { val celsiustemp float = it tofloat / 100 val celsiustext string = getstring r string temperature_celsius_format, celsiustemp binding thermostattemperaturecelsiusvaluetext text = html fromhtml celsiustext, html from_html_mode_legacy val fahrenheittemp float = it tofloat / 100 * 9 / 5 + 32 val fahrenheittext string = getstring r string temperature_fahrenheit_format, fahrenheittemp binding thermostattemperaturefahrenheitvaluetext text = html fromhtml fahrenheittext, html from_html_mode_legacy binding thermostattemperatureseekbar progress = celsiustemp toint } // ========================================================================================== // =================================================================================== // codelab level 5 // observer on the current fan mode status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 5 copy code below viewmodel fanmode observe viewlifecycleowner { timber d "fanmode $it" this fanmode = it binding fancontrolfanmodelayout valuetext text = convertfanmodetostring it } // ========================================================================================== // =================================================================================== // codelab level 5 // observer on the current heating setpoint and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 6 copy code below viewmodel occupiedheatingsetpoint observe viewlifecycleowner { val celsiustemp float = it tofloat / 100 val celsiustext string = getstring r string temperature_celsius_format, celsiustemp binding thermostatsettemperatureheatingcelsiusvaluetext text = html fromhtml celsiustext, html from_html_mode_legacy val fahrenheittemp float = it tofloat / 100 * 9 / 5 + 32 val fahrenheittext string = getstring r string temperature_fahrenheit_format, fahrenheittemp binding thermostatsettemperatureheatingfahrenheitvaluetext text = html fromhtml fahrenheittext, html from_html_mode_legacy } // =================================================================================== // =================================================================================== // codelab level 5 // observer on the current cooling setpoint and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 7 copy code below viewmodel occupiedcoolingsetpoint observe viewlifecycleowner { val celsiustemp float = it tofloat / 100 val celsiustext string = getstring r string temperature_celsius_format, celsiustemp binding thermostatsettemperaturecoolingcelsiusvaluetext text = html fromhtml celsiustext, html from_html_mode_legacy val fahrenheittemp float = it tofloat / 100 * 9 / 5 + 32 val fahrenheittext string = getstring r string temperature_fahrenheit_format, fahrenheittemp binding thermostatsettemperaturecoolingfahrenheitvaluetext text = html fromhtml fahrenheittext, html from_html_mode_legacy } // =================================================================================== // =================================================================================== // codelab level 5 // observer on the current system mode status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 8 copy code below viewmodel systemmode observe viewlifecycleowner { timber d "systemmode $it" this systemmode = it binding thermostatsystemmodelayout valuetext text = convertsystemmodetostring it } // =================================================================================== // =================================================================================== // codelab level 5 // observer on the current humidity status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 9 copy code below viewmodel humidity observe viewlifecycleowner { val humidity int = it / 100 val humiditytext string = getstring r string humidity_format, humidity binding humiditysensorhumiditypercentagevaluetext text = html fromhtml humiditytext, html from_html_mode_legacy binding humiditysensorhumidityseekbar progress = humidity } // =================================================================================== // =================================================================================== // codelab level 5 // observer on the current battery status and react on the fragment's ui // ----------------------------------------------------------------------------------- // todo 10 copy code below viewmodel batterystatus observe viewlifecycleowner { val text string = getstring r string battery_format, it binding thermostatbatterylayout valuetext text = html fromhtml text, html from_html_mode_legacy } // =================================================================================== // =================================================================================== // codelab level 5 // trigger the processing for setting system mode // ----------------------------------------------------------------------------------- // todo 11 copy code below alertdialog builder requirecontext settitle r string thermostat_mode setsinglechoiceitems modelist, convertsystemmodetoindex this systemmode { dialog, which -> timber d "thermostat mode set $which ${modelist[which]} " viewmodel setsystemmode convertindextosystemmode which dialog dismiss } setnegativebutton r string cancel, null show // =================================================================================== // =================================================================================== // codelab level 5 // trigger the processing for setting fan mode // ----------------------------------------------------------------------------------- // todo 12 copy code below alertdialog builder requirecontext settitle r string fan_control_fan_mode setsinglechoiceitems modelist, convertfanmodetoindex this fanmode { dialog, which -> timber d "fan mode set $which ${modelist[which]} " viewmodel setfanmode convertindextofanmode which dialog dismiss } setnegativebutton r string cancel, null show // =================================================================================== build and run the virtual device app to build and run your app, follow these steps using a usb cable, connect your mobile device the minimum os requirement is android 8 0 oreo select the sample virtual device app from the run configurations menu in the android studio then, select the connected device in the target device menu click run you can see the device you created in the matter virtual device app onboard and control the virtual device via the smartthings app onboard to onboard the virtual device select and set up the virtual device type you created click save click start to show the qr code for onboarding then, go to the smartthings app and click the + button then, onboard the virtual device by scanning its qr code control by smartthings app in the smartthings app, control the virtual device by using its various functions such as on and off for switch contribute to matter open source optional notethis step is optional, but you can proceed if you want to know how to contribute your code to matter open source to contribute to matter open source, you need to have the latest code therefore, apart from the project files provided by this code lab activity, you should fork and modify the latest code from matter open source project matter follows the "fork-and-pull" model for accepting contributions to do this sign in or sign up to github fork the matter repository by clicking fork on the web ui for each new feature, clone your fork to the local pc and create a working branch $ git clone https //github com/<username>/connectedhomeip git $ git checkout –b <branch-name> before running the build command, source the environment setup script activate sh at the top level this script takes care of downloading gn, ninja, and setting up a python environment with libraries used to build and test $ source scripts/activate sh build the virtual device app using the build_example py $ /scripts/build/build_examples py --target android-arm64-virtual-device-app build add each modified file to include in the commit then, create a commit $ git add <filename1> <filename1> $ git commit –s noteto contribute to the open source, you must check the integrity of the code for this, checking using restyle is recommended push to your github fork $ git push origin <branch-name> then, submit your pull request by clicking contribute > open pull request on the web ui write a description of the problem, change overview, and test then, sign the contributor license agreement cla so a reviewer can automatically be assigned click open pull request tipsee contributing to matter for more information you're done! congratulations! you have successfully achieved the goal of this code lab topic now, you can create a matter-compatible virtual device and contribute your code to matter open source by yourself! if you're having trouble, you may download this file matter virtual device complete code 11 49 mb learn more by going to smartthings matter libraries
events mobile, iot, ai, smarttv
blog5g, 8k, bread-making robots, gaming… #ces2019 had it all. sandwiched between flight delays thanks to “karl the fog,” i made a quick trip to las vegas to spend a few days at the 2019 consumer electronics show. on monday afternoon, samsung hosted a press conference to tout our latest consumer products. if you missed out, you can catch up on everything in the samsung newsroom. i might be adding a samsung space monitor or “the wall” (and a new house big enough to fit it in) to my wish list. we also announced our next galaxy unpacked event which will be livestreamed from san francisco on february 20th. samsung senior vice president, yoon lee, participated in an engaging cnet panel on the next big thing: the future of media (skip ahead to the 12-minute mark). i look forward to one day hearing him play the drums here in the u.s. “live” with the rest of his band who are based in korea. on tuesday afternoon, i attended esports: the new playground for marketers. not only was i inspired by kristen and kristin, two amazing women blazing trails in a male-dominated industry, i was excited to hear about how esports are gaining traction with corporate sponsors. whether it’s ninja and fortnite on the galaxy note9 or the first deal between an esports league and a global sports merchandising company (overwatch league and fanatics), esports are here to stay. it won’t be long until kids are dressing up for halloween -- not as drew brees or dak prescott -- but as their favorite professional gamer. as a side note, i was amused to hear that twitch has a feature that allows others to broadcast over top of existing twitch streamers ala mst3k. also, on tuesday was a great session on the smart venue. the panelists talked about how professional sports venues are becoming more integrated into their communities, offer more than just watching the game or event, and leverage a variety of mobile and iot technologies to do more for fans. from getting concessions delivered directly to your seat to being able to place micro bets as the game progresses, teams are seeing new ways to engage the audience (as well as drive revenue for venue owners). wednesday brought a keynote session on the new mobility revolution. while the secretary of transportation was unable to attend due to the shutdown, the panel did not disappoint. bolstered by the launch of partners for automated vehicle education (pave), the automotive industry is leading the way to educate the public ahead of legislation (as it has done in the past around seat belts and air bags). as car manufacturers add to the load for drivers with the integration of voice assistants and the ability to connect to and control the smart home, it’s becoming more and more important to automate some of the traditional aspects of driving. one of the stats cited during the talk was that more than 40% of drivers have been surprised by something their car did -- and this was not solely drivers of automated driving vehicles. we need to better educate the public on the capabilities of vehicles and their included safety measures. i also had a chance to attend a dinner hosted by hackster, kickstarter, and dragon innovation. i was inspired by the stories from not impossible labs and encourage anyone interested in how technology can benefit humanity to apply for this year’s not impossible awards. i also enjoyed meeting the teams from re3d and mycroft. re3d was a finalist in richard branson’s extreme tech challenge and flew a student from michigan tech out to vegas for the event. spending time at dinner with these innovators inspired me about what future generations are building. earlier in the week, i attended exploring technology and advanced materials innovation in space based on my personal passion around human space travel. i think the biggest takeaway that i can pass on to all of you is that your technology may be used outside of its original intentions. most designers assume that gravity is present; in the future, that may not always be the case. you may have designed a solution assuming an experienced technician would be readily able to service the device, yet most techs do not have their own rockets, so it may be someone in low earth orbit that has to conduct repairs and maintenance themselves. admittedly, it might be tough to predict such a specific use case, but looking ahead (or up) may benefit your product in unexpected ways. finally, while samsung announced a number of its own robots, i was quite intrigued by breadbot. while i did not get a chance to taste a fresh-baked loaf myself, i felt the wilkinson baking company really rose to the occasion by showing a product that admittedly costs a lot of dough, but is able to deliver on-the-spot gratification to those in knead. while some ideas at ces might be half-baked, breadbot certainly is not. perhaps we’ll see it in the near future at a smart venue while we watch esports on the wall.
Lori Fraleigh
tutorials iot
blogby sangsu lee samsung’s smartthings has been working with other leaders in the tech industry to define and develop the matter protocol, the new industry standard that makes onboarding and control of devices as smooth as possible using an ip-based connection protocol with wi-fi, thread, and ethernet. to help oems integrate their devices with smartthings, we have developed ioter to emulate matter supported thread devices with a linux pc and thread rcp dongle. additionally, ioter also comes with an automation feature to help you quickly test multiple iot devices. what is ioter? ioter acts as a device emulator to developers, testers, and manufacturers of connected devices that are compliant with matter and thread. benefits include: flexibility: multiple types of iot devices can be implemented using a single rcp dongle. multi-device support: each rcp dongle supports a single device. ioter supports up to 10 rcp dongles at a time. low cost: limited expenses for testing various iot device types. time saving: virtual devices on demand - no need to search for and procure multiple iot device types. easy to use: quickly control the status of devices from within ioter. automated testing: repeated testing through scripts can validate device stability and connection. ioter emulates all matter supported devices with a linux pc and thread rcp dongle. ioter runs the all cluster app of matter on a linux pc to emulate multiple instances of various matter supported iot nodes. each of these iot nodes uses the underlying thread rcp-based usb dongle (radio) for data transmission. by using the smartthings station as a border router and smartthings application along with emulated iot nodes, we can configure a smart home. overview required tools before diving into this tutorial, ensure you have the following prerequisites set up on your development environment: bluetooth-enabled, windows desktop or laptop ubuntu 22.04 (previous versions may have bluetooth conflicts) all installation instructions have been validated on ubuntu 22.04 lts. usb hub with power input (usb3.0 recommended) thread rcp usb dongle. we verified with these: nordic nrf52840 ot rcp dongle guide nordic nrf52840-dk board ot rcp board guide phone with latest smartthings app installed an onboarded samsung smartthings station or smartthings hub. 1. set up your nrf 52840 openthread rcp dongle openthread rcp is used to connect to the thread network. apply the thread rcp firmware to the nrf52840 dongle: install 'nrf connect for desktop' on a windows pc from nordic semiconductor site execute 'nrf connect for desktop' install and open 'programmer' before selecting a device, insert the dongle and press the button shown in the red box in the image below to enter download mode. in 'select device' option , select the inserted nrf52840 dongle. in 'add file,' select rcp firmware file ot-rcp-18b6f94.hex (rcp version 6) select 'write' to flash the firmware. your openthread rcp dongle creation is complete and ready for testing! 2. install ioter clone the ioter repository and install ioter on your system. clone the ioter repository in your current directory: git clone https://github.com/samsung/ioter.git install ioter on your local machine: cd ioter ./script/setup execute ioter: ./script/run docker image support alternatively, you can use a docker image with an ‘ioter' environment. we have confirmed that it is working on the host operating systems listed below: ubuntu lunar 23.04 ubuntu jammy 22.04 (lts) ubuntu focal 20.04 (lts) ubuntu bionic 18.04 (lts) the following host operating systems are unsupported, but may work: ubuntu xenial 16.04 macos any os running on an arm platform such as raspberry pi configure the server configure your host with the following settings: set xhost to connect to x server and use x11: $ xhost +local:root (for ubuntu 23.04 only) stop the wireplumber service process that keeps the bluetooth service running: $ systemctl --user stop wireplumber turn off the bluetooth service: $ systemctl stop bluetooth or $ service bluetooth stop run docker container start the docker container with the following command: sudo docker run --rm -it -e display=$display \ -v [host_ioter_path]:/home/iot/ioter \ -v /tmp/.x11-unix:/tmp/.x11-unix \ -v "$home/.xauthority:/root/.xauthority:ro" \ --device=[device_node_path] \ -v /dev:/dev \ --privileged \ --net=host \ --cap-add=net_admin --cap-add=sys_admin \ docker.io/spdkimo/ioter:[version] \ python3 ioter/src/main.py where: host_ioter_path: path of ioter repository on host pc device_node_path: path of device node (for example, most devices start with 'dev/ttyacm') version: ioter image version such as '0.1.0' (you can find details from https://hub.docker.com/repository/docker/spdkimo/ioter/) 3. onboard matter supported iot devices reminder: before you start using ioter, ensure smartthings station has been onboarded in the samsung smartthings app. when you initiate ioter with a run script, the main window appears with a list of devices. select the device: press on the start button, the device control window appears notethe power on button is the same as the power operation of the actual device. in the smartthings app, click on the add device button in the upper right corner. use scan qr code or scan for nearby devices to start onboarding. use the qr code and/or paring code (created in step 1) to proceed with the onboarding. after onboarding the device, you can control the device states with ioter or the mobile app. the below example demonstrates controlling the on/off states of a light bulb. 4. automated testing use automations to validate the connectivity and stability of various iot device types. some examples of how you can do this include: test multiple devices in a loop use the + or - button to add/remove on-boarded device or sleep commands automation scrips are saved in xml format and can be loaded on demand. once executed, the progress bar shows the current completion percentage. pro tips: device/sleep commands can be reordered by using the ↑ and ↓ buttons. log window shows the current activities including script loads, executions, saves, and number of successful/unsuccessful commands. reference: starts/ends the loop. add the command of the on-boarded device . add sleep for the given interval. device type (for example, light bulb, contact sensor, or door lock). device types supported commands (for example, on/off or level control). device command’s value (for example, light bulb is on or off). sleep interval, in seconds. loop count and loop interval, in seconds. clears all loops and commands. runs the automation script. clears the log window. script completion progress bar. the log window, which shows current activities. next steps ioter is a powerful tool to help you onboard and test various types of iot devices in a virtual smart home environment. now that you have a solid foundation, explore ioter's features and start testing any matter thread compliant iot devices. if you encounter any issues or have any questions, please do reach out on our ioter github repository or the developer section of our smartthings community forums.
Sangsu Lee
news health, galaxy watch, mobile, ai, iot
news
We use cookies to improve your experience on our website and to show you relevant advertising. Manage you settings for our cookies below.
These cookies are essential as they enable you to move around the website. This category cannot be disabled.
These cookies collect information about how you use our website. for example which pages you visit most often. All information these cookies collect is used to improve how the website works.
These cookies allow our website to remember choices you make (such as your user name, language or the region your are in) and tailor the website to provide enhanced features and content for you.
These cookies gather information about your browser habits. They remember that you've visited our website and share this information with other organizations such as advertisers.
You have successfully updated your cookie preferences.