PrerequisitesBefore completing this tutorial, you should have read the, and registered for an account as discussed in the page.It is recommended that you become at least familiar with the basic Groovy concepts discussed in the and tutorials.Start by logging into IDE at at.Next, navigate to My Locations page to see the Locations you created.Normally you will see just one Location where you installed your Hub.Click on the Location name appearing in the far left column (i.e., the Name column). You may need to log in again with your SmartThings userid and password. Create a SmartAppIn the IDE, navigate to the My SmartApps page.This will bring you to a page that shows all of the SmartApps that you have created.This is also where you can create a new SmartApp. EditorOnce you’ve created your SmartApp, you’ll be taken to the editor and Simulator.Before we look at the code, it’s worth becoming familiar with some of the basic features.Above the code window, there are five buttons: Save This button saves your SmartApp in the SmartThings cloud. Publish This allows you to publish your SmartApp for yourself, so you may install it in your SmartThings mobile app, as well as to submit it to the SmartThings team for publication into the SmartThings catalog. IDE Settings Here you can make changes to personalize the editor to your liking.You can choose from a variety of themes to control the look and feel, specify your preferred keymapping, and set the font size.
App Settings This takes you back to the form that you created this SmartApp from, where you can view the values entered when you created the SmartApp, as well as edit certain properties about the SmartApp. Simulator This button toggles the display of the online Simulator.
We’ll discuss the Simulator in further detail next. Definition ( name: 'My First SmartApp', namespace: 'mygithubusername', author: 'Peter Gregory', description: 'This is my first SmartApp. , category: 'My Apps', iconUrl: ', iconX2Url: ', iconX3Url: ')We don’t need to change anything here, so let’s move on to defining our preferences.If you do need to change some of your SmartApp’s metadata, you can change these values later. PreferencesThe preferences method is where we define what information our SmartApp needs from the user.When a user installs a SmartApp on their mobile device, they will be taken to a screen (or screens) where they can configure the SmartApp.The content of these screens are derived from our preferences definition.Preferences can be displayed as a simple, single screen, or multiple screens.This tutorial will use a simple preferences definition, with only one screen.In the editor, there is a preferences definition stubbed in for us.
Please Microsoft, read this comment, this app developer is scamming people, me included. You should ban this app from the store and offer refunds since you are the ones allowing this to happen. I can't believe I keep waiting for you to take this kind of issues seriously. PLEASE FIX THE APP OR GIVE US OUR MONEY BACK.
Input 'theswitch', 'capability.switch', required: trueThe first argument to input is what we - inside our SmartApp - want to refer to the device as.In this case, we use 'theswitch'.This becomes the identifier for the device in our SmartApp, so that we can refer to the switch as theswitch (without the quotes).We’ll see this in action shortly.The second argument is the type of device our SmartApp will work with.' Capability.switch' states that our SmartApp is requesting the user to pick from any device that supports the Switch capability.The concept of capabilities is core to SmartThings, and requires a bit more explanation.First, consider that the catalog of connected devices is growing at a rapid pace.New devices arrive on the market almost daily.Many of these devices do similar things, and some do multiple things. NoteWe could also subscribe to any change in the motion sensor, by simply specifying the attribute we want to monitor (e.g., 'motion' instead of 'motion.active').This would then call the specified handler method when there is any reported change to the 'motion' attribute.For attributes that don’t have a discrete set of possible values (for example, temperature readings), this is how we subscribe to changes for that attribute.We can then get the value of the Event in the event handler by looking at the value of the passed-in Event.If we were to do this in our SmartApp, it would look like this. SummaryIn this tutorial, you learned how to write a SmartApp.
To do this, we:. Created a new SmartApp using the web-based IDE. Defined the preferences that specifies what input we need from the user. Subscribed to device Events and controlled a device. We used the to determine what attributes and commands a capability supports. Used the web-based Simulator to test our SmartApp with virtual devices.
Published the SmartApp for yourself and installed it on your mobile phone. Extended our SmartApp by allowing a user to enter the number of minutes to wait before turning the switch off, and implemented this using the runIn method.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |