# How to set input devices as optional?

**URL:** <https://community.smartthings.com/t/how-to-set-input-devices-as-optional/22009>\
**Category:** Writing SmartApps\
**Created:** [September 8, 2015, 10:27am UTC](https://community.smartthings.com/t/how-to-set-input-devices-as-optional/22009 "2015-09-08T10:27:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cety](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@Cety](https://community.smartthings.com/u/Cety)\
**Post date:** [September 8, 2015, 10:27am UTC](https://community.smartthings.com/t/how-to-set-input-devices-as-optional/22009/1 "2015-09-08T10:27:18Z")

</div>

Hi Guys,

For below code

preferences {  
section(“Select Devices”) {  
// TODO: put inputs here  
input “door”, “capability.contactSensor”, title: "Select a Door sensor"  
input “livingMotion”, “capability.motionSensor”, title: "Select Living Room Sensor"  
input “bedroomMotion”, “capability.motionSensor”, title: "Select Bedroom Sensor"  
input “bathroomMotion”, “capability.motionSensor”, title: "Select Bathroom Sensor"  
input “kitchenMotion”, “capability.motionSensor”, title: “Select Kitchen Sensor”  
}  
}

I defined 5 sensors for this smartApp, but currently i only have 4 sensors with me, can I put 1 of the sensor input as optional without remove my current code?  
Currently SmartThings App need user fill all the input, else I will get “Please fill out all required fields” message on my SmartThings App

---

<div class="post-metadata">

**Author:** ![Cety](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@Cety](https://community.smartthings.com/u/Cety)\
**Post date:** [September 8, 2015, 11:57am UTC](https://community.smartthings.com/t/how-to-set-input-devices-as-optional/22009/2 "2015-09-08T11:57:08Z")

</div>

Got the answer myself 😄

just simply add required: false

But I got unexpected error on my SmartThings APP ☹

---

<div class="post-metadata">

**Author:** ![bravenel](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/bravenel/32/13223_2.png) [@bravenel](https://community.smartthings.com/u/bravenel)\
**Post date:** [September 8, 2015, 4:02pm UTC](https://community.smartthings.com/t/how-to-set-input-devices-as-optional/22009/3 "2015-09-08T16:02:04Z")

</div>

If you don’t input anything, then that variable will be `null`. So in your code, you have to protect against trying to do something with a `null` value. One way to do that is this very simple test, for example:

```
if(kitchenMotion) { .... code that does something with kitchenMotion .... }

```

If `kitchenMotion` is `null`, the test fails, the code doesn’t execute (which is what you want), and you don’t step on the null value.

---

<div class="post-metadata">

**Author:** ![Cety](https://avatars.discourse-cdn.com/v4/letter/c/a87d85/32.png) [@Cety](https://community.smartthings.com/u/Cety)\
**Post date:** [September 10, 2015, 5:23am UTC](https://community.smartthings.com/t/how-to-set-input-devices-as-optional/22009/4 "2015-09-10T05:23:58Z")

</div>

Thanks Bruce 😄
