ESPHome get lux on motion

I have an esp8266 multi sensor with motion/temp/hum/lux connected to HA via esphome and I need to build an automation based on movement and light level.

Currently I have the lux reading coming in every 10 seconds. Is it possible to make the sensor send a lux reading whenever motion is detected? That way I can set the interval to once an hour and not poll constantly.

The lux sensor

  - platform: adc
    pin: A0
    name: "Kitchen LUX"
    unit_of_measurement: lx
    update_interval: 10s
    filters:
      - lambda: |-
          return (x / 10000.0) * 20000000.0;

Wrong catagory. Moved.

You need to use this: https://esphome.io/guides/automations.html#component-update-action

So you add to your PIR sensor something like this:

on_press:
  then:
    - component.update: lux_sensor

Assuming your motion sensor is binary and you set the id of your lux sensor to lux_sensor.

Something like this in the yaml of the node?

sensor:
  - platform: adc
    pin: A0
    name: "Kitchen LUX"
    unit_of_measurement: lx
    update_interval: 10s
    filters:
      - lambda: |-
          return (x / 10000.0) * 20000000.0;
          
binary_sensor:
  - platform: gpio
    pin: D5
    name: "Kitchen PIR Sensor"
    device_class: motion
    on_press:
      then:
        - component.update: lux_sensor

Still not sure what value to put in for the lux_sensor though

Just add the id to the adc sensor like this:

sensor:
  - platform: adc
    pin: A0
    id: lux_sensor
    name: "Kitchen LUX"
    unit_of_measurement: lx
    update_interval: 10s
    filters:
      - lambda: |-
          return (x / 10000.0) * 20000000.0;
          
binary_sensor:
  - platform: gpio
    pin: D5
    name: "Kitchen PIR Sensor"
    device_class: motion
    on_press:
      then:
        - component.update: lux_sensor

Perfect, works great, thanks :slight_smile:

1 Like