Lights keep turning on after turning them off using a light sensitive sensor

Hello everyone,

I would like to ask for your advice on the following matter.

I have purchased a light-sensitive sensor so that I can switch on my living room lights when the light intensity in the room falls below a certain value. I have set up an automation for this purpose, which works as intended. However, here’s the issue: at 11:00 PM, the automation turns off all the lights because we start winding down for bed. Now, it turns out that the trigger measuring the minimum light intensity to turn the lights on keeps getting activated again. In other words, after I turn off the lights, they are turned back on 5 minutes later because the automation detects that the lux value in the living room is below a certain threshold. While the automation is logically functioning, it’s not what I want.

Do you have any ideas on how I can ensure that the lights remain off after 11:00 PM until it starts getting dark again the next day?

Thank you in advance for your input.

Herman F.

Below the code of the automation;

alias: Licht woonkamer schakelen op lichtsterkte
description: ""
trigger:
  - type: illuminance
    platform: device
    device_id: 0c7e8186753e5a92f3d5c7e16b4cfca1
    entity_id: 826c1a66b2af564b02ea0f62be76eae9
    domain: sensor
    below: 1000
    for:
      hours: 0
      minutes: 5
      seconds: 0
    id: Lampen aan
  - platform: time
    at: "23:00:00"
    id: Lampen uit
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Lampen aan
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 50
            target:
              entity_id:
                - light.lampen_woonkamer_50
          - service: light.turn_on
            data:
              brightness_pct: 30
            target:
              entity_id: light.lampen_woonkamer_30
      - conditions:
          - condition: trigger
            id:
              - Lampen uit
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.lampen_woonkamer_50
                - light.lampen_woonkamer_30
mode: single

It’s working exactly as you designed it, you need a condition for it not to fire after 23:00. Assuming you only want this to work between 08:00 and 23:00:

alias: Licht woonkamer schakelen op lichtsterkte
description: ""
trigger:
  - device_id: ""
    domain: ""
    entity_id: ""
    platform: device
  - platform: time
    at: "23:00:00"
    id: Lampen uit
condition:
  - condition: time
    before: "23:00:00"
    after: "08:00:00"
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Lampen aan
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 50
            target:
              entity_id:
                - light.lampen_woonkamer_50
          - service: light.turn_on
            data:
              brightness_pct: 30
            target:
              entity_id: light.lampen_woonkamer_30
      - conditions:
          - condition: trigger
            id:
              - Lampen uit
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.lampen_woonkamer_50
                - light.lampen_woonkamer_30
mode: single

Or create other conditions, like the setting of a helper, i.e., I have one that indicates that we are sleeping so I can make the condition sleep mode <> 'awake' for example.

2 Likes

Hi @CO_4X4 ,

Your method did the magic. Made a condition as you mentioned and so far it is working like a charm.

Thank you very much!
Herman F.

1 Like