Best Approach to Trigger Automation using light threshold

Hi I am having difficulties with a fairly simple automation.
I have HA running as a docker container on Synology. Running version 0.111.4

I am using a Aqara motion/light sensor to trigger the lights in a room using the following automation.

- alias: Lights on after dark
  trigger:
    - platform: numeric_state
      entity_id: sensor.lightlevel_lounge
      below: 12
  condition:
       - condition: state
         entity_id: alarm_control_panel.alarm
         state:  'disarmed'
  action:
     service: homeassistant.turn_on
     entity_id: light.lounge_group

However, it does not work most of the time and I am not seeing any obvious error/warning messages in the logs.

I saw in this community a reference to creating an entity

What would others recommend? Can you see a reason why my code is so unreliable? Any assistance would be great.
Thanks

That will only trigger the first time the light drops below 12 and the alarm is off. If the light level is already below 12 and the alarm is then disarmed, that won’t trigger.

You could either add another automation which triggers when the alarm is disabled and the light level is below 12, or you could run a script every X minutes that only runs if the lights are off, the alarm is disabled and the light level is below 12.

Ah, I think I understand why now, the alarm shuts off at 5 am and probably the light level is below 12 at that time, I assumed that when the light level went above 12 it would trigger again when the level fell below 12. I will try your suggestions. Thanks Callifo.

You should use the motion state as the trigger and the light level as the condition.

Hey Trevor1, for clarity you are suggesting using the alarm state as the trigger e.g. when it changes to “disarmed” and the condition is light level?
Sounds worth a try! But the change in state of the alarm is only once per day, whereas the light level could be multiple times a day, particularly here in the UK!!!

Doesn’t your Aqara motion/light sensor have two entities to it? one binary sensor for motion and one light level sensor? Mine do. I use the binary sensor to check the room for motion, and the lightlevel to check if it is dark enough to want the light turned on. I would then leave the alarm condition as is.

Ah yes, sorry I misunderstood. I have not figured out the motion sensor. So far I think the motion sensor is only triggered when someone moves around, so if you are sitting watching a movie it won’t necessarily sense your presence. My preference is for the light to come on when the room gets dark irrespective if someone is in the room but I don’t want the light to come on if we are out of the house.

Okay another way you could do this, and maybe the easiest is like this:

- alias: Lights on after dark
  trigger:
    - entity_id: sensor.lightlevel_lounge
      platform: state
  condition:
       - condition: state
         entity_id: alarm_control_panel.alarm
         state:  'disarmed'
       - condition: state
         entity_id: sensor.lightlevel_lounge
         below: 12
  action:
     service: homeassistant.turn_on
     entity_id: light.lounge_group

Doing it in this fashion, any state change in the light level sensor (ie. lightlevel numeric change) will trigger the automation, and then it will check the numeric condition of the light level itself.

Actually you should probably add a third condition to this. only if the lights are off.

thanks Trevor, it looks good. I have modified my automation yaml and it did not trigger when the light level dropped below 12. I think its something to do with my formatting, VScode is not reporting any errors and nothing in the logs so I am assuming its not even triggering.

Does it fire if you remove the control panel condition?

it fires now, thanks Trevor, it did not help that the after we sorted the trigger I found that the action did not work. My light.lounge.group was a group created in hive, this does not appear to work in HA.

  action:
     service: homeassistant.turn_on
     entity_id: group.living_room

When I changed it to a group I created in HA yaml config it triggered like a dream. Will investigate further. Thanks for your assistance. I love this community!