Het is handiger als je er een screenshotje bij doet
Succes betekend enkel dat het script foutloos gelopen heeft.
Als de douche lamp werkelijk aan is, dan gaat het toch goed?
Als er staat - Device: Douche Lamp (device.class: light) dan betekent het dat deze lamp niet goed in de lijst met devices staat.
Ik zie trouwens dat je niet het laatste script gebruikt, dat is het probleem misschien.
Gebruik dit script ajb: Post #18
Ik heb de eerdere versie nu aangepast.
Ik heb nu ook een script om langzaam naar een kleinere waarde of 0 te dimmen
Ik heb het script even DimSlowX-0 genoemd.
Flow:
Code:
/*
* Dim-- a light in steps to low or zero level (transition)
*/
// Use flowcard "Run Homeyscript DimSlowX-0 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 = "Spot Keuken L"
// USER INPUT
// enter an end dim level, 0 is turning the light off
var myDimlevelEnd = 0.01; /* range: 0.00 - 1 */
// Enter a delay time (for the next dim level)
var waitForDimlevel = 250; /* time in ms */
// Enter the value to decrease 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 {
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') {
// Get the current dim level of the device
var currentDimlvl = '';
currentDimlvl = device.capabilitiesObj.dim.value;
// Just to inform you while testing
await log(`\nCurrent Dim level: ${currentDimlvl} \nWait for ${waitForDimlevel}ms between steps of ${myDimlevelStep} `)
// this works, but myDimlevelStep has to be rounded
for (let step = currentDimlvl; step >= myDimlevelEnd; step -= Number(myDimlevelStep)) {
await wait(waitForDimlevel);
step = Math.round((step)*100)/100; // round to 0.00
log(`\nDimming ${device.name} to ${step}`)
// decreasing 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 zero
if (step == 0) {
break;
}
}
}
}
}
}
return(true);
Graag gedaan. Ja, het zou Tuya sockets gewoon moeten zien.
Als je een lamp er aan hebt hangen, kun je dat aangeven in de app. Dan wordt het een virtualClass lamp en zou het script het zeker mee moeten nemen.
(Screenshot is ook een Tuya socket trouwens (wifi uitvoering)):
Wat zegt de developer pagina als je zoekt op die Tuya socket?
Staat er ook Class: socket (Virtual Light)?
Zoals ik in het bericht boven de jouwe al aangaf, kun je bij advanced settings van de socket aangeven wat er is ingeplugd. Selecteer dan “lamp”. Daarna is het een virtuele lamp geworden, en die wordt zeker weten meegenomen door het script (device.virtualClass).
Om sockets mee te nemen wijzig je de volgende regel:
// 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 == "💡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";
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);
Voor lampen werkt het goed allen voor de stekkerdozen niet hij ziet ze niet. Terwijl er in developer page daar staat Class socket (Virtual: light).
Ik heb hem ook aangepast als Lamp maar hij blijft hem niet zien.
Kan het zo niet zeggen.
Ik heb lamp Staande lamp in een tuya socket zitten en deze wordt gedetecteerd, MuziekSet Power is een socket zonder virtueel apparaat.
Output:
De volgende lampen of stekkers staan nog AAN:
Spot Keuken L
Spot Keuken M
MuziekSet Power
Staande Lamp
———————————————————
✅ Script Success
↩️ Returned: true
Staat er niets boven de output in het output scherm?
Bij mij staan daar lampen en sockets die ik niet monitor / wil monitoren, je ziet ook device.class: socket
- Device: FlowChecker OnOff (device.class: light)
- Device: Spot Keuken L (device.class: light)
- Device: Spot Keuken M (device.class: light)
- Device: z ! MuziekSet Power ! (device.class: socket)
- Device: Lamp Staande Lamp (device.class: socket)
- Device: 5.Daluren J/N (device.class: light)
- Device: 1.Lampen Woonkamer (device.class: light)
- Device: A - test (device.class: socket)
Output:
De volgende lampen of stekkers staan nog AAN:
Spot Keuken L
Spot Keuken M
MuziekSet Power
Staande Lamp
———————————————————
✅ Script Success
↩️ Returned: true
Het leek mij ook interessant om dit met Homeyscript te proberen, maar dat gaat niet helemaal goed. Ik heb de lijst met te matchen namen aangemaakt (copy/paste vanuit de device output). Alle lampen staan aan. Maar hij matcht er maar een paar uit de lijst.
Hieronder de code en de output. Iemand een idee wat er mis gaat?
// 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 = "";
//currentText = device.name;
// Enter lights and sockets names, device.name == "Exact light/socket name"
// currenText = "Sensible light/socket name"
if ( device.name == "Kleine kast" ) currentText = "Kleine kast";
if ( device.name == "Keuken 1" ) currentText = "Keuken 1";
if ( device.name == "Keuken 2" ) currentText = "Keuken 2";
if ( device.name == "Eettafel" ) currentText = "Eettafel";
if ( device.name == "Plafondlamp tuindeuren" ) currentText = "Plafondlamp tuindeuren";
if ( device.name == "Plafondlamp Zithoek" ) currentText = "Plafondlamp Zithoek";
if ( device.name == "Erker eettafel" ) currentText = "Erker eettafel";
if ( device.name == "Wandlamp eetkamer" ) currentText = "Wandlamp eetkamer";
if ( device.name == "Wandlamp Zithoek" ) currentText = "Wandlamp Zithoek";
if ( device.name == "Wandlamp TV" ) currentText = "Wandlamp TV";
if ( device.name == "Hal" ) currentText = "Hal";
if ( device.name == "Wandlamp overloop" ) currentText = "Wandlamp overloop";
if ( device.name == "Erker voorzijde" ) currentText = "Erker voorzijde";
if ( device.name == "Lampen achter bank" ) currentText = "Lampen achter bank";
if ( device.name == "Grote kast" ) currentText = "Grote kast";
if ( device.name == "Wandlamp trap" ) currentText = "Wandlamp trap";
if(currentText != ""){
console.log('MATCH:', 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);
Playing with this script makes me very excited about Homeyscript!
In order to understand what the script (and myself) is actually doing I changed a few parts that made it better to understand for me. I do not know if it is all how it should be done code-wise, but for me it works and I am able to understand it.
Thanks again Peter for the nice example!
// Which light/socket is still on?
// List of devices to check
// name is the device name in Homey (case sensitive)
// displayname is the name as you want it to appear in the list
let lightsToCheck = [
{'name' : 'Kleine kast', 'displayName' : 'Kleine kast'},
{'name' : 'Grote kast', 'displayName' : 'Grote kast'},
{'name' : 'Keuken 1', 'displayName' : 'Keuken rondom eiland'},
{'name' : 'Keuken 2', 'displayName' : 'Keuken boven eiland'},
{'name' : 'Eettafel', 'displayName' : 'Boven eettafel'},
{'name' : 'Plafondlamp tuindeuren', 'displayName' : 'Plafondlamp bij tuindeuren'},
{'name' : 'Plafondlamp Zithoek', 'displayName' : 'Plafondlamp in Zithoek'},
{'name' : 'Erker eettafel', 'displayName' : 'Spots erker bij eettafel'},
{'name' : 'Wandlamp eetkamer', 'displayName' : 'Wandlampen in eetkamer'},
{'name' : 'Wandlamp Zithoek', 'displayName' : 'Wandlampen in Zithoek'},
{'name' : 'Wandlamp TV', 'displayName' : 'Wandlamp bij TV'},
{'name' : 'Hal', 'displayName' : 'Hal'},
{'name' : 'Wandlamp overloop', 'displayName' : 'Wandlamp op overloop'},
{'name' : 'Erker voorzijde', 'displayName' : 'Spots erker voorzijde'},
{'name' : 'Lampen achter bank', 'displayName' : 'Lampen achter bank'},
{'name' : 'Wandlamp trap', 'displayName' : 'Wandlamp trap'}
]
const devices = await Homey.devices.getDevices();
let lightsText = "";
_.forEach(devices, device =>
{
// check if device is a light or virtual light (in a socket)
// check on socket only needed when virtualClass=='light' does not work for you
if ( device.class == 'light' || device.virtualClass == 'light' || device.class == 'socket' )
{
// if you need a list of all devices that match the IS LIGHT criteria above, uncomment the next line
console.log("- Device:", device.name + " (device.class: " + device.class + ")");
// check if device is on
if ( device.capabilitiesObj &&
device.capabilitiesObj.onoff &&
device.capabilitiesObj.onoff.value )
{
// light is ON so include it to the output
if (currentLight = lightsToCheck.find(item => item.name == device.name)) {
lightsText = lightsText + "\n" + currentLight.displayName;
}
}
}
});
if ( lightsText != "" )
lightsText = "De volgende binnenlampen 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 binnenlampen 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);```
@Peter_Kawa
Mooi nieuw script geplakt met alleen de Tuya stekkers.
Dit is de output:
- Device: 🎄Trap color (device.class: light)
- Device: 🎄 Trap wit (device.class: light)
- Device: 🎄 Trap < Groep > (device.class: light)
Output: De volgende lampen of stekkers staan nog AAN: 🎄Trap color
——————————————————— ✅ Script Success
↩️ Returned: true
Het klopt dat die Trap aan staat. Hij ziet helaas die tuya sockets niet. Ik zou niet weten waarom niet ?
Is dit script niet aanpasbaar naar ook kijken naar Devices in het algemeen ?
Script werkt goed voor Lampen en schakelaars als lamp. Krijg het alleen niet voor elkaar om die Tuya stekkerdozen er tussen te knutselen. Misschien die via de flow laten checken. Het is mooi dat je nou AF een hoop kan doen
Ik ben een homeyscript-noob, maar om te oefenen wilde ik kijken of of ik ipv van met een lijst van devices die gecheckt worden met een lijst van devices die niet gecheckt moeten worden. Verder heb ik de in de output de devices gesorteerd op device type.
misschien heeft iemand er iets aan!
// Which device is still on?
let devices = await Homey.devices.getDevices();
let lightsText = "";
let currentText = "";
let logText = "";
let lightsON = false;
// array aangemaakt om straks te sorteren
let arrayofdevices = "";
_.some(devices, device =>
// paar extra device types toegevoegd
{
if ( device.class == 'light' ||
device.virtualClass == 'light' ||
device.class == 'socket' ||
device.class == 'fan' ||
device.class == 'speaker' ||
device.class == 'tv' )
// 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 + ")");
// devices to ignore
if ( device.name != 'Badkamer Licht Knop Buiten (Always On)'
&& device.name != 'Quooker'
&& device.name != 'Balkon'
&& device.name != 'Whisper Flex Ultimate' ){
currentText = (device.name);
if(currentText != ""){
lightsON = true;
if(lightsText=="")
// wilde device type voor de device naam hebben
lightsText = " [" + device.class + "] - " + currentText;
else
lightsText = lightsText + "\n" + " [" + device.class + "] - " + currentText;
}
}
}
}
});
//wilde de devices sorteren naar type (en omdat type vooraan staat werkt dat dus)
arrayofdevices = lightsText.split("\n");
arrayofdevices.sort();
lightsText = arrayofdevices.join("\n");
if ( lightsON == true )
lightsText = "De volgende devices 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 devices 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);
Ik heb er nog een script achteraan gemaakt wat de devices die aan staan ook uitzet. Omdat ik dit niet altijd wil, laat ik homey een notification sturen naar mij met de vraag of devices moeten worden uitgezet. Als ik die bevestig, dan pas gaan de devices uit.