I want to use an ESP32wroom to read the export PV-power readings (in Watts) from my Myenergy Zappi and to convert that onto an output pin in the 0-3,3Volts range. Then I will convert the 0-3,3V output into a 1-10V output (many diagrams available for that) to drive a voltage regulated module for my electric boiler.
On top of that I would like to be able to use a button(switch) in HA to switch the (same) PIN to 0 or 3,3V to disable or boost the boiler for vacation or several cloudy days without sufficient PV power.
Presently I have a mechanical solution for that but would like to replace that with an ESP solution. Could somebody provide me a YAML-code because I have tried PWM, ADC etc but can’t get it to work and I am not so much into software. I am sure you’re not only helping me.
Well you could probably use this integration in home assistant, then import it into esphome.
Import via one of these
Thx Nickrout,
The best configuration I got sofar was the one underneath. However, if I look at the logs the shown result is pretty much correct but if I messure the ADC-pin (25) the voltage is 3,3Volts constantly.
sensor:
- platform: homeassistant
name: "Power Sensor"
entity_id: sensor.myenergi_zaptas_power_ct_grid
id: power_sensor
on_value:
then:
- lambda: |-
float voltage = (x /4000.0) * 3.3;
int dac_value = (int)(voltage / 3.3 * 255.0);
ESP_LOGD("main", "Setting DAC value: %.2f V (%d)", voltage, dac_value);
id(dac_output).set_level(dac_value);
# DAC (Digital-to-Analog Converter) Output
output:
- platform: ledc
pin: GPIO25
frequency: 60 Hz
id: dac_output
min_power: 0%
max_power: 100%
The log shows:
[20:22:48][D][sensor:094]: ‘Power Sensor’: Sending state 1037.00000 with 1 decimals of accuracy
[20:22:48][D][main:057]: Setting DAC value: 0.86 V (66)
I guess I have to add something more to get the rerading 0,86V on pin25 instead of the constant 3,3V I measure with the multimeter.
2 comments
-
The above multiplies by 3.3 and in the next line divides by 3.3. That doesn’t make much sense.
-
What was the value of sensor.myenergi_zaptas_power_ct_grid at this point?
In my earlier message I pasted the log-info but now I see that it is missing the Watts indicator. The sensor in that message shows 1037 Watts and the ESP calculates that into a voltage of 0,86Volts which could be fairly correct. The issue is that the log shows the right value but the GPIO pin does not output that 0,86V value. The GPIO pin is constantly 3,3V (almost). While rebooting the ESP the multimeter shows 0,0Volts for a brief moment and than 3,3Volts so we could say that the pin is “active”, at least something happens.
I expect DAC set_level is a float between 0 and 1 (0-3.3V).
Never tried though…
Just quickly try:
id(dac_output).set_level(0.5);
to see if you get ~1.65V
Ok, so I’ve set the value to 0,5 and indeed the output on GPIO25=1,61 Volts.
The log still shows the relative value of the sensor.
[13:27:45][D][homeassistant.sensor:024]: ‘sensor.myenergi_tachoires_power_export’: Got state 422.00
[13:27:45][D][sensor:094]: ‘Power Sensor’: Sending state 422.00000 with 1 decimals of accuracy
[13:27:45][D][main:063]: Setting DAC value: 0.35 V (26)
So my guess is that the ESP sets the value to 0,35V (correct) but doesn’t output the value accordingly to the GPIO25 pin.
I found the problem.
I changed the code into:
on_value:
then:
- lambda: |-
float voltage = (x / 4000.0) * 3.3; // Calculate voltage based on input
float dac_normalized = voltage / 3.3; // Normalize to 0.0 to 1.0
ESP_LOGD("main", "Setting DAC value: %.2f V (%.2f)", voltage, dac_normalized);
id(dac_output).set_level(dac_normalized);
and now I get the GPIO pin outputing the same voltage as the log registrates.
That hurdle is taken. Thx for you help.