Straightforward mistake I cannot see - another simple automation

This is driving me mad. If I walk into the room this sensor is "detecting", nothing happens. The (new to me) green 'yeah, that's right' lights come up in the automation on my phone, but nothing happens.

2 minutes later, the light comes on.

I'm positive it's something glaringly obvious, please help!

Automation is basically, tv room amp off? Sun is below horizon? Presence detected? Turn the light on. Not wait a couple of minutes and do it.

I have this light coming on with the tv room amp btw, never skips a beat.

Thanks for reading.

alias: TV Room (anyone there)
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.hobeian_zg_204zm_occupancy
    from: null
conditions: []
actions:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: media_player.tv_room_2
                state: "off"
              - condition: state
                entity_id: sun.sun
                state: below_horizon
              - condition: state
                entity_id: binary_sensor.hobeian_zg_204zm
                state:
                  - "on"
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.tv_room_light
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: media_player.tv_room_2
                state: "off"
              - condition: state
                entity_id: sun.sun
                state: below_horizon
              - condition: state
                entity_id: binary_sensor.hobeian_zg_204zm
                state:
                  - "off"
                enabled: true
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.tv_room_light
mode: restart

The only thing that triggers this automation is the state of binary_sensor.hobeian_zg_204zm_occupancy... are you sure that is working correctly? There are a number of older threads about this device not working properly.

Second, you have 2 very similar entity ID's your automation binary_sensor.hobeian_zg_204zm_occupancy and binary_sensor.hobeian_zg_204zm are those both valid and are they being used in the right places?

Yep, well done. The missing _occupancy was definitely what I wasn't able to see and looks like it was causing the issue, so thanks for seeing that.

I think I might need to find a better trigger to turn the light back off though. If you leave the room and the occupancy clears (which it does see, the state definitely changes in HA) it doesn't turn the light off again in time, and is (I think) waiting for a trigger that won't occur.

What's a decent trigger to use in this situation?

Thanks again.

I do something similar for presence in certain rooms of the house but base it off of “wasp-in-the-box” logic. I use a timer helper. Anything that should indicate presence in the room, including presence and/or motion sensors or a device like a fan or media_player states, etc. are used as triggers and each trigger gets an ID. Then, I use choose action, I use triggered by ID conditions with actions that turn on the timer and the lights.

The key is to loop back and reset the timer, so there’s choose blocks with conditions that evaluate the current states of my sensors and devices which will reset the timer. The timer is set relatively short, between 3 to 5 seconds typically, except for my bathrooms which I set to 15 minutes.

When the timer does run out and no conditions are met, the lights go off.

Appreciate the insight, that might be above my skill level tbh.

Ultimately, this is just to turn on a light in a very dark tv room - perhaps I should just get it to turn on for a period of time. Once you sit down turn on the amp, it'll turn the light off anyway as part of that device's automation - the thinking is that by then you're not tripping over stuff.

Check the automation's debug traces for a time that happened and see which condition of the Choose isn't passing. Once we know that, we can figure out the changes that are needed.

You fixed it when you noticed the missing bit from the entity. Did you miss my reply?