Action for when house unattended, or when people have just arrived

OK I’ve tried heaps of ways of doing this and I haven’t had much luck.

Basically, the situation is I want some additional lights on when a motion sensor is tripped. But I only want these extra lights to come on when the house is unattended (i.e. friends/family over to check on house), or immediately after I get back home.

I’ve written it out in pseudocode here. Hopefully

trigger: the front door motion sensor is tripped

conditions:

- light.extras is off
- OR:
  - zone.home is 0
  - AND:
    - zone.home is now >0 
    - zone.home was 0 less than 10 minutes ago 
 
action: turn lights.extras on
trigger:
  - platform: state
    entity_id: binary_sensor.fr_door
    to: 'on'
conditions:
  - condition: state
    entity_id: light.extras
    state: 'off'
  - not:
      - condition: state
        entity_id: binary_sensor.house_occupied
        state: 'on'
        for: "00:10:00"
action: 
  - service: lights.turn_on
    target:
      entity_id: lights.extras

EDITED: See below

Thanks for this suggestion. However, I can’t get the for key to work for numeric_state in a condition. Any ideas?

Message malformed: extra keys not allowed @ data['condition'][1]['conditions'][0]['for']

Sorry, that’s my error. You can use for with Numeric state triggers, but not conditions…

The work-around would be to set up a Template binary sensor for house occupancy. Then you could use that in a State condition with the for.

I was going to use some fancy templates to do this, but in the end I ended up settling for a timer to run when zone.home > 0. The conditions check whether zone.home is zero, or if the timer is active.