Okay, I am really a newbie in scripting… I have copy/pasted from the best of my knowledge, but I fail!
I am trying to read the Wind angle from a Netatmo Aneometer but this script return: Undefined
var angle
let devices = await Homey.devices.getDevices();
_.forEach(devices, device => {
if (device.name ==‘Netatmo - Vind’) {
angle = device.capabilities.measure_wind_angle;
}
});
return angle;
Well, thank you both. I did look in the delveloper tools and copy/pasted from there. Tried with device.capabilities[‘measure_wind_angle’]; but nothing else than Undefined…sadly
My script works just fine, thanks to you. But now I want to use the output, directions[ section ], to be used as a logical alpha for use in a flow. This is how the script looks like:
// Part I - getting the wind direction in degrees from my Netatomo Anemometer
var angle
let devices = await Homey.devices.getDevices();
_.forEach(devices, device => {
if (device.name ==‘Netatmo - Vind’) {
angle = device.capabilitiesObj?.measure_wind_angle?.value;
}
});
// Part II - converting wind direction in degrees to Cardinals
let directions = [“N”,“NNE”,“NE”,“ENE”,“E”,
“ESE”, “SE”, “SSE”,“S”,
“SSW”,“SW”,“WSW”,“W”,
“WNW”,“NW”,“NNW” ];
let section = parseInt( angle/22.5 + 0.5 );
section = section % 16;
return directions[ section ];
After the variable you want. Is your variable directions[section]? In that case:
await tag(‘Directions’, directions[section]).
‘Directions’ maybe any given name you want as Tag, directions[section] has to be the name of your variable
I’m just starting with script, but the example that comes with homey doesn’t even work and also mentions device.state so how do I check if a light is on? I have tried device.on device.onoff device.setcapabilities.onoff (it probably should be getcapabilities but that is not recognized either) but nothing seems to return anything useful.
The only thing I get to work is device.name
Thanks, I finally found it already somewhere yesterday, I did think it should have been easier to find and a bit strange that an example that you get doesn’t work…Anyway, it works now, at least for the lights, I still do not get any details about lights that are behind a Hue socket unfortunately, script is as underneath now. (I have the undefined rule in there otherwise I get some errors)
Maybe a bit off topic, but is there anyway to reset the on/off memory of a device?
I also see some hue light that was on before the power got disconnected, and thus the memory stays on, and thus it shows up in the list, but I cannot switch it off because it doesn’t find it anymore (because of poweroff through a physical wallswitch).
if (device.class != 'light' || device.virtualClass != 'light') return;
Homeyscript only reflects the state of the device as it’s known to Homey internally, so if Homey doesn’t know the correct state, there’s nothing you can do from Homeyscript to fix that.
if the comparison would be an OR, then it would return always? because if the class is a light, then the virtualclass isn’t a light and the other way around also, that is why I used an AND