Turn off light between certain times, else dim light

I’m having trouble to get the automation below working:

Condition light: ON
State Motion Sensor: ON to OFF

Between (after) 23:00:00 and (before) 06:30:00 Dimmable Light should Turn off (state Motion Sensor ON -> OFF).
For everything in between (when Light is ON) the light should be dimming to 50%.

The is issue that between 23:00 and 06:30 the light doesn’t go off, but always dims to 50%.

I know this can be done different ways and I guess much easier (ideas are welcome! :wink: ) but in the case below using choose: I can’t get it to work.

Thanks for help and ideas.

- alias: 'Motion Sensor - off (1min)'
  trigger:
    platform: state
    entity_id: binary_sensor.tms_gang
    from: 'on'
    to: 'off'
  condition:
    condition: state
    entity_id: light.dimmable_light_1
    state: "on"

#  mode: single
  action:
    - choose: #if
        - conditions:
            - condition: time
              after: '23:00:00'
            - condition: time
              before: '06:30:00'
          sequence:
            - service: light.turn_off
              entity_id: light.dimmable_light_1

      default: #else
        - service: light.turn_on
          entity_id: light.dimmable_light_1
          data:
            brightness_pct: 50
            transition: 4

I think the problem is that with a time condition if you only provide a before or after time then it runs to midnight. So your current conditions are that it is between midnight and 6.30 and between 23.00 and midnight, which of course is never possible and therefore never true. In order to span midnight you either need to use an OR condition or use both before and after in the same time condition to create a ‘between’

Try this…

- alias: 'Motion Sensor - off (1min)'
  trigger:
    platform: state
    entity_id: binary_sensor.tms_gang
    from: 'on'
    to: 'off'
  condition:
    condition: state
    entity_id: light.dimmable_light_1
    state: 'on'
  action:
    - choose:
        - conditions:
            - condition: time
              after: '23:00:00'
              before: '06:30:00'
          sequence:
            - service: light.turn_off
              entity_id: light.dimmable_light_1
      default:
        - service: light.turn_on
          entity_id: light.dimmable_light_1
          data:
            brightness_pct: 50
            transition: 4

:thinking: I’ve seen that of course in other topics before, but didn’t think about it anymore.
I’ll give it a try and let you know, thanks!

1 Like

Try joining that into one condition:

- condition: time
  after: '23:00:00'
  before: '06:30:00'

That’s what I suggested, and he said he would try, an hour ago :wink:

1 Like

Hi Marc,
Thanks for the help! It’s working as it should be. :+1:

Christoph, thank you too.

1 Like