Automation turns lights on and then off

Hey folks, I’m seeing some very unexpected behavior with my Sunset automation. This has happened multiple times now and it’s leaving my wife feeling unsafe (so she is not happy with my Home Assistant setup).

This is what my automation looks like in YAML:

alias: Sunset
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: 0
condition: []
action:
  - service: cover.close_cover
    data: {}
    target:
      entity_id:
        - cover.kitchen_left_fireplace_blind
        - cover.kitchen_right_fireplace_blind
        - cover.bathroom_closet_blind
        - cover.bedroom_left_blind
        - cover.bedroom_right_blind
        - cover.home_theater_left_blind
        - cover.home_theater_right_blind
  - service: light.turn_on
    data: {}
    target:
      entity_id:
        - light.outside_front_light
        - light.outside_driveway_light
        - light.outside_gazebo_lights
        - light.outside_christmas_lights
        - light.hallway_entry_light
    enabled: true

But the last trace shows that the automation failed to turn on a couple of the lights:

And my logbook shows that it did turn on all the lights but then turned them off:

When I got home late in the evening, all the lights were off. :frowning: Any idea why this might be happening? It’s very unexpected and frustrating. It feels like I can’t even get a basic automation to work as expected in Home Assistant.

That automation looks fine. Do you have any other automations to turn these lights off later? Do the lights work when you toggle them in the dashboard?

Why are the lights disabled in the trace?

@Arh, I don’t have any other automations controlling these lights. Turning them on/off via my dashboards works just fine. That’s what I end up having to do every evening after the lights fail to turn on automatically and my wife yells at me. :expressionless:

@Stiltjack, that was just a disabled action that I had previously tried. I was originally using the lignt.turn_on service with the devices instead of the entities and later on switched it to using the entities instead (thinking that might somehow resolve the problem). However, no matter whether I configure the action with devices or entities, the same issue occurs.

I notice that in your log each set of lights appears to be turned on and off twice with different icons - presumably these are different entities with the same friendly name (looks like a switch and a light)? In any case, it suggests that there is more going on than is shown in your automation.

Do all of the following lights use the same communications protocol? For example, are they all zigbee or Wi-Fi or something else? Whichever protocol they use, can you confirm it’s reliable?

        - light.outside_front_light
        - light.outside_driveway_light
        - light.outside_gazebo_lights
        - light.outside_christmas_lights
        - light.hallway_entry_light

The reason why I ask is because the Log indicates they were all commanded to turn on at 8:54:52 but within 2-3 seconds they were all reported to be off. If Home Assistant sends an “on” command to a device and the device fails to promptly acknowledge the command (i.e. report that it’s now on) then Home Assistant sets the entity’s state back to off (it’s not your automation doing this, it’s the way Home Assistant handles unacknowledged commands). In other words, Home Assistant didn’t transmit an “off” command but simply set the entity back to off because the “on” command failed to be acknowledged.

Failure to acknowledge a command may be due to a communication problem, between Home Assistant and the physical device, at the moment the command was transmitted. That’s why I asked if the connection between Home Assistant and your lights is rock-solid reliable.

@123, the lights are all GE Enbrighten Z-Wave switches. My whole Z-Wave network has been rock solid since I downgraded to a 500 series controller. I have an automation that tells me if any devices are unavailable and haven’t seen any notifications about these or any other Z-Wave devices. Also, the lights always work as expected when turned on/off via scenes or the app. Is there any way for me to tell for if the devices failed to turn on due to a Z-Wave network issue?

What I’m finding particularly suspicious is that 4/5 lights turn on right away, then the last one turns on only after a couple of seconds and then all 5 lights immediately turn off. Any idea what could explain that kind of timing?

Probably poor network connection.

Like I said, my Z-Wave network has been rock solid since I downgraded to a 500 series controller and I’ve never seen any issue with commands not working when manually controlling lights via the app. Also, these lights are all in different parts of my house so the chance of all 5 being unreachable at the same time is very low. If you are insisting that this is a Z-Wave network issue, how can I confirm that? Also, what would be the mitigation? I had a similar automation running in SmartThings for years without fail. Are you saying that Home Assistant can’t reliably handle something as simple as keeping my outside lights on at night?

I don’t insist on anything. I don’t have z-wave and I use mostly zigbee. As I understand from your post you have an app for controlling lights. Meaning you are accessing it over some cloud and you integrated those lights in home assistant.
I had similar problem with tuya wifi switches. It works over app but it had problems in home assistant. I solve the problem by getting rid off tuya wifi switches.
Then I tried sonoff switches converted to tasmota firmware and got again dropping of wifi network. In the end I expanded wifi mesh and problem went away.
As I don’t use z-wave I don’t know how it works or how you can test signal strength. But if there is a way to test signal strength, I will try that first.

@ddaniel, there is no cloud involved in the control of these lights. I’m using a Zooz Z-Stick with Z-Wave JS UI to pair and control a number of Z-Wave devices in my home. My Z-Wave network has been very stable for a while now and I’ve never seen devices losing connectivity or becoming unavailable.

wouldn’t this be best done using a scene?