Skip to content

Support for ADC-based ambient light sensor #10

@szupi-ipuzs

Description

@szupi-ipuzs

Based on my tests (as I mentioned in libretiny-eu/libretiny#219), the mere existence of one of the keys: 'day', 'dusk', 'evenfall', 'evening' and 'night' suggest that there's an ADC-based ambient light sensor. There seem to be no configuration of ADC in UPK, but all of my 3 kind of lamps that have this use the same setup, which can be expressed in esphome yaml like this:

sensor:
  - platform: adc
    id: ambient
    name: Ambient
    unit_of_measurement: "V"
    state_class: "measurement"
    pin: P23

And the keys can be expressed as esphome select like this:

globals:
  - id: light_sensitivity
    type: int
    restore_value: no
    initial_value: '0'

select:
  - platform: template
    id: light_sensitivity_setting
    name: "Ambient light trigger"
    entity_category: config
    restore_value: yes
    options:
     - "Day"
     - "Dusk"
     - "Evenfall"
     - "Evening"
     - "Night"
    initial_option: "Evenfall"
    optimistic: true
    set_action:
      - logger.log:
          format: "Chosen option: %s"
          args: ["x.c_str()"]
    on_value:
      then:
        lambda: !lambda |-
          if (i == 1)
          {
            id(light_sensitivity) = 0.157f;
          }
          else
          if (i == 2)
          {
            id(light_sensitivity) = 1.800f;
          }
          else
          if (i == 3)
          {
            id(light_sensitivity) = 2.100f;
          }
          else
          if (i == 4)
          {
            id(light_sensitivity) = 2.180f;
          }
          else id(light_sensitivity) = 0.0f;

The above thresholds are taken from UPK itself of course.

My python knowledge is yet too basic to try the pull request, so I'm leaving this to someone else to try :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions