How to adjust automation to run only when the number of people in "Home" goes from 0 to 2?

Hi, I currently have an automation run where when the number of people in the zone Home changes to be above 1 (using a numeric trigger). The automation turns on the lights in our room.

This works for most scenarios, except for when my partner is still sleeping when I come home. The automation runs as there’s now two people home and then turns on the lights.

Basically, I am trying to figure out how I can specifically run the automation when the count goes from 0 to 2 people and not run if it changed from 1 to 2 people.

Can someone help point me in the right direction?

Use both from: 0 and to: 2 in your automation.

Does your zone count really go from 0 to 2 without going through 1, though? Wouldn’t you want it to trigger if it went from 0 to 1? How about this:

trigger:
  - platform: state
    entity_id: zone.home
    from: 0

I agree with @Troon. It is very unlikely that the state is ever going to jump from 0 to 2. If the from: 0 trigger proposed above doesn’t cover your needs, you can try adding a Wait action to listen for the second person entering the zone in a timely manner.

trigger:
  - platform: state
    entity_id: zone.home
    from: 0
    not_to: unavailable
condition: []
action:
  - wait_for_trigger:
      - platform: state
        entity_id: zone.home
        to: 2
    timeout:
      seconds: 30
    continue_on_timeout: false
....