[QUESTION] Making a set of flows that trigger other flows quicker?

not running a loop would probably be faster, you need to call individual devices by their device ID.
The easiest way to get that would probably be this

let devices = await Homey.devices.getDevices();

   _.forEach(devices, device => {

     if (1==1){

           

         console.log(device.id + ", " +device.name + ", " + device.zoneName +", "+ device.class);

         } 

});

after that you can use await Homey.devices.GetDevice({id: "id here"})
edit: I guess you can use name too, I personally have a ton of lams called “lamp” :smiley:
get all conditionals, asign them to variables.

create your if and if else loops in this format

if(LuxSensorLiving < 10 && LuxSensorBathroom <10 && TimeVariable = 'Night'){
} else if(){} else if(){}....

Thanks Nick!
What I want to do is make my lights in kitchen turn on instantly (enough) following the criteria in the flow chart from the first post.
We found out that using flows is bound to use a few seconds, so next thing I want to do is learn to code over night :smiling_face_with_tear:

How do you define multiple arguments in a flow for HomeyScript to run? I’ve got only an option for one argument in THEN card.

I updated my answer to better help you on the way :wink:

1 Like

my guess is to comma seperate them :wink:

Tnx! :slight_smile:
I’ll look into it tomorrow!


EDIT (tommorow is now):
Thanks Nick. I was obviously long overdue for some sleep to get what I was doing wrong.

But this morning - Eureka time! The missing link (writing the whole process for reference for the others uneduceted like myself):

By using

const Devs = await Homey.devices.getDevices();
console.log(Devs)

Find the capabilities in the log:

capabilities: [
  'alarm_motion',
  'measure_temperature',
  'measure_luminance',
  'measure_battery',
  'alarm_battery'

And then, put the wanted capability to be read and stored in variable LuxSensorLiving (“the missing link” [Source]):

const LuxSensorLiving = device.makeCapabilityInstance('measure_luminance');
console.log(LuxSensorLiving.value);

Okay. Now I think I have what I need to get all the needed criteria from the sensors, and I think I can manage if-statements on my own.

The next thing will be

  • Finding a logic/variable through HomeyScript, probably some getVariables thingy.
  • Finding how to activate hue scenes from the script.

I’ll keep the track of it in the post. Now, if you’ll excuse me, I need to go to work with what I’m getting payed for to do. Strike the last one.

let variables = await Homey.logic.getVariables();

    _.forEach(variables, variable => {

      console.log(Object.values(variable))

    });

use this to discover the ID’s of your variables, call them the same way as devices but with var sensorliving = await Homey.logic.getVariable({id:""})

then call the value with sensorliving.value

Now we’re talking!

Console

lux_sensor_kitchen: 49
lux_sensor_living: 34.83
dim_light_kitchen: 1
onoff_light_kitchen: false
state_shades_kitchen: up
onoff_guest_mode: false
onoff_sleep_mode: false
———————————————————
✅ Script Success
↩️ Returned: undefined

Thank you very much Nick!

Two general questions:
What’s the best practice for refering to devices - using IDs or names? I guess the latter can change, thus making maintenance a pain in the… and I could not get it to work either, but it would be easier…

Is there a way to refer to IDs quickly or do you always have to find it, copy it, and then use it?
And should IDs be hidden f.ex. when you take prnt-scrn to ask for help?

Okay, that was three. I’ll stop now. I’ll show my self out.

I’m replying to the original post questions.
How to set dim and temp depending time of day and placement of sun.

I have 1 flow to do it all. It depends on 2 variables. Dim level and temperature. These variables are set based on time of day and placement of sun. There are also flows that update the lights in real time during the transition, which takes just over an hour.

Here’s the flow to start lights during movement.

When: Zone active.
And:
House disarmed
Sun is Down
A virtual switch
Or:
Sun is up
It’s quite dark in the kitchen
House is disarmed
Then:
Set light to dim level
Set light to temp
Set a logic value for further logics.

I hope this helps!

As a side note. I have Philips Hue lights with the Bridge. Calling a Hue Scene is the fastest way to simlultaniously turn on many light at the exact same time with next to no latency. Calling them from Homey one by one or using the group app introduces delays. But you can’t both use scenes and set dim and temp at the same time.

Great idea, Aste!

I was thinking of something along the same lines, but I was worried about loading Homey too much if I was to have variables ToD Dim and ToD Temp updated at all times.

How many flows are controlling their value? And what’s triggering them?

I wanted to dim light depending on light level in the house. Ie. if someone is up to drink some water late at night, that they don’t get welder’s flash burn :smile:

Glad it spawned some interest :slight_smile:

So this is just the flow that turn on or increase dim (brightness) when someone enters the kitchen. In my case, it’s a hue light strip over the kitchen counter.

This is the base.
When sun is down and someone is home and awake, ambient lighting is on.
When someone come into the kitchen, it transition to “movement” dim level. Which is brighter.
After zone inactive for x time, it transitions back to ambient dim level.

Then I recently implemented the ToD (Time of Day) for both dim level and temperature. The idea was based upon circadian lighting. But I chose to only transition during sun rise and sun set.

This is the evening flow for movement dim level


Decrease value by 0.01 every minute and disable itself when reaching 0.6.

I stop at dim level 0.6 during this transition. Later during the night I lower dim level a bit more to prepare for bed time. The idea is that I want more light when it’s light outside and less light the darker it gets outside to not blind everyone. Just like your phone screen.

I use Sun events Golden hour as a trigger.

This exact same logic is replicated for temperature level (but it is reversed). In the morning, I decrease the value by 0.01 and trigger by Sun events Dawn.

Now you have ambient, movement and the dim and temp values. But what if we could transition the temperature live when lights are on, not just off a movement trigger? We can :slight_smile:

During the transition time when variables change I run this flow that transitions not only the counter top lights, but a few more lights under the cabinets and in the windows.

Making sure the lights are on in the first place.
Someone is home
Logic check not important here
General lighting logic virtual switch is on
Then set temp level on all the lights in the kitchen (using the group app) after 5 seconds to have the latest temp level variable value.

This flow is also disabled when the variable value transition flow is disabled.

I’ve then replicated this into all the rooms so all lighting in the house have the temperature transitioning from cold white to warm white during sun set and in reverse during rise. It’s kind of magic and WAF 10 :smiley:

I hope this will help move you forward and achieve your goals.

Thank you for the detailed explanation, Aste!

I like your ideas. I even have similar myself. It’s great to see what other people do, and how they automate in their homes.

I see you use every minute as the trigger. Do you find it putting an extensive load on Homey or do you not notice any performance issues? Because this is what I saw as the solution to this problem through approach similar to yours, and I didn’t dare to have flows running every minute.

With a risk of getting this thread even more off-topic as I have by now, here is my approach to changing lights from cold to warm. 45 minutes before the sunset, a flow starts this one, which then goes through all lights in the room, as shown in the attached flow. The point is in using Duration to define the time for the transition rather than iterating it, by triggering the flow every minute

But I like your idea of not turning off light, and rather dimming them to an ambient level.

Glad you liked it.

I try to be mindful of not hogging then flow engine to much. But running a few flows every minute to do these tasks don’t make a notable dent in performance. But I do have all the flows disabled during rest of the day and only enable them when they need to run.

I’ve also tried the during option, but I like the idea of being able to stop things from happening whenever any situation change. Like leaving home or coming home. The variables always update, but lights are only triggered when someone is home. And the lights then join the fun regardless of where in the transition phase we are.

I also use the temperature value for when manually triggering lights like the ceiling lights from wall switches

To circle back to your original question. The way of doing it with variables removes the lag introduced by using flows in serial and give even more flexibility.

1 Like

Nois!

I agree with your reasoning. I would probably end there as well if I gave it enough thought. :slight_smile: It is a good way to have an instant response from the lights.

I am going to do something similar to you, to check how it works out. Right now, I’m over my head with scripting the set from the original post in HomeyScript.

I liked this one. You have no need for the Hue app at all. I use predefined scenes for dim and temp.

And this one. I think it works really well, especially in situations like this.

Hey guys, just a quick update.

I wasn’t able to finish my HomeyScript to check if that would be any quicker, because I couldn’t get the part of turning on a hue scene to work, and eventually gave up…

However, I have managed to get the set from the original post quicker (0.01-0.05s)

Soultion
By cheating. Or rather, I’ve implemented the idea of enabling/disabling the relevant flows, depending on a common criteria (in my case, night- or daytime). In other words, I restructured the original flow set, from one large set, to 2 smaller sets of flows - one of which is active during the day-, and the other during the nighttime.

This way the original set gets split in three (one flow for night, and two for daytime). This eliminates running through multiple flows, and the trigger is therefore almost instantaneous. Any delay experienced now is due to time Homey uses to register Hue sensor.

There are few new help-flows to control enabling and disabling of the relevant flows. They serve the purpose of all AND criterias from the original flow set.
In this example, these only run (A) when lights turn off, deciding which flow-set gets enabled, and (B) at transition from daytime to nightime. This way they do not put any extra load on Homey, which was the intend all along. If that is not a concern, this method from a post above can also be used.

Conclusion
If execution speed of a set of flows with many criterias is the main concern, you might want to consider enabling/disabling flows instead of having a large set of flows with respective AND criterias.

HOOP has not been tested (yet)
HomeyScript has not been tested (yet)

Every second as trigger could cause issues, I don’t think every minute as trigger does.

Hint: to prevent all kinds of flows being triggered at once at whole minutes or hours, I vary the every … trigger with several seconds
F.i. every 57s, every 307s, every 59min and so on

That is a good way to bypass all of the flows running at the same time.

What kind of flows do you have that need to be updated that frequently?

That would probably be for syncing various virtual sensors

And for f.i. humidity comparison, I save the shower humidity sensor value every ~30s.
By comparing the 2 values, and the value raises quickly, like with 4% in 30s, someone is showering.

If…
Every 29s
Then…
Set Numvar [SavedHumidity] to [humidity]

If…
Humidity has changed
And…
Is humidity higher than [SavedHumidity] + 4%
Then…
someone is showering

I use a similar setup to compare power usage and determine if f.i. my oven is ready.
F.i. if the current power has dropped by 2200W in ~30s, then my oven must be hot

Nice! You always leave me wondering about something. :smile:

First, do you feel like all those flows triggered every x minutes clog Homey?

And now, here we go off topic again :smile:

What sensor do you use for humidity?

And what automations do you have for the showering mode?

That was a good idea with humidity sensor. I was thinking of buying aqara water leak sensor, to prevent bathrom lights from turning off when someone is showering. It’s an old bath, so I dont have a fan inside.

:sweat_smile::hugs:

I don’t know how to find the flows with that trigger :grimacing: But it can’t be thát many.
I’ve all kinds of status and check flows, but they run like every 12 or 24hrs.

Aqara temperature & humidity sensor. But a flood sensor can do the job as well I guess.
I read sonewhere in this forum an other approach.
They made a comparison between the shower humidity and the livingroom humidity.
If…
Hum shower changes
And…
Logic [humidity] is greater than [humidity] (of livingroom) + 5

I also use it for the light atm, so it stays on for a longer period than with the motion sensor.
I came to find out I use the motion sensor to start a comparison :sweat_smile: and not “Every…”

  • Motion - save humidity value

  • Humidity check - turn light on

  • light off

  • Motion + light when not showering

  • Light off when not showering

This one should definitely be in an own thread. :smiley: You could make it, there are probably other people who would appreciate it as well.

How is polling time on this one - does it take long for sensor to report humidity value change to Homey?

Yeah, I reckoned you used some other flow triggers. I am no expert, but it just feels that using every x minutes, or similar, should be avoided if you can use other, more precise triggers. But, my problem with that is definitely not based on knowledge, and I might be wrong here.

So, 260 seconds is the time that is enough for a bathroom visit! :smiley:

And finally, it seems to me that the flows B2-4 and B3-4 possibly do the same thing, so you might get away by using just one.