# Extract value from switch-bot reading

**URL:** <https://discourse.nodered.org/t/extract-value-from-switch-bot-reading/76439>\
**Category:** General\
**Tags:** function-node\
**Created:** [11 March 2023 19:38 UTC](https://discourse.nodered.org/t/extract-value-from-switch-bot-reading/76439 "2023-03-11T19:38:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matisok](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/matisok/32/3445_2.png) [@matisok](https://discourse.nodered.org/u/matisok)\
**Post date:** [11 March 2023 19:38 UTC](https://discourse.nodered.org/t/extract-value-from-switch-bot-reading/76439/1 "2023-03-11T19:38:05Z")

</div>

Hi there.

I have recently grown fond of the switch-bot IoT devices - they are well made and seem to be open for node-red.

I am using the node: test-switchbot-devices which reads my connected devices nicely. A call returns this:

 ![Screenshot 2023-03-11 at 20.35.58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/bace04b1b9467c70be7e88da93fb64331f9af322.png)

and the device I am interested in is at "object 3" in the screenshot.

{"deviceId":"DE1B6383BD87","deviceType":"Meter","hubDeviceId":"DC5EC64D9A13","humidity":36,"temperature":19.1}

and I am specifically interested in collecting the temperature value.

I suppose I run this through a function node? How should it look like?

Thanks for the help.

Mathias

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [11 March 2023 20:04 UTC](https://discourse.nodered.org/t/extract-value-from-switch-bot-reading/76439/2 "2023-03-11T20:04:40Z")

</div>

In a change mode  
set `msg.` `payload`  
to JSONata J:  
`$$.payload[deviceId = "DE1B6383BD87"]`

That should return the object.  
To get indiviual readings add `.temperature` etc, or later in flow use `msg.payload.temperature`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 May 2023 20:04 UTC](https://discourse.nodered.org/t/extract-value-from-switch-bot-reading/76439/3 "2023-05-10T20:04:51Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
