How to use ESP32 DAC output

Hi,
I’m trying to use a DAC output (GPIO25) on my ESP32 via esphome. I have not used a DAC output before. When I use other sensors or switch outputs they automatically turns up in Home Assistant. The yaml file compiles and uploads fine to the ESP, but how shall I write values to the DAC output? It never shows in HA.

Here is my .yaml file:

esphome:
  name: brewpot
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: "MYWIFI"
  password: "wifipassword"

captive_portal:
spi:
  miso_pin: GPIO19
  mosi_pin: GPIO23
  clk_pin: GPIO18

sensor:
  - platform: max31865
    name: "Return Temperature"
    cs_pin: GPIO5
    update_interval: 1s
    id: tank_temp
    reference_resistance: "430 Ω"
    rtd_nominal_resistance: "100 Ω"

output:
  - platform: esp32_dac
    pin: GPIO25
    id: induction_power

switch:
  - platform: gpio
    name: "induction_on"
    pin: GPIO15
    id: relay

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

There is an example usage in the docs

on_...:
  then:
    - output.set_level:
        id: dac_output
        level: 50%

Thanks for your input. I guess my fist problem is that I’m new to esphome and more advances usage. I will try to get things in place in steps. First step would be to just set the dac to some different values.

In many example, as yours, it says “on_…”, but I have not found any example of what the “…” shall be set to. I guess it relates to an action?

So, if I want a simple push-button in the Gui, where shall I start? Someone that is used to esphome and HA that could point in any direction?

My goal is to have a slider in HA gui which controls the DAC from 0 to 100%.

This is what I’m using for esp32-dac:

[snip]
substitutions:
  devicename: esp32_xyz
  upper_devicename: "esp32 XYZ"

output:
  - platform: esp32_dac
    pin: GPIO25
    id: dac_output1
    min_power: 0.07
    #max_power: something
  - platform: esp32_dac
    pin: GPIO26
    id: dac_output2

light:
  - platform: monochromatic
    output: dac_output1
    name: "$upper_devicename DAC1"
    gamma_correct: 2
    id: dac_light1
  - platform: monochromatic
    output: dac_output2
    name: "$upper_devicename DAC2"
    id: dac_light2

So, you are missing the light component

1 Like

Now I finally get control over the dac output. ferbar, your pointer towards the light component confused me a bit. It was not needed to control the DAC output. Below is my final setup:

ESPHome:

esphome:
  name: brewpot
  platform: ESP32
  board: nodemcu-32s

wifi:
  ssid: "MYWIFI"
  password: "wifipassword"

captive_portal:

output:
  - platform: esp32_dac
    pin: GPIO25
    id: induction_power

# Enable logging
logger:

# Enable Home Assistant API
api:
  services:
    - service: set_dac_value
      variables:
        dac_value: int
      then:
        - output.set_level:
            id: induction_power
            level: !lambda 'return dac_value / 100.0;'
ota:

configuration.yaml

input_number:
  brewpot_power_control:
    name: Induction power
    initial: 0
    min: 0
    max: 100
    step: 1
    mode: slider

automations.yaml

- id: '1608937364121'
  alias: Write output value to esp32 DAC
  description: ''
  trigger:
  - entity_id: input_number.brewpot_power_control
    platform: state
  condition: []
  action:
  - service: esphome.brewpot_set_dac_value
    data_template:
      dac_value: '{{ trigger.to_state.state | int }}'
  mode: single