# Using a function to read sensor values

**URL:** <https://community.homey.app/t/using-a-function-to-read-sensor-values/32589>\
**Category:** Developers\
**Tags:** javascript\
**Created:** [July 20, 2020, 12:19pm UTC](https://community.homey.app/t/using-a-function-to-read-sensor-values/32589 "2020-07-20T12:19:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oscar\_Andersson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/oscar_andersson/32/26933_2.png) [@Oscar\_Andersson](https://community.homey.app/u/Oscar_Andersson)\
**Post date:** [July 20, 2020, 12:19pm UTC](https://community.homey.app/t/using-a-function-to-read-sensor-values/32589/1 "2020-07-20T12:19:08Z")

</div>

I am writing a function which returns two values from different Aqara sensors.  
But I only get values from the same sensor, how should I rewrite this code:

```auto
let devices = await Homey.devices.getDevices();
let sensor;

function readvalues(sensorID){  
Object.values(devices).forEach(device => {
if (device.id = sensorID) {                
            sensor = device;
        }       
    });
    var RH = sensor.capabilitiesObj.measure_humidity.value;
    var Temp = sensor.capabilitiesObj.measure_temperature.value;
return [RH,Temp];
}
var values = readvalues("87dd5a75-7948-4be2-8a27-49bb8b2b5f6c");
log (values);

var values2 = (readvalues("d03e1905-3a79-4fa3-8371-eaafee164925"));
log (values2);

return values[0]-values2[0];

```

This is the result:

[59.9, 20.5]  
[59.9, 20.5]

* * *

Script returned:  
0

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [July 20, 2020, 1:42pm UTC](https://community.homey.app/t/using-a-function-to-read-sensor-values/32589/2 "2020-07-20T13:42:53Z")

</div>

> [@Oscar\_Andersson](#):
>
> if (device.id = sensorID)

That’s an assignment, not a comparison. You should use `==` or (preferably) `===`.
