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

I searched for hlep on this and fell at the first hurdle

The instructions are to set (In visual editor Mode) the Time to be 10 p.m. then set hte trigger to repeat every hour…

But my visual editor does not have the “Repeat” function at all.

Can you help guide me please.

EDIT added the following ChatGPT response:
To turn off all lights every hour between 11 pm and 5 am every night using Home Assistant, you can create an automation with the following steps:

  1. Open your Home Assistant configuration file and add the following code to create an input boolean for the automation:

yamlCopy code

input_boolean:
  night_mode:
    name: Night Mode
    initial: off
  1. Next, create a new automation by going to the “Configuration” menu in the sidebar, selecting “Automations”, and clicking the “+” button.
  2. In the automation editor, give your automation a name, and select “Time” as the trigger type.
  3. Under the “Time” trigger, set the following parameters:
  • At: 11:00 PM
  • Repeat: Every 1 hour
  • Until: 5:00 AM
  1. Next, add a condition to the automation that checks if the “Night Mode” input boolean is on. This will ensure that the automation only runs during the designated hours.
  2. Finally, add an action to the automation that turns off all lights in your home. You can use the “Home Assistant” service with the “turn_off” action to accomplish this. Here is an example of the code you can use for the action:

yamlCopy code

action:
  - service: homeassistant.turn_off
    entity_id: all_lights

Replace “all_lights” with the entity ID for all the lights in your home.

And that is why you don’t use chat bots to design automations.

Why do you want to repeatedly turn the light off?

A far better way to accomplish this may be with state driven automations rather than blind polling.

Describe what you want to achieve, not how you think you should solve the problem.

3 Likes

Thanks very much for this.

Context:
We have two young adults in the house. I frequently come downstairs to find out that all the lights are on downstairs (and have been all night !). The kids have depreciated a lot, so no point in trying to sell them now.

  • Pretty much all lights in Philips Hue - one hub for the kitchen, one for the rest of the house.
  • We do have some motion sensors (one Hue, two Smartthings), but they generally haven’t worked well.
  • Homeassistant runs in a docker on an Unraid server.

Intention:
Want to turn off all lights after 10 p.m and thereafter, in case one of the kids gets up to make a midnight snack, or has a marathon Gaming session.

Thats all well and good. But you also need to define an exception (else this will fall flat, partner approval factor will be very low) as part of your requirements.

So what do you want to use to tell the system NOT to do this?

For instance in my home I have motion sensors and. An read the state of my TV so my living room lights are tied to those and don’t start considering a room ‘vacant’ and shutting things down until those are quiet.

If you don’t do this, I forsee a situation where you or the spouse or the kids have a late fri night and it starts an argument because ‘the darned light won’t stay on’

which gave you a very complicated solution, while it seems pretty easy to me…
if light turned on after 21:00 before 04:00 for one hour turn off the light.

trigger: light turn on / for 60 minutes
condition: after 21:00 / before 04:00
action: turn off lights

and that is about it…

that’s because there is no “repeat” that exists under the trigger section.

that is only available in the action section.

Hence why it’s not good to use ChatPGT. It’s close enough so that you think it might make sense but not close enough to actually get it to work correctly. Then when it doesn’t work some people get frustrated and then they still have to come on here and ask for help. Only now they have a preconceived notion of the way they think it should work based on the erroneous info given previously.

If you really want it to run every hour then just make a time pattern trigger and then put your time interval limitations in the conditions.

Then all you need to do is decide on what the definition of “all the lights” will be. Do you really mean ALL the lights or just some select lights?

In the future, please don’t.

There’s no need to post ChatGPT’s non-functional instructions.


As for what you requested, aceindy’s suggestion should fulfill it.

3 Likes

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

Thanks very much for this and all of the other replies.