Handling Devices (Finding by name and adding new)

Sorry, I think this is a bit of a basic question, but I’m only 30 minutes into writing my first SmartApp.

My goal is to subscribe to receive updates from a Raspberry PI which is talking to my alarm. I have that bit figured out, I’m just trying to work out the devices part.

I’m trying to figure out two things:

  1. How do you find a Device in a list by Name? I know I can loop through the whole list, but that’s not particularly efficient

  2. Is it possible to programmatically add a device? When I loop through the devices, I’d like to programmatically add a new Contact Sensor if I’m getting data for a device that isn’t already registered with Smart Things.


Depends on the protocol.

As a security measure, zigbee requires that you prove that you have access to a new device by doing something physically with that device at the time of joining. Usually that’s a button press, sometimes it’s a specific on off pattern. This is intended to prevent a hacker from remotely stealing control of devices.

Zwave has almost the same thing except that it will allow one controller to transfer its entire network to another controller without physically manipulating the individual devices.

Oh I don’t need ZigBee or zWave. I just need a Simulated Contact Sensor.

I think you might be able to do that, there are a couple of smart apps that do generate new virtual devices.

Check out SwitchMania, it creates four different kinds of virtual devices.

Thanks, I’ll check it out.