Voltage value range sets "day" or night"?

Hi everyone!

Just looking for a pointer in the right direction.

I have a photo transistor connected to an adc pin on an esp32 devboard. It sends a voltage value based on the amount of light it receives. 0-0.5V in the dark and 1.0-3.9V in bright light. For future automations, I’d like to eval these voltage ranges to report “day” or “night”. Is this possible, or do I just hard code these ranges within future automations?

Assuming that you want to do this in ESPHome (so not in Home Assistant) an option to try is: create a Select Template that can be in one of three states, and add some on_value_range select to your ADC sensor:

# Select setup
select:
  - platform: template
    name: "Time of day"
    id: tod
    optimistic: true
    options:
      - night
      - dusk
      - day
    initial_option: dusk

# ADC Sensor with range selections
sensor:
  - platform: adc
    pin: A0
    name: "Living Room Brightness"
    update_interval: 5s
    on_value_range:
      - above: 0.5
        below: 1.0
        then:
          - select.set:
              id: tod
              option: "dusk"
      - below: 0.5
        then:
          - select.set:
              id: tod
              option: "night"
      - above: 1.0
        then:
          - select.set:
              id: tod
              option: "day"

The state of this Select Template can then be used further in automations.

1 Like