Why isn’t an automation working?

The following was copied directly from automations.yaml. Note that this automation was entered via the HA interface, but even though I did that, I clicked on Automations under ‘YAML configuration reloading’ on the Developer Tools page.

- id: <number>
  alias: testlux
  description: ''
  trigger:
  - type: illuminance
    platform: device
    device_id: <number>
    entity_id: sensor.light_level
    domain: sensor
    below: 10
  condition: []
  action:
  - type: turn_on
    device_id: <number>
    entity_id: switch.testdev_basement_switch
    domain: switch
  mode: single

Legit question: was is the sensor value? I went to the sensor’s tab on the ESPHome page and clicked Logs. Here is some data:

INFO Reading configuration /config/esphome/luxsensor.yaml...
[23:57:11][C][bh1750.sensor:118]: BH1750 'Light Level'
[23:57:11][C][bh1750.sensor:118]:   Device Class: 'illuminance'
[23:57:11][C][bh1750.sensor:118]:   State Class: 'measurement'
[23:57:11][C][bh1750.sensor:118]:   Unit of Measurement: 'lx'
[23:57:11][C][bh1750.sensor:118]:   Accuracy Decimals: 1
[23:57:11][C][bh1750.sensor:119]:   Address: 0x23
[23:57:11][C][bh1750.sensor:124]:   Update Interval: 90.0s
[23:57:53][D][bh1750.sensor:159]: 'Light Level': Got illuminance=5.8lx
[23:57:53][D][sensor:124]: 'Light Level': Sending state 5.77264 lx with 1 decimals of accuracy
[23:59:23][D][bh1750.sensor:159]: 'Light Level': Got illuminance=5.2lx
[23:59:23][D][sensor:124]: 'Light Level': Sending state 5.20669 lx with 1 decimals of accuracy

I know that switch.testdev_basement_switch works as expected because I created an automation to turn the switch on after a specified time and that worked as expected.

Why the heck isn’t this automation working???

?

Is this really your device_id?

No it’s just unnecessary redaction.

Try this trigger instead:

trigger:
  - platform: numeric_state
    entity_id: sensor.light_level
    below: 10

Keep in mind that the light level has to transition from above 10 to below 10 for the automation to trigger. e.g It will not trigger when going from 9 to 8.

Thank you - that worked. Also thanks for sharing the info about the transition - wasn’t ware of that.

More trouble, ugh. I modified the automation to be more like what I want:

- id: '1653576529407'
  alias: testluxauto
  trigger:
  - platform: time
    at: '14:55:00'
  condition:
  - condition: time
    after: '14:55:00'
  - condition: numeric_state
    entity_id: sensor.light_level
    below: '10'
  action:
  - type: turn_on
    entity_id: switch.testdev_basement_switch
    domain: switch
  mode: single

I waited until after 2:55 pm and until I saw the value for sensor.light_level change in the log, at which point I darkened the sensor. I saw the value change in the log, but the switch never turned on. Now what am I doing wrong???

That will only fire exactly at 2.55 if both conditions are true.

What you could do is change just the trigger in your above example to be

trigger:
  - platform: state
    entity_id: sensor.light_level

This will trigger every time the light level changes but only fire the automation when after 2.55 and the light level is below 10

That worked - thanks!
So that I can stop annoying this helpful community with silly questions: Can you point me to some ‘document’ that describes automatons, etc. in detail so that I can try to learn this stuff myself?

The basics can be found here: Understanding Automations - Home Assistant

Once you understand that, automations are a matter of thinking through the trigger and conditions in a logical way. There will always be quirks and I find most of my solutions in old posts on the forum.