Advanced flow. Controleren of er nog lampen aan staan

Hallo Homey gebruikers,

Ik ben wat aan de slag gegaan met Advanced flows.
Wat ik graag zou willen doen is dat als de laatste persoon het huis verlaat er gecontroleerd wordt of er nog lampen aanstaan.
Ik kan alleen geen flow kaart vinden die kijkt of er lampen aan staan.

ik heb wel een test gedaan met de kaart alle lampen. Maar dan ziet de flow het niet als waar als er 1 lamp aan staat in plaats van alle.

Hebben jullie ideeën?

Mvg,

Jasper

Kan je iets meer uitleg geven over wanneer je deze actie controleert en hoe?

Je zou een variabele ja/nee kunnen gebruiken.

Heb je bijvoorbeeld een flow voor weggaan? Dan zou je hier kunnen maken als persoon x weggaat en status lampen is ja dan geef melding: wil je de lampen uitzetten?

Je kunt gebruik maken van de onderstaande kaart in de EN kolom. Dit kun je per ruimte doen of de gehele woning.

1 Like

Ik zie bij EN de volgende kaarten:

De Flow die ik wil maken is:

  1. Als de laatste persoon weggaat.
  2. En er staan nog lampen aan
  3. stuur notificatie naar gebruiker x

Maar als ik het gelijk zo kan maken dat je de vraag krijgt om ze uit te zetten als er nog aan staan zou het helemaal super zijn :smiley:

En is er ook een manier om dan te laten zien in een notificatie welke lamp(en) er nog aan staan?

1 Like

Dan zou ik even in Homeyscript duiken. Een dergelijke heb ik in het verleden al eens langs zien komen.

Klopt @Dijker :wink:
Ik had een script van RonnyW wat aangepast voor een open deur/raam alert.
Dat kan natuurlijk ook met lampen (en tussenstekkers, waar vaak ook lampen aan hangen).

@Jasper_vd
(Je hebt er geen AF voor nodig, maar het kán wel in AF natuurlijk)

Flow:

De variabele wordt automatisch aangemaakt en geupdatet.

.
Maak een nieuw script in HomeyScript, ik heb het script “which_lights_still_on.js” genoemd; Kopieer onderstaande code naar het script en sla het op.
Onder het kopje // USER INPUT pas je de device namen aan naar de lampen en stekkers die jij wil monitoren, en sla het weer op.
Daarna kun je de flow testen.

// Which light/socket is still on?

let devices = await Homey.devices.getDevices();
let lightsText = "";
let currentText = "";
let logText = "";
let lightsON = false;
_.some(devices, device =>
{
if ( device.class == 'light' ||  
device.virtualClass == 'light' || 
device.class == 'socket' ) 
// device.class is found at https://tools.developer.homey.app/tools/devices

  {
  if ( device.capabilitiesObj &&
  device.capabilitiesObj.onoff &&
  device.capabilitiesObj.onoff.value )
    {
    // just to compare and check if there was no typo
    console.log("- Device:", device.name + " (device.class: " + device.class + ")");
    currentText = "";
    // Enter lights and sockets names, device.name == "Exact light/socket name"
    // currenText = "Sensible light/socket name"
    if ( device.name == "Eettafel lamp" ) currentText = "Eettafel lamp";
    if ( device.name == "Spots OSD achter" ) currentText = "Spots OSD achter";
    if ( device.name == "Gang beneden" ) currentText = "Gang beneden";
      if(currentText != ""){
      lightsON = true;
      if(lightsText=="")
      lightsText = currentText;
      else
      lightsText = lightsText + "\n" + currentText;
      }
    }
  }
});

if ( lightsON == true )
lightsText = "De volgende lampen of stekkers staan nog AAN:\n" + lightsText + "\n";
/// ENglish:
// lightsText = "The following lights or sockets are still ON: " + lightsText;
else
// comment this out if you don't want a msg when all's fine:
lightsText = "Alle lampen en stekkers zijn uit";
/// ENglish:
// lightsText = "All lights and sockets are off";

// just to compare and check
console.log("\nOutput:\n", lightsText);

// Create / update HomeyScript variabele
await tag("lights_plugsText", lightsText);

return (true);

Resultaat (voorbeeld):

Have fun
~Peter

2 Likes

Enorm bedankt voor je hulp @Peter_Kawa!

Ik loop tegen een probleempje aan.
Ik heb de devices hernoemd naar de namen uit mijn Homey.

// Which light is still on?

let devices = await Homey.devices.getDevices();
let lightsText = "";
let currentText = "";
let logText = "";
let lightsON = false;
let plugsON = false;
_.some(devices, device =>
{
if ( device.class == 'light' ||  device.virtualClass == 'light' || device.class == 'socket' )

  {
  if ( device.capabilitiesObj &&
  device.capabilitiesObj.onoff &&
  device.capabilitiesObj.onoff.value
  )
    {
    // just to compare and check if there was no typo
    console.log("- Device:", device.name + " (device.class: " + device.class + ")");
    currentText = "";

// USER INPUT
    // Enter lights and sockets names, device.name == "Exact light/socket name"
    // currenText = "Sensible light/socket name"
    if ( device.name == "Eettafel lamp" ) currentText = "Eettafel lamp";
    if ( device.name == "Spots OSD achter" ) currentText = "Spots OSD achter";
    if ( device.name == "Gang beneden" ) currentText = "Gang beneden";
    if ( device.name == "Keuken lamp" ) currentText = "Keuken lamp";
    if ( device.name == "Spotjes keukenblad" ) currentText = "Staande Lamp";
    if ( device.name == "Lamp Wc Beneden" ) currentText = "Lamp Wc Beneden";
    if ( device.name == "Spotjes voor" ) currentText = "Spotjes voor";
    if ( device.name == "Spotjes OSD voor" ) currentText = "Spotjes OSD voor";
    if ( device.name == "Spotjes badkamer" ) currentText = "Spotjes badkamer";
    if ( device.name == "Lamp gang boven" ) currentText = "Lamp gang boven";
    if ( device.name == "Slaapkamer inloop" ) currentText = "Slaapkamer inloop";
    if ( device.name == "Slaapkamer spotjes" ) currentText = "Slaapkamer spotjes";
    if ( device.name == "Lamp trapgat" ) currentText = "MuziekSet Power";
    if ( device.name == "Lamp wc boven" ) currentText = "Lamp wc boven";
    if ( device.name == "Lamp deuren voor buiten" ) currentText = "Lamp deuren voor buiten";
   // End of user input

      if(currentText != ""){
      lightsON = true;
      plugsON = true;
      if(lightsText=="")
      lightsText = currentText;
      else
      lightsText = lightsText + ", " + currentText;
      }
    }
  }
});

if ( lightsON == true || plugsON == true )
lightsText = "De volgende lampen of stekkers staan nog AAN: " + lightsText;
/// ENglish: 
// lightsText = "The following lights or sockets are still ON: " + lightsText;
else
// comment this out if you don't want a msg when all's fine:
lightsText = "Alle lampen en stekkers zijn uit";
/// ENglish: 
// lightsText = "All lights or sockets are off";

// just to compare and check
console.log("Output: ", lightsText);

// Create / update HomeyScript variabele
await tag("lights_plugsText", lightsText);

return (true);

Als ik dan test met een lamp nog aan krijg ik de volgende melding:

  • Device: Eettafel Lamp (device.class: light)
    Output: Alle lampen en stekkers zijn uit

Hij ziet dus wel dat de eettafel lamp aan is maar me output is dat alle lampen en stekkers uit zijn. (dat krijg ik dan ook als notificatie uit met flow)

Zie je toevallig waar het fout gaat in het script? (waarschijnlijk heb ik iets verkeerd veranderd :face_with_raised_eyebrow: :innocent:)

Bedankt alvast!

Graag gedaan, Jasper.
Je was 2 dingetjes vergeten te veranderen (dat zie je wel in het script), maar dat maakt voor jouw script output niets uit verder

Ik wllde teveel tegelijk in het script denk ik :wink:
Probeer dit script eens!

// Which light/socket is still on?

let devices = await Homey.devices.getDevices();
let lightsText = "";
let currentText = "";
let logText = "";
let lightsON = false;
_.some(devices, device =>
{
if ( device.class == 'light' ||  
device.virtualClass == 'light' || 
device.class == 'socket' ) 
// device.class is found at https://tools.developer.homey.app/tools/devices

  {
  if ( device.capabilitiesObj &&
  device.capabilitiesObj.onoff &&
  device.capabilitiesObj.onoff.value )
    {
    // just to compare and check if there was no typo
    console.log("- Device:", device.name + " (device.class: " + device.class + ")");
    currentText = "";
    // Enter lights and sockets names, device.name == "Exact light/socket name"
    // currenText = "Sensible light/socket name"
    if ( device.name == "Eettafel lamp" ) currentText = "Eettafel lamp";
    if ( device.name == "Spots OSD achter" ) currentText = "Spots OSD achter";
    if ( device.name == "Gang beneden" ) currentText = "Gang beneden";
    if ( device.name == "Keuken lamp" ) currentText = "Keuken lamp";
    ///if ( device.name == "Spotjes keukenblad" ) currentText = "Staande Lamp";
    if ( device.name == "Spotjes keukenblad" ) currentText = "Spotjes keukenblad";
    if ( device.name == "Lamp Wc Beneden" ) currentText = "Lamp Wc Beneden";
    if ( device.name == "Spotjes voor" ) currentText = "Spotjes voor";
    if ( device.name == "Spotjes OSD voor" ) currentText = "Spotjes OSD voor";
    if ( device.name == "Spotjes badkamer" ) currentText = "Spotjes badkamer";
    if ( device.name == "Lamp gang boven" ) currentText = "Lamp gang boven";
    if ( device.name == "Slaapkamer inloop" ) currentText = "Slaapkamer inloop";
    if ( device.name == "Slaapkamer spotjes" ) currentText = "Slaapkamer spotjes";
    ///if ( device.name == "Lamp trapgat" ) currentText = "MuziekSet Power";
    if ( device.name == "Lamp trapgat" ) currentText = "Lamp trapgat";
    if ( device.name == "Lamp wc boven" ) currentText = "Lamp wc boven";
    if ( device.name == "Lamp deuren voor buiten" ) currentText = "Lamp deuren voor buiten";

      if(currentText != ""){
      lightsON = true;
      if(lightsText=="")
      lightsText = currentText;
      else
      lightsText = lightsText + "\n" + currentText;
      }
    }
  }
});

if ( lightsON == true )
lightsText = "De volgende lampen of stekkers staan nog AAN:\n" + lightsText + "\n";
/// ENglish:
// lightsText = "The following lights or sockets are still ON: " + lightsText;
else
// comment this out if you don't want a msg when all's fine:
lightsText = "Alle lampen en stekkers zijn uit";
/// ENglish:
// lightsText = "All lights and sockets are off";

// just to compare and check
console.log("\nOutput:\n", lightsText);

// Create / update HomeyScript variabele
await tag("lights_plugsText", lightsText);

return (true);

Goedemorgen,

Wanneer ik nu lampen aan heb staan krijg ik de volgende output.

  • Device: Eettafel Lamp (device.class: light)

  • Device: Gang Beneden (device.class: light)

Output: Alle lampen en stekkers zijn uit

——————————————————— :white_check_mark: Script Success

:leftwards_arrow_with_hook: Returned: true

Hij ziet dus wel dat er 2 lampen aan staan.
Maar de Output blijft dat alles uit staat :face_with_raised_eyebrow:
Ik heb zelf niet kunnen vinden waar het fout lijkt te gaan

Owww ik zie het nu!
Ik denk dat dit het probleem is:
Die twee lampen staan niet in je lijst met devices:

L is niet gelijk aan l
B is niet gelijk aan b

3 Likes

Ahhhh bedankt!

Ik zie inderdaad dat bij het aanmaken van lamp namen Homey steeds begint met hoofdletters voor nieuwe woorden.

Nu dat ik de hoofdletters gelijk heb gaat hij goed! :smiley:

Enorm bedankt voor je hulp.

2 Likes

Bedankt! ik had hem inderdaad ook toegevoegd onder anders.

Weet jij toevallig ook of er een zelfde soort script is om een lijst met lampen op een bepaald dimniveau te zetten?
Dan hoef ik niet steeds alle lampen los toe te voegen in flows maar kan ik een paar scripts maken met bepaalde dim niveau.

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

NOOB vraagje…

Heb de App Homey Script geïnstalleerd op mijn Homey Pro. Waar en hoe maak ik dan vervolgens een script aan? In jouw geval het script met de naam ‘DimAlightGradient’.

1 Like

After installation, visit https://my.homey.app/script on your Mac or PC to start scripting.

2 Likes

Dank!

1 Like

Kan iemand mee kijken ik krijg dit script niet goed ?
In de flow krijg ik dat Er nog lampen aan staan en dan gelijk daar achter de lampen en stekkers zijn uit ?

// Which light is still on?

let devices = await Homey.devices.getDevices();
let lightsText = "";
let currentText = "";
let logText = "";
let lightsON = false;
let plugsON = false;
_.some(devices, device =>
{
if ( device.class == 'light' ||  device.virtualClass == 'light' || device.class == 'socket' )

  {
  if ( device.capabilitiesObj &&
  device.capabilitiesObj.onoff &&
  device.capabilitiesObj.onoff.value
  )
    {
    // just to compare and check if there was no typo
    console.log("- Device:", device.name + " (device.class: " + device.class + ")");
    currentText = "";

// USER INPUT
    // Enter lights and sockets names, device.name == "Exact light/socket name"
    // currenText = "Sensible light/socket name"
    if ( device.name == "💡keuken spot Li" ) currentText = "💡keuken spot Li";
    if ( device.name == "💡keuken spot Re" ) currentText = "💡keuken spot Re";
    if ( device.name == "💡keuken spot Mid" ) currentText = "💡keuken spot Mid";
    if ( device.name == "💡Woonkamer bulb" ) currentText = "💡Woonkamer bulb";
    if ( device.name == "💡Hobby S1" ) currentText = "💡Hobby S1";
    if ( device.name == "💡Hobby S2" ) currentText = "💡Hobby S2";
    if ( device.name == "💡Hobby S3" ) currentText = "💡Hobby S3";
    if ( device.name == "💡eetkamer vin Re" ) currentText = "💡eetkamer vin Re";
    if ( device.name == "💡eetkamer vin Li" ) currentText = "💡eetkamer vin Li";
    if ( device.name == "💡Slaapkamer S1" ) currentText = "💡Slaapkamer S1";
    if ( device.name == "💡Slaapkamer S2" ) currentText = "💡Slaapkamer S2";
    if ( device.name == "💡Hal lamp Boven" ) currentText = "💡Hal lamp Boven";
    if ( device.name == "💡WC" ) currentText = "💡WC";
    if ( device.name == "💡Hal beneden" ) currentText = "💡Hal beneden";
    if ( device.name == "💡Douche" ) currentText = "💡Douche";
    if ( device.name == "💡Vensterbank" ) currentText = "💡Vensterbank";
    if ( device.name == "🎄 Trap < Groep >" ) currentText = "🎄 Trap < Groep >";    
    if ( device.name == "💡 Vensterbank Gr" ) currentText = "💡 Vensterbank Gr";
    if ( device.name == "🛁Wasmachine" ) currentText = "🛁Wasmachine";
    if ( device.name == "⚡Pc Stekkerdoos" ) currentText = "⚡Pc Stekkerdoos";
    if ( device.name == "⚡Tv Stekkerdoos" ) currentText = "⚡Tv Stekkerdoos";
    if ( device.name == "📻Chromecast" ) currentText = "📻Chromecast";
    if ( device.name == "🎄B Kerst" ) currentText = "🎄B Kerst";
    if ( device.name == "🚰Waterkoker" ) currentText = "🚰Waterkoker";
    
   // End of user input

      if(currentText != ""){
      lightsON = true;
      plugsON = true;
      if(lightsText=="")
      lightsText = currentText;
      else
      lightsText = lightsText + ", " + currentText;
      }
    }
  }
});

if ( lightsON == true || plugsON == true )
lightsText = "De volgende lampen of stekkers staan nog AAN: " + lightsText;
/// ENglish: 
// lightsText = "The following lights or sockets are still ON: " + lightsText;
else
// comment this out if you don't want a msg when all's fine:
lightsText = "Alle lampen en stekkers zijn uit";
/// ENglish: 
// lightsText = "All lights or sockets are off";

// just to compare and check
console.log("Output: ", lightsText);

// Create / update HomeyScript variabele
await tag("lights_plugsText", lightsText);

return (true);

Flow:

Ah I created something similar with an Advanced Flow :slight_smile:

Edit: which does not yet work completely because I was too sloppy with copy / pasting cards :joy:

2 Likes

Dan heb je naam van 1 of meer apparaten niet exact ingevuld:

Wat meldt het script als je het in de console start?

Die test meld gewoon succes en daar staat nou dat de douche lamp aan is.
Werkt dit niet met stekker blokken van Tuya ? Werkt het alleen met lampen ?
Morgen weer kijken in script hoe kan je dit op android bekijken ?