Just is case some other newbees (like me) around, made one also for sensors (as need those values as well in several scripts), combined above advice and Homey example-script:
_.myReadSensor = async function (sensorName, capabilityName) {
const devices = await Homey.devices.getDevices();for (const device of Object.values(devices)) {
if (!device.capabilitiesObj || device.class !== ‘sensor’) continue;if (device.name === sensorName) { const sensorCapability = device.capabilitiesObj[capabilityName]; if (sensorCapability) { return sensorCapability.value; } else { return null; } }
}
return null;
}