ESP32 LEDC - Controlling an analog meter as output

How do I convert readings from a tempearture sensor to a level to use in LEDC?

- platform: ledc
  pin: GPIO16
  id: gpio_16

sensor:
  - platform: homeassistant
    name: "Garden temperature"
    id: gdntemp
    entity_id: sensor.espresense_garden_ds18b20_temperature_1
    on_value:
      then:

The meter reads from 0 to 30. What do I put after the “then:” to get the temperature data from a sensor entity into the LEDC level, so that the meter shows the temperature?

LEDC = output

Or if its a other changing signal → ADC would be the keyword
with an ADC / or DS18B20 both might supply more than 3,3v on the pin connected to ESP … therefore they advise resistors inbetween Data out and ESP… (voltage divider)

good luck!

Sorry I should have clarified! I’m terrible at explaining things… I already have sensors set up with ESPresense, so the temperature data I want to display on the meter is in the entity “sensor.espresense_garden_ds18b20_temperature_1”.

I want to get the value from that entity, which I think I should divide by 30 and multiply by 100… I’m after the actual YAML (is it a lambda?) code I use so that that number can then go into the set_level.

In the LEDC example:

   - output.set_level:
        id: buzzer
        level: "50%"

Instead of “50%” I want to use the value from the temperature entity.

Here is what works, I am using resistors between the meter and the ESP32 output pin:

output:
- platform: esp32_dac
  pin: GPIO26
  id: gpio_26

sensor:
  - platform: homeassistant
    name: "Garden temperature"
    id: gdntemp
    entity_id: sensor.espresense_garden_ds18b20_temperature_1
    on_value:
      then: 
        - lambda: |-
           auto temperature = id(gdntemp).state;
           auto level = (temperature / 30);
           id(gpio_26).set_level(level);
1 Like