# How to get deviceId from a device specified in "Device: State"

**URL:** <https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484>\
**Category:** Help\
**Tags:** device-state\
**Created:** [June 4, 2024, 11:36am UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484 "2024-06-04T11:36:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Santoso](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@David\_Santoso](https://forums.losant.com/u/David_Santoso)\
**Post date:** [June 4, 2024, 11:36am UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484/1 "2024-06-04T11:36:35Z")

</div>

I’m building a simple workflow to set the connection status of a specified device in Losant. I use the “Device: State” trigger to select the device, and then I set its connection status using the “Device: Set Connection Status” node.

While I’ve been able to run this workflow successfully by manually entering the device ID, I want to use a variable such as `{{data.deviceId}}`, derived from the device selected in the “Device: State” trigger. Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [June 4, 2024, 1:29pm UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484/2 "2024-06-04T13:29:51Z")

</div>

Hi @David_Santoso,

Yes on the Device: State Trigger the device that sent the state is attached to the payload under the “device” property name. To access this devices ID the payload path would be `device.id` and to use that in handlebars it would be `{{ device.id }}`.

You can view most of the device properties on the example payload on the device state trigger.

 ![Screenshot 2024-06-04 at 9.28.21 AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/f/f732ad4b3d632126a49ee0fe8136da1b434734fd.png)

I hope this helps and let us know if you have any more questions.

Best,  
Erin

---

<div class="post-metadata">

**Author:** ![David\_Santoso](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@David\_Santoso](https://forums.losant.com/u/David_Santoso)\
**Post date:** [June 4, 2024, 2:04pm UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484/3 "2024-06-04T14:04:37Z")

</div>

Hi @Erin_Thompson, I’ve tried {{ device.id }} or {{device.deviceId}} but still getting “Validation Error - deviceId required”.

Best,  
David

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [June 4, 2024, 2:30pm UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484/4 "2024-06-04T14:30:01Z")

</div>

Hi @David_Santoso,

I went and peaked at your workflows to see what is going on. You are using a virtual button to trigger a workflow that is then using the [Device: State Node](https://docs.losant.com/workflows/outputs/device-state/) and then trying to conditionally set the connection status for that device. In this workflow you are not using the [Device: State Trigger](https://docs.losant.com/workflows/triggers/device/) at all. Let me know if I am looking at the wrong workflow but I am looking at the one that has been updated today and is named “Set Device Connection Status”.

My suggestion to you would be to have one flow that is a Virtual Button to the Device State Node. And then have another flow that is the Device: State Trigger and then you can update your conditional node to check the device state for the error property and then set the connection status to either connected or disconnected. When you have a workflow that starts with the Device: State Trigger you will have access to the device property.

If you want to keep this as one workflow, you will have to use the [Device: Get node](https://docs.losant.com/workflows/data/get-device/) to find the device and add it to your payload.

I hope this helps.

Best,  
Erin

---

<div class="post-metadata">

**Author:** ![David\_Santoso](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@David\_Santoso](https://forums.losant.com/u/David_Santoso)\
**Post date:** [June 4, 2024, 3:05pm UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484/5 "2024-06-04T15:05:26Z")

</div>

Hi @Erin_Thompson,

Yes, it’s the correct workflow and sorry, I’m using Device: State Node and not Device: State Trigger.

Since I’ve already specified the device in Device: State Node, isn’t there a way to get the deviceId of that device?

Best,  
David

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [June 4, 2024, 3:25pm UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484/6 "2024-06-04T15:25:05Z")

</div>

Hi @David_Santoso,

Unfortunately no the Device: State Node does not add a device to the payload to pass into other nodes. [Here](https://docs.losant.com/workflows/outputs/device-state/#node-example) are examples of what the device state node can add to the payload. When using a virtual button as a workflow trigger you will have to use the Device: Get node to add the device directly to the payload. If you do this then you could use the device ID from the payload on the Device State node and the set connection nodes. You can also add device ID directly on to the [data for the virtual button](https://docs.losant.com/workflows/triggers/virtual-button/#data-in-json-format).

Best,  
Erin

---

<div class="post-metadata">

**Author:** ![David\_Santoso](https://avatars.discourse-cdn.com/v4/letter/d/c0e974/32.png) [@David\_Santoso](https://forums.losant.com/u/David_Santoso)\
**Post date:** [June 4, 2024, 4:42pm UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484/7 "2024-06-04T16:42:00Z")

</div>

Thank you @Erin_Thompson, I was able to do it using the Device: Get node as per your recommendation.

I have another question though. I saw that the Device: Get node generate both device.id and device.deviceId payload. I tried both and they work, but why did it generate both?

Best,  
David

---

<div class="post-metadata">

**Author:** ![Erin\_Thompson](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/erin_thompson/32/501_2.png) [@Erin\_Thompson](https://forums.losant.com/u/Erin_Thompson)\
**Post date:** [June 4, 2024, 5:04pm UTC](https://forums.losant.com/t/how-to-get-deviceid-from-a-device-specified-in-device-state/5484/8 "2024-06-04T17:04:05Z")

</div>

@David_Santoso,

That’s to match our API schemas. Some of our API resources can return several different IDs on the same resource. It is nice to have an property with the resource type included so there is no question as to which resource an ID is referencing.

Most of our users end up using deviceId when using handlebars helpers because it includes the type of resource.

Thanks,  
Erin
