I want to turn off all lights every hour after 10 pm until 5 am - Repeat Trigger

Here are some ideas

First the simple automation to turn on light with a motion sensor and turn it off 2 minutes after the motion sensor stops sensing motion

- id: 'Utility_room_on_with_Motion'
  alias: 'Utility room on with Motion'
  initial_state: true
  mode: restart
  max_exceeded: silent
  trigger:
    platform: state
    entity_id: binary_sensor.utility_room_motion
    from: "off"
    to: "on"
  action:
    - service: light.turn_on
      data:
        entity_id:
          - light.utility_ceiling
        brightness_pct: 100
    - wait_for_trigger:
        platform: state
        entity_id: binary_sensor.utility_room_motion
        from: "on"
        to: "off"
    - delay: 120
    - service: light.turn_off
      target:
        entity_id: light.utility_room

And

Here is a room with multiple motion sensors and we want the light off when the last motion sensor stops sensing. The light we turn on depends on time of day

- id: 'Office_Lights_Motion'
  alias: 'Office Lights Motion'
  initial_state: true
  mode: restart
  max_exceeded: silent
  trigger:
    - platform: state
      entity_id: binary_sensor.office_sensor_motion
      from: 'off'
      to: 'on'
    - platform: state
      entity_id: binary_sensor.office_radar
      from: 'off'
      to: 'on'
  action:
    - choose:
      # Make-up time
      - conditions:
          - condition: time
            after: '06:00:00'
            before: '09:00:00'
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
        sequence:
          - condition: state
            entity_id: light.computer
            state: 'off'
          - service: light.turn_on
            data:
              entity_id:
                - light.computer
                - light.makeup
              brightness_pct: 100
          - service: light.turn_on
            data:
              entity_id:
                - light.office_panel
              brightness_pct: 60
      # Rest of day
      - conditions:
          - condition: state
            entity_id: light.computer
            state: 'off'
        sequence:
          - service: light.turn_on
            data:
              entity_id:
                - light.computer
                - light.makeup
              brightness_pct: 100
    - wait_template: >
        {{  is_state('binary_sensor.office_sensor_motion', 'off')
           and is_state('binary_sensor.office_radar', 'off') }}
    - delay: 30
    - service: light.turn_off
      data:
        entity_id:
          - light.

And last my bedroom

I have 3 motion sensors. One can make false detections as it is a radar that can see a curtain move so we only use it to turn off.

If we are in bed we do not want the light to turn on or turn off unless we press the button. If a light is already on, we do not turn more light on either. We have sensors that detect that we are in bed

And there is a time condition.


- id: 'Bedroom_light_motion'
  alias: 'Bedroom light motion' 
  initial_state: true
  mode: restart
  max_exceeded: silent
  trigger:
    - platform: state
      entity_id: binary_sensor.bedroom_motion
      to: 'on'
    - platform: state
      entity_id: binary_sensor.bedroom_2_motion
      to: 'on'
#  condition:
#  we cannot use conditions because motion has to retrigger wait to turn off
  action:
    - if:
        - condition: state
          entity_id: binary_sensor.bed_sensor_kenneth
          state: 'off'
        - condition: state
          entity_id: binary_sensor.bed_sensor_diane
          state: 'off'
        - condition: state
          entity_id: light.ceiling_2
          state: 'off'
        - condition: state
          entity_id: light.ceiling_3
          state: 'off'
        - condition: state
          entity_id: light.bed_kenneth
          state: 'off'
        - condition: state
          entity_id: light.bed_diane
          state: 'off'
        - condition: numeric_state
          entity_id: sensor.bedroom_luminance
          below: 10
        - condition: time
          after: '06:00:00'
          before: '23:30:00'
      then:
        - service: light.turn_on
          data:
            entity_id: light.bedroom
            brightness_pct: 50
    - condition: state
      entity_id: binary_sensor.bed_sensor_kenneth
      state: 'off'
    - condition: state
      entity_id: binary_sensor.bed_sensor_diane
      state: 'off'
    - wait_template: >
        {{ is_state('binary_sensor.bedroom_motion', 'off')
           and is_state('binary_sensor.bedroom_2_motion', 'off')
           and is_state('binary_sensor.bedroom_radar', 'off') }}
    - delay: 60
    - if:
        - condition: state
          entity_id: binary_sensor.bed_sensor_kenneth
          state: 'off'
        - condition: state
          entity_id: binary_sensor.bed_sensor_diane
          state: 'off'
      then:
        - service: light.turn_off
          data:
            entity_id: light.bedroom

None of these are exactly what you want but you have the examples of triggers. You have conditions based on luminance or time. You have the time out based on motion stopping. You have example of multiple motion sensors to get better coverage. I hope it is something that can inspire

1 Like