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:
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