Keep lights off in time range

Hi all!
I’m facing a problem on switch automation: I want to check every minute and switch off the lights (and keep them off if switched on) if time is between 7:30 am and 8 Pm and only If the switch is currently on and if manual override is off (disable_auto_shutdown_lights).
Manually starting the trigger works and switch works as well (I use them everyday to switch lights). I think it’s something related to automation but I can’t find the reason (no error in log)
Here is my automation config (in a separate yaml included with include_dir_merge_list)

 - alias: "Lights off between 07:30 and 20:00"
   initial_state: "on"
   hide_entity: False
   trigger:
     platform: time
     minutes: "/1"
     seconds: 00
   condition:
       condition: and
       conditions:
         - condition: time
           after: "07:30"
           before: "20:00:00"
         - condition: state
           entity_id: switch.living_room_floor_lamp
           state: "on"
         - condition: state
           entity_id: switch.disable_auto_shutdown_lights
           state: "off"
   action:
     - service: switch.turn_off
       entity_id: switch.living_room_floor_lamp
     - service: notify.telegram_debug
       data:
         message: "lights_off 07:30 - 20:00"

Any suggesions?

Thanks!

You’re missing the seconds in your after condition. That might be it.

As an alternative trigger, consider using two different ones. One at 7:30, and one based on the switch going on. That way your militant light turning off will happen nearly instantaneously instead of every minute!

Remove initial_state and hide_entity from the automation. Those don’t belong in the automation. They belong in the configuration. I’m surprised you’re not getting any errors with those in there.

As mentioned by Dolores, be sure to add seconds to your “after” time condition. It should be “07:30:00”.

Everything else looks like it should work.

Thank you for your suggestions!..I’ll try when at home the I’ll let you know it if works :slight_smile:

Ok just tried these modifications:

  • added seconds on first time definition: no way
  • removed seconds from both time definitions: no way
  • removed initial_state and hide_entity as suggested: no way (but I’m pretty sure this wasn’t the problem, removed only on correct suggestion :slight_smile: )

Well I found the problem and the problem was…me :roll_eyes:
One of my conditions is

 - condition: state
   entity_id: switch.disable_auto_shutdown_lights
   state: "off"

That switch.disable_auto_shutdown_lights doesn’t exists. It is a copy paste error :sweat_smile:…correct entity is input_boolean.disable_auto_shutdown_lights! After changing with correct entity of course it worked flawlessly.

Anyway, thank you all for suggestions!