ML8511 sensor conversion

Im trying to make a small sensor with a nodmcu lolin V3 that can measure light (for automation) and the UV, to know how much sun there is and calculate the mW/cm^2. So the light sensor was a brease and have it working with ESPHome without any hicups, but the UV sensor is another story.
Seems ESPhome doesnt have a sensor specific for it (the ML8511 sensor) wich means i need to do this via arduino code (C++), so my question is can i make a costum sensor with all the code i need to convert the voltage reading (from ML8511) to mW/cm^2 without using arduino code?

Here is the code i have currently (i can see the voltage reading from the uv sensor) in ESPhome:

esphome:
   name: solar-sensor
   platform: ESP8266
   board: nodemcuv2
 
 /# Enable logging
 logger:
 
 /# Enable Home Assistant API
 api:
 
 ota:
   password: "8a6e8e7d3263e0b03992f19297e31f9f"
 
 wifi:
   ssid: "AKIWIFI 44710"
   password: !secret wifi_password
 
  / # Enable fallback hotspot (captive portal) in case wifi connection fails
   ap:
     ssid: "Solar-Sensor Fallback Hotspot"
     password: "XXXXXXXXX"
 
 captive_portal:

 /# I2C Lumen sensor
 i2c:
   sda: GPIO4
   scl: GPIO5
   scan: true
   id: bus_a
 
 /# Example configuration entry
 sensor:
   - platform: bh1750
     name: "BH1750 Illuminance"
     address: 0x23
     measurement_duration: 69
     update_interval: 20s
     
   - platform: adc
     pin: A0
     name: "UV Read"
     update_interval: 10s
     filters:
      - multiply: 3.3

I want to use the code given by this website on my uv sensor:
https://www.esp8266learning.com/wemos-ml8511-example.php

Thanks in advance!

any news about this sensor?

I believe you do not need C++ code here. First, your ESP will give you values between 0 and 1 on the adc sensor. All you need to do is to interpolate it to UV intensity. Luckily, the characteristics of the UV sensor is almost linear, so you can use something like this (sorry, not tested). Get yourself the datasheet and check my math :slight_smile:

Note, this is based on the default esp8266 behaviour. If you have a dev board as D1 mini, the ADC could give a different value range so the calibration would look different

  - platform: adc
    pin: A0
    name: "UV"
    update_interval: 10s
    unit_of_measurement: "mW/cm2"
    accuracy_decimals: 1
    filters:
    - calibrate_linear:
      # Map 0.0 (from sensor) to 0.0 (true value)
      - 0.3 -> 0
      - 0.85 -> 15