Automation runs but don't understand why

Why did this automation run while media_player.kodi is in the state ‘idle
am I doing something wrong with the several conditions (specifically the NOT condition)?

- alias: 'Lights on as the sun gets dimmer and Kodi is playing'
  trigger:
    platform: numeric_state
    entity_id: sensor.woonkamer_lux
    below: 3
  condition: 
    condition: and
    conditions: 
      - condition: time
        before: '22:30:00'
      - condition: or
        conditions:
          - condition: state
            entity_id: media_player.kodi
            state: 'paused'
          - condition: state
            entity_id: media_player.kodi
            state: 'playing'
      - condition: not
        conditions: 
          - condition: state
            entity_id: light.hue_color_1_voor
            state: 'on'

The recent addition is this:

      - condition: not
        conditions: 
          - condition: state
            entity_id: light.hue_color_1_voor
            state: 'on'

but as far as I know I’m doing that correctly.
It seems it’s not performing the AND for all those conditions and triggers just based on the light.hue_color_1_voor being off.

Did you debug it? Click on the 3 dots next to the automations → Traces and you will see why the automation runs.

You didn’t really say what you actually wanted so here is how it is now:

time is before: ‘22:30:00’ and light.hue_color_1_voor is not ‘on’ and either media_player.kodi is ‘paused’ or media_player.kodi is ‘playing’

if all of that is true then the automation will run when triggered.

I have it fully in yaml. When I click traces through the UI it says nothing found. I guess I could port it to the new automation ui part and then do traces, right?
Until now I have all my automations in yaml. Been with Home Assistant for about 7 years now :slight_smile:

@finity it ran while:
yes it was before 22:30
no kodi was no in playing or paused because it was in state “idle”
yes the lihgt was off.

So I as I understand it shouldn’t have ran because not all conditions were met.
But to me it seems like it’s not doing the AND properly for the NOT condition. And it’s treating that as an OR.

You don’t need to do that. just add an “id:” line to the automation config and you can then get traces

And just to be sure your indenting isn’t an issue (but it looks right to me) you can just move the “not” above the “or”.

- alias: 'Lights on as the sun gets dimmer and Kodi is playing'
  id: some_random_string_here
  trigger:
    platform: numeric_state
    entity_id: sensor.woonkamer_lux
    below: 3
  condition: 
    condition: and
    conditions: 
      - condition: time
        before: '22:30:00'
      - condition: not
        conditions: 
          - condition: state
            entity_id: light.hue_color_1_voor
            state: 'on'
      - condition: or
        conditions:
          - condition: state
            entity_id: media_player.kodi
            state: 'paused'
          - condition: state
            entity_id: media_player.kodi
            state: 'playing'
- alias: 'Lights on as the sun gets dimmer and Kodi is playing'
  id: lights_on_as_the_sun_gets_dimmer_and_kodi_is playing
  trigger:
    - platform: numeric_state
      entity_id: sensor.woonkamer_lux
      below: 3
  condition: 
    - condition: time
      before: '22:30:00'
    - "{{ is_state('light.hue_color_1_voor', 'off') }}"
    - "{{ states('media_player.kodi') in ['paused', 'playing'] }}"
 action:
    ... etc ..

Thanks everyone for your suggestions.
It seems moving the NOT above OR has done the trick.
Since that change I didn’t see any wrong triggers happening anymore.
I’ll monitor a few more days before selecting the “solution” answer.

At the time it actually needed to run (last night) it ran correctly however what I find interesting is that the traces info shows FALSE for the NOT condition.
I would expect it would show TRUE.

The wanted state should be “off” (which was the case when the automation ran well last night).
Perhaps the traces part isn’t coping well with NOT conditions?

Is there a particular reason why the last State Condition adopts a Yoda-like query:

Is the light on, not?

instead of simply:

Is the light off?

In your latest example, the initial condition: and isn’t necessary because, by default, a list of conditions is logically ANDed.

Have your requirements changed? In your latest example:

  1. The Time Condition has a starting time (14:00).
  2. There’s a State Condition to check if an input_boolean is off.
  3. A State Condition checks if the media_player is idle instead of the original playing or paused.

Ah yes sorry for the confusion.
I have 2 quite similar automations. One is for when kodi is playing or paused and the other for when kodi is idle.
Yesterday the one triggered where kodi is not playing (which was expected behavior) so that’s the tracing you see.
The other one didn’t run at all (which is also expected behavior).

Reason for the NOT ‘on’ checking is because I noticed occasionally the light is in the status “unavailable”. So just checking for OFF is not enough.
Now I could also check for off AND unavailable but I thought perhaps there are even more statuses I don’t know about so that’s why I wanted to specifically check for NOT being on.

  condition: 
    - condition: time
      after: '14:00:00'
      before: '22:30:00'
    - "{{ is_state('input_boolean.autolightslivingroon.kodi', 'off') }}"
    - "{{ states('light.hue_color_1_voor') != 'on' }}"
    - "{{ is_state('media_player.kodi', 'idle') }}"