Automation misbehaving - What am I missing?

Hello,

I wrote an automation for my house that if I wake up between 5:00am and sunrise, a motion sensor will trigger and turn on a few lights including WLED in my kitchen. It then sets the WLED instance to a White Dim preset. This works great.

However, the automation is also not supposed to trigger if the WLED instance is already on. This is sort of working in that if the light is already on (triggered earlier), but it gets triggered again later in the morning and the light is still on, it still sets the light to White Dim even if I have changed WLED to another preset. I can’t figure out why this is happening.

Tracing it says that is didn’t do it, but the logbook says it did. I am super confused

Here is the yaml:

alias: Morning Light - Kitchen
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.z_wave_motion_sensor_home_security_motion_detection_3
    to: "on"
conditions:
  - condition: sun
    before: sunrise
  - condition: time
    after: "05:00:00"
  - condition: state
    entity_id: light.kitchen_wled1
    state: "off"
actions:
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.kitchen_wled
  - device_id: 4b9d1dad2034d8c3c45a69db47416b59
    domain: select
    entity_id: 399f9305aea8764be603dbffdc572afa
    type: select_option
    option: White Dim
mode: single

Here is the trace and the log book: HA Trace - Album on Imgur

Any suggestions on what I am missing?

Hi Michael,

?maybe this?

Thanks,

light.kitchen_wled is a light group and light.kitchen_wled1 is just one of the members. I will sync them up, but suspect I will have the same problem in the morning (and I will confirm)

I am just most curious why the trace says if fails because the 3rd condition shows it is on, it still sets the device to white dim.

Well conditions are “and” unless coded otherwise, so if that is not “off” The trace has to stop at that condition statement and run no actions.

I totally agree that is what it should do, but if you look at the trace it shows that it saw the light on and stopped - but the logbook shows that it still set the preset to White Dim anyway.

Make sure those are the same runs of the automation. Default there are 5 traces, but you can change that to see more. It may have run, turned on the light, run again, and showed the next trace it did not turn the light on, within fractions of a second even.

If the trace says the automation didn’t execute the actions then it probably didn’t. What exactly does the logbook entry say?

is it possible that the preset is being changed by something other than this automation?

from looking it over I don’t see anything wrong with the automation and if the light is already on and the only thing changing is the preset then I can’t see it being this automation doing that.

@Sir_Goodenough @finity Here are some updated logs from today: https://imgur.com/a/XnWHXPI

You can see the motion sensor is only triggering once for a given time period.

I didn’t capture the first trace of the day as it got triggered again while I was capturing it and it rolled off as number six, but you can see what it did in the logs

  1. First trigger - the automation turns on the light and set it to White Dim
  2. Following triggers - Says that it stops execution because the light is already on, but the logs show the action to set the WLED to White Dim happened anyway and was triggered by the automation. I do NOT see it send the signal to turn on the light in the following triggers - just in the first.

I think I would be looking into the times in the logbook that the preset became “unknown”.

that might be the cause of the issue.

if the automation actions are blocked from running then there’s no way it could be causing the preset to change.

maybe the log entry is just reflecting the fact that the last time that the preset was changed to a valid value it was done by that automation.

:man_shrugging: