Best way to call a bunch of services at once?

For my lock up script I have it just turning everything off, some groups, some individual entities. I’ve noticed delays in this, so the last item on the list sometimes takes 10 seconds to actually shut off. Is there a better way to do this so it’s parallel?

One easy option would be to put all of your “actions” into a HASS scene, then call the scene/turn_on service. I do that for a “goodnight routine” and my 6 actions all happen quickly.

If you want to stick to an AppDaemon-only solution, you’ll want to looking into threading.

You can use multiple run_ins for each routine having the delay as 0.

This way AD will schedule a callback for each across several threads, and they could get executed quicker.

But fact is HA will only execute 1 at a time anyway, as they will be in a queue.

So at the end there might not be any point.

Regards

The reason I’m asking is it takes 10s to actually shut off the lights after executing the script which seems odd. Not sure what’s causing it, AppDaemon, HA or zwave.

This is what happens when it’s triggered now

    self.turn_off('group.upstairs_lights')
    self.turn_off('group.downstairs_lights')
    self.turn_off("light.theater")
    self.turn_off("switch.appliance_switch")

    self.call_service("remote/turn_off", entity_id="remote.living_room")
    self.call_service("media_player/media_stop", entity_id="media_player.dining_room")
    self.call_service("media_player/media_stop", entity_id="media_player.kitchen")

try creating an automation in HA that does all that, if its faster you know its the connection between AD and HA if not you know its HA or zwave.

do you have AD connected to HA locally without ssl or through an outside dns (duckdns)
i ask because a lot of people have duckdns and letsencrypt installed in HA itself.
that causes that all connections from AD to HA go over the internet, with all kind of possible delays.

Direct, they are on the same machine in dockers.

Wonder if I flooding zwave too since up/downstairs lights contain like 20 entities.

try to turn off all lights individual instead of as group and see if that helps.

For the lights, you can also use light.turn_off without specifying an entity_id. It will then turn off all lights.

That’s definitely it - you are just hitting zwaves limits. Remember zwave is slow :wink: