The best way to handle multiple Logic criteria and multiple lightbulb settings in advanced flow?

I’m setting up some flows and have a couple of questions about multiple “logic” conditions and multiple “then” actions.

Using this flow as an example, I have an “Outdoor Lights” variable that sets to “Morning” or “Evening” if the lights should come on, and “Off” after those times. I also have a “Season” variable that’s set for “Halloween” or “Christmas”, and “Default” the rest of the year.

Then, I have resulting actions where Morning or Evening+Default are Temp 50% and Dim 50%. If it’s Evening and either Halloween or Christmas, half the lights change to one colour and the other half change to another, and all are Dim 100%.

While wanting to make sure I’m creating flows as efficiently as I can, I had some questions/doubts about what I’ve set up. Based on this flow screenshot, should I be handling anything differently?

  1. For Season, it’s checking for Default, then Halloween, then Christmas. I figured it would be better to check one possibility at a time, instead of firing them all at once, but maybe that’s not necessary?

  2. For the bulb settings, to change Dim as well as either Color/Temp, I also have those happening one after the other, but maybe they should fire all at once? The bulbs are in the Kasa LAN app, then a Group. I used to have them set up in Home Assistant Community, which was a complicated setup, but one feature I miss is that it had the option to set Dim and Color/Temp in one Then. So now, I’m not sure how to best handle the multiple changes.

What you mean with efficiently? As less CPU time? My suggestion is that until your are absolutely sure there is a technical or performance problem, the main goal should be to create understandable flows.

And when ever you are optimizing flows, make sure you are doing some measurements in order to know how well your optimizations are. Otherwise it is useless and a waste of time.

1 Like

You could consider using HomeyScript.

// Name = SocketSwitch
// RuuRd van der Noord - 2025-01-07
//
const dev_socket = [
    {name: `OverloopL`, id:`9b8383be-3db5-4637-afc0-efe6ccf20767`, class:`socket`, zone:`Overloop`},
    {name: `BadLamp`, id:`017fa664-07a2-4046-882b-afcba571c7f6`, class:`socket`, zone:`Badkamer`},
    // Add other devices here...
];

async function switchDevice(deviceName, state) {
    const device = await Homey.devices.getDevice({ id: deviceName.id });
    if (device) {
        await device.setCapabilityValue('onoff', state);
        return true;
    }
    return false;
}

async function processCommands(commands) {
    const results = [];
    const commandList = commands.split(';');
    
    for (const command of commandList) {
        const [name, state] = command.split('=');
        const device = dev_socket.find(d => d.name === name);
        if (device) {
            const result = await switchDevice(device, state === 'on');
            results.push({ name, state, result });
        } else {
            results.push({ name, state, result: 'Device not found' });
        }
    }
    return results;
}

// Example usage
const args = 'BadLamp=on;OverloopL=on'; // Input commands
processCommands(args).then(results => {
    results.forEach(res => {
        console.log(`Device: ${res.name}, State: ${res.state}, Result: ${res.result}`);
    });
});

Scripts should also be understandable and readable like what [ Rmb wrote above.

1 Like