Advanced flow. Controleren of er nog lampen aan staan

Graag gedaan. Voor nu weet ik daar een heel handige app voor, Zone Memory.

Je kunt ook een paar losse ‘actie’ flows maken, waarin je een groep lampen op verschillende gewenste dim nivo’s instelt. Een groep voor overdag, 's avonds etc

De < group > app is ook erg handig. Zet een paar lampen in een groep, en je kunt de gezamenlijke capaciteiten als zijne 1 lamp bedienen.
Je kunt ook groepen in een groep ‘hangen’.
Ik heb hier een dim script, welke instelbare tijdsduur en stapgrootte heeft. (Hier zijn ook apps zoals Transitions en Chronograph voor, maar met gebruik in flows kun je “de flow is gedisabled want was te vaak gestart” meldingen krijgen.
Flow:

Bijbehorend script:

/*
 * Dim a light in steps (transition)
 */
// Use flowcard "Run Homeyscript DimAlightGradient with argument",
// the argument is the lamp's name.
let myLight = args[0]

// User input 
// enter the target dim level
var myDimlevel = 0.80; /* range: 0.01 - 1 */
// enter a start dim level
var myDimlevelStart = 0.01; /* range: 0.01 - 1 */
// Enter a delay time (for the next dim level)
var waitForDimlevel = 750; /* time in ms */
// Enter the value to increase the dim level with
var myDimlevelStep = 0.05; /* range: 0.01 - 1 */
// User input end

if (myLight == '' || myLight == undefined) {
    console.log ('Missing argument');
    return(false);
} else {

var waitTime = ''
// Get all devices
const devices = await Homey.devices.getDevices();

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

    if (device.name == myLight) {

      // If this device is a light (class)
      // Or this is a 'What's plugged in?'-light (virtualClass)
      if (device.class === 'light' || device.virtualClass === 'light' || device.class == 'button') {

      await log(`\nWait for ${waitForDimlevel}ms between steps of ${myDimlevelStep} `)         

        // this works, but myDimlevelStep has to be rounded
        for (let step = Number(myDimlevelStep); step <= myDimlevel; step += Number(myDimlevelStep)) {  
          await wait(waitForDimlevel);
          step = Math.round((step)*100)/100; // round to 0.00      
          
          log(`\nDimming ${device.name} to ${step}`)
          
          // increasing the dim level
          await device.setCapabilityValue('dim', step)
            .then(() => log('OK'))
            .catch(error => log(`Whoops an Error!:`, error));
        }
      }
    }
  }
}

return(true);

.
Toegevoegd script:
Deze start vanaf het huidige dim niveau van de lamp:

// Dim a light up in steps, starting with it's current dim level

// Use flowcard "Run Homeyscript DimSlowX-100 with argument",
// the argument is the lamp name

// (for a media device for it's volume: device.class = amplifier, volume = volume_set).
let myLight = args[0]
// // only for testing with console
//myLight = "Lamp Bank R"

//
// USER INPUT
// Crucial: Enter the time it takes for the light,
// to return it's dimlevel to this script
var waitForCurrendDimValue = 1500; /* time in ms */
// enter the TARGET dim level
var myDimlevel = 0.5; /* range: 0.01 - 1 */
// Enter the step delay time (for the next dim level)
var waitForDimlevel = 500; /* time in ms */
// Enter the step value to increase the dim level with
var myDimlevelStep = 0.02;
// User input end
//

if (myLight == '' || myLight == undefined) {
    console.log ('Missing argument, enter a device name at flowcard argument field');
    return(false);
} else {

// Turn the light on, to be able to get the current dim value
let device_id
const devices1 = await Homey.devices.getDevices({ filter: {name: myLight} });
_.forEach(devices1, device => {
  device.setCapabilityValue('onoff', true)
  log(device.name + ' was turned on')
});

log(`\Wait for ${waitForCurrendDimValue} millseconds for light to return its dim level`);
await wait(waitForCurrendDimValue)
  .then(() => log('OK'))
  .catch(error => log(`Whoops an Error!:`, error));

var waitTime = ''

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

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

    if (device.name == myLight) {

      // If this device is a light (class)
      // Or this is a 'What's plugged in?'-light (virtualClass)
      if (device.class === 'light' || device.virtualClass === 'light' || device.class == 'button') {

      await log(`\nWait for ${waitForDimlevel}ms between steps of ${myDimlevelStep} `)

      // // Turn the light on
      // await device.setCapabilityValue('onoff', true)
      //  .then(() => log('OK'))
      //  .catch(error => log(`Whoops an Error!:`, error));

      // Get the current dim level of the device
      currentDimlvl = device.capabilitiesObj.dim.value;
      log(`\nCurrent Dim level: ${currentDimlvl}`);

        // this works, but myDimlevelStep has to be rounded
        for (let step = Number(currentDimlvl); step <= myDimlevel; step += Number(myDimlevelStep)) {
          await wait(waitForDimlevel);
          step = Math.round((step)*100)/100; // round to 0.00

          log(`\nDimming ${device.name} to ${step}`)

          // increasing the dim level
          await device.setCapabilityValue('dim', step)
            .then(() => log('OK'))
            .catch(error => log(`Whoops an Error!:`, error));

          // just in case, quit if 'step' has become 1
          if (step == 1) {
          break;
          }
        }
      }
    }
  }
}

return(true);
2 Likes