Scripts Taking Long Time To Execute

I am having some issues with a few of my scripts that take a really long time to execute. I am not sure if it is because of the door locks (as they seem to take a while to respond to commands) or if its the call to turn off groups that have quite a few entities in them.

I’m running the latest HassIO release on ESXi, with Aotec Z-stick, GE Jasco Zwave switches (like 30 of them, all but 1 are Plus) and 2 Schlage Zwave locks.

When I’m laying in bed and I execute this good night script (via Alexa) it runs through the steps very slowly and sometimes things happen out of order. It will take a few seconds (at least usually) for the door locks to trigger, then I’ll lay there for at least 10-15 seconds for the lights to turn out and sometimes another 10 plus seconds for the fans to turn on. Also, sometimes it happens out of order. Like the fans will turn on before the lights turn off, or the bedroom lights will turn off before the hallway light. For the most part we are really good at turning all the other lights off in the house before we lay down, so it really shouldn’t even have to turn off any of those.

goodnight:
  alias: Goodnight
  sequence:
    - alias: Lock Doors
      service: lock.lock
      data:
        entity_id:
          - lock.back_door
          - lock.front_door
    - delay:
        seconds: 2 
    - alias: Turn off lights besides bedroom
      service: script.turn_on
      data_template:
        entity_id: >
          {% if is_state('group.Goodnight_lights', 'on') %}
             script.goodnight_lights_off
          {% else %}
             script.no_delay
          {% endif %}
    - alias: Turn off bedroom lights
      service: homeassistant.turn_off
      data:
        entity_id:
          - light.master_dimmer
          - switch.master_light
    - delay:
        seconds: 2
    - alias: Turn on fans
      service: homeassistant.turn_on
      data_template:
        entity_id: >
          {% if states('sensor.bedroom_temperature') | float > 67 %}
             group.Master_Bedroom_Fans
          {% elif states('sensor.bedroom_temperature') | float > 63 %}
             switch.master_outlet
          {% else %}
             input_boolean.dummy
          {% endif %}

I don’t get any errors in my logs from this. I have another similar script that I use when I leave the house and a bunch of times I just stood by the door waiting for it to lock and the lights to turn off an I eventually just gave up and opened it on my phone and did everything manually.

Everything else on this setup runs really fast and smooth. Z-wave does take a bit t respond after a heal or system reboot, but after that everything responds almost instant, reboots are fast, automations normally happen within a second, (like if one light is turned off, to another one off), and the interface is snappy. It just seems, for the most part, these two scripts are painstakingly slow.

I am having nearly the same thing happen to me. I have a “good night” routine set up in Google Assistant, which triggers two simple scripts that lock my doors and turn off most of my light groups. It takes a minute or so to execute the script, whether I trigger it manually in HA or by voice via Google. Hoping somebody can provide a theory about why things are so incredibly slow.

Did you ever figure this out?

Yes and no.

I took the delays out of the script which helped a bit but doesn’t speed up the process of the zwave devices turning off. I had my zstick in the basement, in a closet that has concrete walls. Only a fee of my devices were 1 hop away and the rest were 2-3 hops. I got a usb over ethernet adapter and moved my zstick to a more central part of the house. This sped up the response of my most used devices bc it was more central and less hops.

When I run my good night script, if the doors are locked and most of the other lights are off besides my bedroom they react fairly fast. If other things are left on it takes longer. I think it has to do with the nature of how zwave works. From what I understand (correct me if I’m wrong), only one device can communicate at a time and when you send it a command it needs to respond with a result before the next command can be sent to the next device. For devices like door locks that take a bit to actuate this can cause a delay. If you have devices multiple hops away or at the limit of the wireless range it can cause delays.

Since I moved my zstick it’s been better but not perfect. I just ran out of time and ambition to keep chasing it. Other things in life are taking priority right now and not leaving me really any time to mess with home assistant much anymore.