Since adding different brightness/time of day variables my lights don't always turn on

I know this is pretty basic stuff and I have far more involved automations running but I cannot figure out why between 6pm and 11pm my lights only turn on half the time with this automation. When I check traces it just says it chose to do nothing and stopped the automation. My ADHD is making it frustratingly difficult to troubleshoot. That and my family hate it when the automations stop behaving! :slight_smile:
Below is the image of the GUI for the automation. I’m happy to post the YAML if it’s easier.

The two different Light Turn On “Kitchen” options are the two different brightness settings.

Pls post the yaml and the download of the trace for when it failed

Here you go…and thanks for the input.

alias: Kitchen Main Lights Motion
description: “”
trigger:

  • platform: state
    entity_id:
    • binary_sensor.kitchen_motion_sensor_occupancy
      id: kitchen motion sensor on
      from: “off”
      to: “on”
  • platform: state
    entity_id:
    • binary_sensor.kitchen_motion_sensor_occupancy
      id: kitchen motion sensor off
      from: “on”
      to: “off”
      for:
      hours: 0
      minutes: 3
      seconds: 30
      condition:
      action:
  • choose:
    • conditions:
      • condition: trigger
        id: kitchen motion sensor on
      • condition: numeric_state
        entity_id: sensor.kitchen_motion_sensor_illuminance_lux
        below: 70
      • condition: time
        before: “22:59:00”
        after: “06:00:00”
        sequence:
      • service: light.turn_on
        data:
        brightness: 255
        target:
        area_id: kitchen
    • conditions:
      • condition: trigger
        id: kitchen motion sensor on
      • condition: numeric_state
        entity_id: sensor.kitchen_motion_sensor_illuminance_lux
        below: 70
      • condition: time
        before: “05:59:00”
        after: “23:00:00”
        sequence:
      • service: light.turn_on
        data:
        brightness: 78
        target:
        area_id: kitchen
    • conditions:
      • condition: trigger
        id: kitchen motion sensor off
        sequence:
      • service: light.turn_off
        data: {}
        target:
        area_id: kitchen
        mode: single

I do not have a trace at the moment. I only see the last 5 Trace entries and it seems to work fine during the day. It’s only after 6pm roughly that it starts acting up. I noticed last night that I will walk into the kitchen and nothing will happen…no lights…then I will walk out and come back in about 1 min later and it works.
I will make sure to get the trace yaml tonight when it happens again.

Hope that info helps.

Its easier if you post your yaml using the performatted text option, then others can read it more easily.

However, I’d guess its one of two things.

The lux level is too high, so the condition correctly stops the light from turning on.

or

You have an issue with the signal strength to that device, and its not receiving the command.

Or possibly, a third option… the lux level is not updated at the same frequency as the motion sensor. (This is the least likely as its usually wrapped up in the same device as the motion sensor, but it can still happen - The everything presence one used to do this until they change the firmware a while back.).

1 Like

And finally, although not your issue, you have gaps in your timing conditions. if re-ordered to make them more readable, you have the following:-

after: “06:00:00”
before: “22:59:00”

after: “23:00:00”
before: “05:59:00”

This means there is a 1 minute gap between 05:59:00 and 06:00:00 where the automation won’t fire…

same for 22:59:00 and 23:00:00.

1 Like

+1 to @Rofo 's comments.

please do grab than when it happens. it should tell exactly what’s happening as long as the trigger happens (even if conditions fail).

Thanks for the replies! I will definitely grab the trace tonight.

The 1 min gap in the time was an experiment to see if that was the issue. I’ll put it back to the original with no gaps.

Cheers!

Thanks @Rofo!

I’ll try those first but it has worked perfectly for two years with no issues until I added the time and brightness conditions. I’ll also change the battery on the device just to make sure it’s not that.

I used to use the Adaptive Lighting add-on but could never get it to stop turning the lights to full brightness when the motion sensor was retriggered. None of the settings made any difference so I decided to do it manually with the Choose section in the automation.

Will report back.

Wouldn’t you know it…it all worked as intended last night. Very frustrating!

As soon as it skips a command I’ll post the trace.

It happened again. Here is the trace. Thanks so much for any input/

{
  "trace": {
    "last_step": "action/0/choose/2/conditions/0",
    "run_id": "74a218044d19127e82f2834f0034b4b6",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2024-07-10T03:51:09.694385+00:00",
      "finish": "2024-07-10T03:51:09.702030+00:00"
    },
    "domain": "automation",
    "item_id": "1669593066842",
    "trigger": "state of binary_sensor.kitchen_motion_sensor_occupancy",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2024-07-10T03:51:09.694544+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.kitchen_main_lights_motion",
              "state": "on",
              "attributes": {
                "id": "1669593066842",
                "last_triggered": "2024-07-10T03:21:38.775761+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Kitchen Main Lights Motion"
              },
              "last_changed": "2024-07-07T05:34:54.900635+00:00",
              "last_reported": "2024-07-10T03:21:38.927307+00:00",
              "last_updated": "2024-07-10T03:21:38.927307+00:00",
              "context": {
                "id": "01J2DAJD6P4NB3NN54VWWS4YVN",
                "parent_id": "01J2DAC0447QXACMNRDS1Y60BY",
                "user_id": null
              }
            },
            "trigger": {
              "id": "kitchen motion sensor on",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "binary_sensor.kitchen_motion_sensor_occupancy",
              "from_state": {
                "entity_id": "binary_sensor.kitchen_motion_sensor_occupancy",
                "state": "off",
                "attributes": {
                  "device_class": "occupancy",
                  "friendly_name": "Kitchen Motion Sensor Occupancy"
                },
                "last_changed": "2024-07-10T03:18:08.772034+00:00",
                "last_reported": "2024-07-10T03:18:08.772034+00:00",
                "last_updated": "2024-07-10T03:18:08.772034+00:00",
                "context": {
                  "id": "01J2DAC0447QXACMNRDS1Y60BY",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "binary_sensor.kitchen_motion_sensor_occupancy",
                "state": "on",
                "attributes": {
                  "device_class": "occupancy",
                  "friendly_name": "Kitchen Motion Sensor Occupancy"
                },
                "last_changed": "2024-07-10T03:51:09.693171+00:00",
                "last_reported": "2024-07-10T03:51:09.693171+00:00",
                "last_updated": "2024-07-10T03:51:09.693171+00:00",
                "context": {
                  "id": "01J2DC8EKX2CEBTT1XYN5D1D59",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of binary_sensor.kitchen_motion_sensor_occupancy"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2024-07-10T03:51:09.696668+00:00",
          "changed_variables": {
            "context": {
              "id": "01J2DC8EKYXT7M6GCEKDAN3H8E",
              "parent_id": "01J2DC8EKX2CEBTT1XYN5D1D59",
              "user_id": null
            }
          }
        }
      ],
      "action/0/choose/0": [
        {
          "path": "action/0/choose/0",
          "timestamp": "2024-07-10T03:51:09.696743+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0",
          "timestamp": "2024-07-10T03:51:09.696770+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/0/conditions/1": [
        {
          "path": "action/0/choose/0/conditions/1",
          "timestamp": "2024-07-10T03:51:09.696795+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/1/entity_id/0": [
        {
          "path": "action/0/choose/0/conditions/1/entity_id/0",
          "timestamp": "2024-07-10T03:51:09.696815+00:00",
          "result": {
            "result": false,
            "state": 83,
            "wanted_state_below": 70
          }
        }
      ],
      "action/0/choose/1": [
        {
          "path": "action/0/choose/1",
          "timestamp": "2024-07-10T03:51:09.696862+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0": [
        {
          "path": "action/0/choose/1/conditions/0",
          "timestamp": "2024-07-10T03:51:09.696876+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/1/conditions/1": [
        {
          "path": "action/0/choose/1/conditions/1",
          "timestamp": "2024-07-10T03:51:09.696896+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/1/entity_id/0": [
        {
          "path": "action/0/choose/1/conditions/1/entity_id/0",
          "timestamp": "2024-07-10T03:51:09.696907+00:00",
          "result": {
            "result": false,
            "state": 83,
            "wanted_state_below": 70
          }
        }
      ],
      "action/0/choose/2": [
        {
          "path": "action/0/choose/2",
          "timestamp": "2024-07-10T03:51:09.697025+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/2/conditions/0": [
        {
          "path": "action/0/choose/2/conditions/0",
          "timestamp": "2024-07-10T03:51:09.697055+00:00",
          "result": {
            "result": false
          }
        }
      ]
    },
    "config": {
      "id": "1669593066842",
      "alias": "Kitchen Main Lights Motion",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.kitchen_motion_sensor_occupancy"
          ],
          "id": "kitchen motion sensor on",
          "from": "off",
          "to": "on"
        },
        {
          "platform": "state",
          "entity_id": [
            "binary_sensor.kitchen_motion_sensor_occupancy"
          ],
          "id": "kitchen motion sensor off",
          "from": "on",
          "to": "off",
          "for": {
            "hours": 0,
            "minutes": 3,
            "seconds": 30
          }
        }
      ],
      "condition": [],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": "kitchen motion sensor on"
                },
                {
                  "condition": "numeric_state",
                  "entity_id": "sensor.kitchen_motion_sensor_illuminance_lux",
                  "below": 70
                },
                {
                  "condition": "time",
                  "before": "22:59:00",
                  "after": "06:00:00"
                }
              ],
              "sequence": [
                {
                  "service": "light.turn_on",
                  "data": {
                    "brightness": 255
                  },
                  "target": {
                    "area_id": "kitchen"
                  }
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": "kitchen motion sensor on"
                },
                {
                  "condition": "numeric_state",
                  "entity_id": "sensor.kitchen_motion_sensor_illuminance_lux",
                  "below": 70
                },
                {
                  "condition": "time",
                  "before": "05:59:00",
                  "after": "23:00:00"
                }
              ],
              "sequence": [
                {
                  "service": "light.turn_on",
                  "data": {
                    "brightness": 78
                  },
                  "target": {
                    "area_id": "kitchen"
                  }
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "trigger",
                  "id": "kitchen motion sensor off"
                }
              ],
              "sequence": [
                {
                  "service": "light.turn_off",
                  "data": {},
                  "target": {
                    "area_id": "kitchen"
                  }
                }
              ]
            }
          ]
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01J2DC8EKYXT7M6GCEKDAN3H8E",
      "parent_id": "01J2DC8EKX2CEBTT1XYN5D1D59",
      "user_id": null
    }
  },
  "logbookEntries": []
}

could you post your automation but properly formatted (like you did for this trace)?

reading the trace, i think the light didn’t turn on because of this:

the trace says:

      "action/0/choose/0/conditions/1/entity_id/0": [
        {
          "path": "action/0/choose/0/conditions/1/entity_id/0",
          "timestamp": "2024-07-10T03:51:09.696815+00:00",
          "result": {
            "result": false,
            "state": 83,
            "wanted_state_below": 70
          }
        }
      ],

meaning that the sensor.kitchen_motion_sensor_illuminance_lux was 83. so it didn’t turn on because it thought things were already bright enough.

Hmmm…yes that does look right, thanks @armedad.

It was definitely dark enough so it’s probably the sensor. I’ll start with the battery and go from there.

Thanks for the help!