Dynamically change the value of DAC

To minimize the electricity that I inject to the net, I want to build a load that I can steer with the DAC from an ESP32. I developed the hardware but I have a problem to adjust the DAC output level of the ESP. No matter what I try, the compiler keeps throwing errors. Here is the code that I try to get compiled. Any help is very welcome:

output:
  - platform: esp32_dac
    pin: GPIO25
    id: dac_output
    inverted: false

globals:
  - id: verbruikslevel
    type: float
    restore_value: no
    initial_value: '0.0'

# Enable Home Assistant API
api:
  encryption:
    key: "WHfbz9wfDg+HYgyMTDEpNE/prIcerI8Ix7PT5x2r9no="

  actions:
    - action: verhoog_verbruik    
      then:
        - lambda: |-
                  id(verbruikslevel) = id(verbruikslevel) + 0.1;
        - output.set_level:
            id: dac_output
            level: |- 
                  id(verbruikslevel)

Yet you don’t show us the compiler errors.

1 Like

I solved it in the meantime using Copilot. the last part of the action should be:

    - output.set_level:
        id: dac_output
        level: !lambda 'return (float)id(verbruikslevel);'

Thanks for looking in to this.

Eric