How to troubleshoot automations

Hi!

I have an issue with two of my automations. Basically, I have a Lutron Caséta switch at my front door and Matter Sengled W41-N15A smart bulb in my living room. My automation turn on both of these 30 minutes before sunset. Then it turns them off, the bulb around midnight, the front door at sunrise.

Most of the time it works just fine, however, sometimes, HA claims it turned on both of these, but it doesn’t. I see in automation traces it is running, waiting for the turn-off condition. I’m lost on how and what I should troubleshoot when it happens. I checked the automation logs, and the device info page also says it was turned on but in fact, it wasn’t. Any tips on what do to in such a scenario?

Here are my automation yamls:

Lutron automation:

alias: Front door turn on porch light on sunset
description: Turn light in porch when sunset and turn off on sunrise
trigger:
  - platform: sun
    event: sunset
    offset: "-00:30:00"
condition: []
action:
  - metadata: {}
    data:
      brightness_pct: 30
    target:
      device_id: 922bf2a57867626e4416671f04183341
    action: light.turn_on
  - wait_for_trigger:
      - platform: sun
        event: sunrise
        offset: "-01:00"
  - metadata: {}
    data: {}
    target:
      device_id: 922bf2a57867626e4416671f04183341
    action: light.turn_off
mode: single
trace:
  stored_traces: 10

Smart bulb automation:

alias: Living room sunset automation
description: Turn light in living room when sunset and turn off after midnight
trigger:
  - platform: sun
    event: sunset
    offset: "-00:30:00"
    enabled: true
condition: []
action:
  - metadata: {}
    data:
      brightness_pct: 100
    action: light.turn_on
    target:
      entity_id: light.living_room_light
  - wait_for_trigger:
      - platform: time
        at: "00:10:00"
  - if:
      - condition: state
        entity_id: media_player.living_room
        state: "off"
    then:
      - metadata: {}
        data: {}
        target:
          entity_id: light.living_room_light
        action: light.turn_off
    else:
      - action: light.turn_on
        metadata: {}
        data:
          brightness_step_pct: -40
        target:
          entity_id: light.living_room_light
mode: restart

Hi MicNeo,

So while it is possible to wait long periods of time in a wait or delay, it is generally not recommended. This is because HA restarts and many other possible things can happen which interrupt this 'wait’and then it hangs as you describe.

The suggested method is have a trigger or an automation for turning it on, and another trigger or another automation for turning it off.

2 Likes

Thank you for the reply. I was going to split these into 2 separate automation as you’re suggesting, because I had to remember to restart these two if I reboot HA (e.g. because of an update).

However, the problem was not in turning these lights off, but in turning them on. Let me try splitting these automations and see if that helps.

You don’t need to split them into 2 separate automations. You can add the sunrise event as a separate trigger. If you assign each trigger an ID, you will then be able to use choose of if conditions, based on that ID.

Regarding your light & switch not turning on - have you ever encountered any issues with switching them on from HA manually?
Tell us more about how they are integrated. I’m assuming at least one of those is via matter - in that case - are you running matter via multi-protocol or do you have a standalone router for it?

Thank you for the advice about using trigger IDs. This is really nice! I tried splitting this automation anyway, just to see if it helps, but no. It still happens from time to time.

I have a Lutron hub, and I’m using Lutron integration in HA to control it. When this issue occurred yesterday, I checked the Lutron app, and it also showed that the light was on. But in fact, it wasn’t. So it might be a problem on Lutron side? I have another Lutron switch in my bathroom which is activated based on motion, never had an issue with that one :confused:

When it comes to matter. I’m using SkyConnect stick for it. I have Sonoff stick for my zigbee network. I have 4 devices in matter network, 3 Aquara motion sensors, and that light bulb. I don’t any hub/bridge for that bulb, it is connected with HA directly.

“have you ever encountered any issues with switching them on from HA manually?” - not really. But I don’t switch them manually too often. I played with it right now, and I successfully turned both of these on and off like 30 times. It worked all the time.

That’s the thing, it doesn’t happen every single time, so I’m curious if there are any additional logs I could and should check?

Whenever there’s ample evidence that Home Assistant issues a turn off or turn on command but the device fails to turn on/off, then it implies there’s a communication problem between Home Assistant and the physical device. The fact that it works sometimes but not always is yet another indicator of a communications problem.

The device occasionally fails to receive the command due to marginal communications so that’s where you will need to focus your attention. Given that the two lights use different integrations, you will need to improve your Lutron and Zigbee networks.

Here’s a good guide for Zigbee:

I’m unfamiliar with Lutron Caseta so hopefully someone else can provide guidance.

Thank you! I will look into this guide!