Getting confused with conditions (IF after sunset AND light turned off more than x minutes ago)

I have a sensor in the hallway and lights in an adjoining room. The idea is that when you come down stairs in the morning or through the front door after dark into the hall, the sensor will detect you and turn the adjoining room lights on.

The problem I have had is when you turn the lights off and walk into the hall to go upstairs at the end of the night, they turn on again. I would like to have an automation rule that basically ignores the sensor activation for five minutes after the lights have been turned off to give you enough time to get upstairs.

What I have come up with is:

- alias: "Movement hall"
  trigger:
    platform: state
    entity_id: sensor.fibaro_burglar_7_10
    state: '8'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: sun.sun
        state: below_horizon
      - condition: state
        entitiy_id: group.Dining_Room
        state: off
        for:
          minutes: 5
  action:
    service: light.turn_on
    entity_id: group.Dining_Room

but I am getting the following error:

   16-10-30 06:00:46 homeassistant.bootstrap: The following platforms contain invalid configuration:  automation  (please check your configuration)extra keys not allowed @ data['condition'][0]['conditions'][1]['entitiy_id']. Got None
extra keys not allowed @ data['condition'][0]['conditions'][1]['for']. Got None
extra keys not allowed @ data['condition'][0]['conditions'][1]['state']. Got None
not a valid value for dictionary value @ data['condition'][0]['conditions'][1]['condition']. Got None
required key not provided @ data['condition'][0]['conditions'][1]['entity_id']. Got None. Please check the docs at https://home-assistant.io/components/automation/

I am sure it is something simple but I have reached that stage where I am just confusing myself!

There’s a small typo in the above:
entitiy_id -> entity_id
Maybe that’s it already?

Good spot, thank you.

Sadly, however, I still have the error. :frowning:

Can you have the hallway light on and then lights turned off when motion has not been detected for 5 mins or does this interfere with your other automations?

Otherwise, you could use a boolean switch to do what you want I think.

Have a look at this example perhaps. You could borrow a fair bit of that to make a goodnight boolean to use as a condition I reckon.

Thank you, that looks like it may work - I will have a proper look when I get back tonight.

I have taken a few days but I think I am getting there however I am still having a few teething troubles so any advice would be welcome.

My automations.yaml contains:

- alias: "Dining Room Off"
  trigger:
    platform: state
    entity_id: group.Dining_room
    from: 'on'
    to: 'off'
  action:
    service: script.turn_on
    data:
     entity_id: script.five_minute_delay
      
- alias: "Morning Hall Movement"
  trigger:
    platform: state
    entity_id: sensor.fibaro_system_fgms001_motion_sensor_burglar_19_10
    state: '8'
  condition:
    condition: and
    conditions:
     - condition: state
       entity_id: sun.sun
       state: below_horizon
     - condition: state
       entity_id: input_boolean.enable_timer
       state: 'off'
  action:
    service: light.turn_on
    entity_id: group.Dining_Room

my scripts.yaml contains:

five_minute_delay:
  alias: "Five minute delay"
  sequence:
    - service: homeassistant.turn_on
      data:
        entity_id: input_boolean.enable_timer
    - delay:
        minutes: 10
    - service: homeassistant.turn_off
      data:
        entity_id: input_boolean.enable_timer

and my inout_boolean.yaml contains:

  enable_timer:
    name: Enable Timer
    initial: off

So What I am hoping to see is:
Movement in the hall > dining room lights turn on.
Dining room lights switched off by me > timer starts disabling the hall sensor for 10 minutes

It seems to work most of the time, but occasionally the boolean switch seems to fail to stop the lights coming back on (may be something to do with the fibaro sensor and the way it detects movement - if there is a second movement detected in close proximity to the first I don’t always get an activation)

I have also had a problem where the hue lights in the dining room turn on but to the lowest possible setting. I can’t work out why this is happening or replicate it on demand… it just happens from time to time which is really frustrating when I am trying to sell the benefits of home automation to the Mrs!

Does the order that things are in the automation.yaml script matter?

(PS, yes I know I have called it five minutes delay but put ten minutes in the timer… deliberate of course… :slight_smile: )