This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
The Homey Community has been moved to https://community.athom.com.
This forum is now read-only for archive purposes.
Official HomeyScript
Comments
Okay, understood this and you are right, the example code says that Homey should fetch all devices and do something _.forEach.....
Well, now what to do if I just want to "talk" to a single device? What do I have to do, if I want Home to ask a single device an what to do if I want an single device to do something? Is there a possibility instead of "forEach"? I know there is a support site but I do not understand what to do.
Right now the example script looks like this:
- Homey get all devices
- for each device found Homey is doing something
- But skip each device that is not like "light"
Would this be a right way tor talk to a single device?:
And if this is the right way, why does this shut off all devices?
Regards
Andreas
You only have to run this once, just to get the id of your Leselampe.
In your final script, just use:
Your code gets much faster, because not all devices are retrieved, just the one you really need.
You can now do something like:
The innermost curly brackets { } form a function body that gets called by _.forEach() for every device. If that function returns false, _.forEach() stops, anything else and it will continue with the next device.
Search for "lodash" on the net for more details. There are many other powerful functions.
Have fun!
Thank you very much for your help, this is great for my start of learning.
now that a learned something new from @Lammy the next question comes up.
Has someone ever tried to trigger the app "MQTT Client" (from Menno van Grinsven)? I know the ID and I am able to start a script based on the things Lammy told me in the postings before but now...how to tell the app to do something?
Regards
Andreas
(Response on question from roel_hendr)
I've been playing around a little bit with this issue, and came to the following conclusion:
When you use a card from a specific group as the 'trigger' card, you can only use the variables which are bound to that group.
What this means:
The issue with not being able to read tags from other groups / namespaces, is only an issues in the 'trigger' (...when..) column.
var start = 0;
var end = 1;
var duration = 10000; // In milliseconds (divide by 1000 to get seconds).
var framerate = 2000; // In milliseconds (divide by 1000 to get seconds).
var toAdd = ( ( end - start ) * framerate ) / duration;
var interval = setInterval(function() {
var currentValue = parseFloat(valueElement.innerHTML);
if (currentValue >= end) {
clearInterval(interval);
return;
}
valueElement.innerHTML = (!isNaN(currentValue) == true ? currentValue + toAdd : toAdd);
}, framerate);