# Need Help - Senor Values

**URL:** <https://community.homey.app/t/need-help-senor-values/123334>\
**Category:** Developers\
**Created:** [December 9, 2024, 10:37am UTC](https://community.homey.app/t/need-help-senor-values/123334 "2024-12-09T10:37:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![owuerker](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/owuerker/32/39707_2.png) [@owuerker](https://community.homey.app/u/owuerker)\
**Post date:** [December 9, 2024, 10:37am UTC](https://community.homey.app/t/need-help-senor-values/123334/1 "2024-12-09T10:37:49Z")

</div>

How can I get all sensor having the capability “measure\_generic.plant.nameX” with the string “problem”. NameX are values from 1 to 70.

I tried this with the following script, but I don´t get any value.

// Loop over all devices  
// Get all devices  
const devices = await Homey.devices.getDevices();

// Loop over all devices  
for (const device of Object.values(devices)) {

// If this device isn’t available, skip it.  
if (!device.capabilitiesObj[`measure_generic`]) continue;

if (device.class === ‘sensor’) {  
if (device.capabilitiesObj[`measure_generic`].value === `problem`){  
log (`\n ${device.name} braucht Wasser`);  
}  
}  
}

Lot of thanks for your help

---

<div class="post-metadata">

**Author:** ![Andy\_Henderson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andy_henderson/32/80642_2.png) [@Andy\_Henderson](https://community.homey.app/u/Andy_Henderson)\
**Post date:** [December 9, 2024, 12:28pm UTC](https://community.homey.app/t/need-help-senor-values/123334/2 "2024-12-09T12:28:30Z")

</div>

I’d remove the test for device.class. It seems to me unlikely that a device with the measure\_generic capability would not be a sensor. But you’ll know your setup better than me.

If you add log(device.capabilitiesObj); immediately before testing the value, you’ll do two things:

- Check you are testing for the correct capability (it won’t log anything if not)
- See how capabilities are stored in the object

I suspect you’ll need to burrow down into the object since measure\_generic.plant.nameX suggests that measure\_generic contains ‘plant’ and that ‘plant’ contains several ‘namex’s’.

Andy

---

<div class="post-metadata">

**Author:** ![owuerker](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/owuerker/32/39707_2.png) [@owuerker](https://community.homey.app/u/owuerker)\
**Post date:** [December 9, 2024, 3:31pm UTC](https://community.homey.app/t/need-help-senor-values/123334/3 "2024-12-09T15:31:44Z")

</div>

Thanks  
I added it. Here are two outputs

‘\*\ ***measure\_generic.plant.gelbbunte\_kriechspindel\_51** ’\*\*: {  
id: ‘measure\_generic.plant.gelbbunte\_kriechspindel\_51’,  
type: ‘string’,  
iconObj: {  
id: ‘2b41045f0246a9312cec9161a2bc8079’,  
url: ‘/api/icon/a4dd0ba4-0aed-4a16-a08a-7520c704fdb0’  
},  
title: ‘gelbbunte Kriechspindel (51)’,  
getable: true,  
setable: false,  
insights: true,  
insightsTitleTrue: null,  
insightsTitleFalse: null,  
**value: ‘ok’,**  
lastUpdated: 2024-12-05T16:49:53.924Z

Another one is

' **measure\_generic.plant.passionsblume\_59’:** {  
id: ‘measure\_generic.plant.passionsblume\_59’,  
type: ‘string’,  
iconObj: {  
id: ‘2b41045f0246a9312cec9161a2bc8079’,  
url: ‘/api/icon/a4dd0ba4-0aed-4a16-a08a-7520c704fdb0’  
},  
title: ‘Passionsblume (59)’,  
getable: true,  
setable: false,  
insights: true,  
insightsTitleTrue: null,  
insightsTitleFalse: null,  
**value: ‘problem’,**  
lastUpdated: 2024-12-09T11:05:48.746Z  
},

The common capability name is measure\_generic.plant. The rest is different.

Can you help me how I can add now a check about the 70 sensors to get a list of the sensors with value: “problem” in measure\_generic\_plant.xxxxxx

Lot of thanks

---

<div class="post-metadata">

**Author:** ![Andy\_Henderson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andy_henderson/32/80642_2.png) [@Andy\_Henderson](https://community.homey.app/u/Andy_Henderson)\
**Post date:** [December 9, 2024, 4:21pm UTC](https://community.homey.app/t/need-help-senor-values/123334/4 "2024-12-09T16:21:42Z")

</div>

Looks like you’re close.

It would help if you use the ‘Preformated text’ icon to enclose your code since the forum has done something with your quotes. I’m guessing your code looks something like this:

```auto
// Get all devices
const devices = await Homey.devices.getDevices();

// Loop over all devices
for (const device of Object.values(devices)) {

// If this device isn’t available, skip it.
if (!device.capabilitiesObj[`measure_generic`]) continue;

if (device.capabilitiesObj[`measure_generic`].value === `problem`){
log (`\n ${device.name} Braucht Wasser`);
}
}

```

Try replacing ${device.name} with:

```auto
${device.capabilitiesObj['measure_generic'].id}

```

Does that give you what you want?

Andy

---

<div class="post-metadata">

**Author:** ![owuerker](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/owuerker/32/39707_2.png) [@owuerker](https://community.homey.app/u/owuerker)\
**Post date:** [December 9, 2024, 4:59pm UTC](https://community.homey.app/t/need-help-senor-values/123334/5 "2024-12-09T16:59:30Z")

</div>

Thanks a lot Andy,  
I replaced it but still no output and no error message. ☹  
Here my actual code

```auto
// Get all devices
const devices = await Homey.devices.getDevices();

// Loop over all devices
for (const device of Object.values(devices)) {

// If this device isn’t available, skip it.
if (!device.capabilitiesObj[`measure_generic`]) continue;

if (device.capabilitiesObj[`measure_generic`].value === `problem`){
  log (`\n ${device.capabilitiesObj[`measure_generic`].id} braucht Wasser`);
  }
}

```

---

<div class="post-metadata">

**Author:** ![owuerker](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/owuerker/32/39707_2.png) [@owuerker](https://community.homey.app/u/owuerker)\
**Post date:** [December 9, 2024, 5:08pm UTC](https://community.homey.app/t/need-help-senor-values/123334/6 "2024-12-09T17:08:43Z")

</div>

I changed the apostrophe.  
Butt still the same…

```auto
// Get all devices
const devices = await Homey.devices.getDevices();

// Loop over all devices
for (const device of Object.values(devices)) {

// If this device isn’t available, skip it.
if (!device.capabilitiesObj['measure_generic']) continue;

if (device.capabilitiesObj['measure_generic'].value === "problem"){
  log ("\n ${device.capabilitiesObj['measure_generic'].id} braucht Wasser");
  }
}

```

---

<div class="post-metadata">

**Author:** ![Andy\_Henderson](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/andy_henderson/32/80642_2.png) [@Andy\_Henderson](https://community.homey.app/u/Andy_Henderson)\
**Post date:** [December 9, 2024, 5:49pm UTC](https://community.homey.app/t/need-help-senor-values/123334/7 "2024-12-09T17:49:07Z")

</div>

> [@owuerker](#):
>
> `log ("\n ${device.capabilitiesObj['measure_generic'].id} braucht Wasser");`

Definitely won’t work, you need to use back ticks for templated strings.

If you’re not seeing a log message or an error message, the issue must be the test:

```auto
if (device.capabilitiesObj['measure_generic'].value === "problem"){

```

I can suggest a couple of things, but then I’m out of ideas:

- Try replacing the strict equality === with equality ==  
I don’t see why that would be an issue, though
- Try using != ‘ok’ instead; at the least it should output something!

Also, I just saw:

```auto
device.capabilitiesObj['measure_generic'].title

```

Would give you nicer output than using the id.

Andy

---

<div class="post-metadata">

**Author:** ![owuerker](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/owuerker/32/39707_2.png) [@owuerker](https://community.homey.app/u/owuerker)\
**Post date:** [December 9, 2024, 7:01pm UTC](https://community.homey.app/t/need-help-senor-values/123334/8 "2024-12-09T19:01:34Z")

</div>

Unfortunatly none idea worked. But thanks a lot for your help and suggestions  
But I found some code snippets. It is working using

```auto
// Get all devices
let devices = await Homey.devices.getDevices();

_.forEach(devices, device =>
  {
    if (device.class !=`sensor`) return;
    if (device.capabilitiesObj?.measure_generic == `problem`) return;
    log (`\n${device.name} braucht Wasser`);
  }
);

```

---

<div class="post-metadata">

**Author:** ![owuerker](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/owuerker/32/39707_2.png) [@owuerker](https://community.homey.app/u/owuerker)\
**Post date:** [December 9, 2024, 10:09pm UTC](https://community.homey.app/t/need-help-senor-values/123334/9 "2024-12-09T22:09:48Z")

</div>

Now I get some sensors.  
But there measure\_generic.xxxxx value ist not like I want with value “problem”

Can any developer jump in and help.  
It is hard stuff to understand for a newbie

Thanks

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [December 10, 2024, 6:00am UTC](https://community.homey.app/t/need-help-senor-values/123334/10 "2024-12-10T06:00:25Z")

</div>

It seems you are using a device imported from HA 😀

What do do you want to read from your device?  
You want to get all devices with value ‘problem’?  
measure\_generic is a string capability. And it seems you added it from an entity in repair view. Then a subcapability is used.

What about adding an alarm capability in addition that is set if the entity state is ‘problem’? Then you also can see this in Homey. And use it in your script.  
Or you can add the entity as main capability (only measure\_generic) - if it’s the only capability with this ID in the device.

Or you can just check the value independent of the capability ID. Let me buil da short script…

Check this. It just checks all sensor devices if any measure\_generic\* capability has a value ‘problem’.

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

Object.keys(devices).forEach( (key) => {
  let device = devices[key];
  if (device.class != 'sensor') return;
  if (!device.capabilitiesObj) return;
  Object.keys(device.capabilitiesObj).forEach( (key) => {
    if (key.startsWith('measure_generic') && device.capabilitiesObj[key].value == 'problem')
    log (`\n${device.name} braucht Wasser`);
  })
})

```

---

<div class="post-metadata">

**Author:** ![owuerker](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/owuerker/32/39707_2.png) [@owuerker](https://community.homey.app/u/owuerker)\
**Post date:** [December 10, 2024, 11:55am UTC](https://community.homey.app/t/need-help-senor-values/123334/11 "2024-12-10T11:55:38Z")

</div>

> [@RonnyW](#):
>
> ```auto
> let devices = await Homey.devices.getDevices();
> 
> Object.keys(devices).forEach( (key) => {
> let device = devices[key];
> if (device.class != 'sensor') return;
> if (!device.capabilitiesObj) return;
> Object.keys(device.capabilitiesObj).forEach( (key) => {
> if (key.startsWith('measure_generic') && device.capabilitiesObj[key].value == 'problem')
> log (`\n${device.name} braucht Wasser`);
> })
> })
> 
> ```

Thanks a lot Ronny. It is working like I want
