Skip to content

Instantly share code, notes, and snippets.

@iver56
Last active June 5, 2024 06:40
Show Gist options
  • Save iver56/c5efac308740ccea725bd3eb3ce44350 to your computer and use it in GitHub Desktop.
Save iver56/c5efac308740ccea725bd3eb3ce44350 to your computer and use it in GitHub Desktop.
HomeyScript for checking the position of a sunscreen connected to e.g. Fibaro Roller Shutter 3 or Walli Roller Shutter
/*
* This script is meant to be used in a Homey Flow with the
* 'Run a script with an argument' in the 'And'-column.
* The argument must be the name of the device, then a less than or greater than character (< or >) and finally a number between 0 and 1, e.g. "Zip Nord Venstre<0.5" (note: no spaces around the < or > character!)
*/
if (typeof args[0] !== 'string') {
throw new Error('This script must be run from a Flow!');
}
let comparisonOperator = args[0].includes('<') ? '<' : '>';
log(`comparisonOperator: ${comparisonOperator}`);
let sensorName = args[0].split(comparisonOperator)[0];
log(`sensorName: ${sensorName}`);
let valueThreshold = parseFloat(args[0].split(comparisonOperator)[1]);
log(`valueThreshold: ${valueThreshold}`);
// Get all devices
const devices = await Homey.devices.getDevices();
let device = null;
// Loop over all devices
for (const d of Object.values(devices)) {
// If this device isn't available, skip it.
if (!d.capabilitiesObj) continue;
if (d.name == sensorName) {
log(`\n=== Found device ${d.name} ===`);
device = d;
break;
}
}
if (null === device) {
throw new Error(`Could not find available device with name ${sensorName}`);
}
if (typeof device.capabilitiesObj.windowcoverings_set === 'undefined') {
throw new Error(`Could not find the property windowcoverings_set in device ${sensorName}`);
}
const capability = device.capabilitiesObj.windowcoverings_set;
log(`value: ${capability.value}`);
if (comparisonOperator === '<') {
return capability.value < valueThreshold;
} else {
return capability.value > valueThreshold;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment