Got energy monitor working but do not know enough code to get a calculation done

Dearest community .
I was following this two guide for an energy monitor.
https://www.makeuseof.com/how-to-build-a-diy-household-energy-monitor-using-esp8266/

and after some tweaking i think i got the values correct on the lovelace card and the log.
Screenshot from 2022-06-05 20-10-21

But i would like it to display WATTS. As you know amps = watts ÷ volts
But i dont know enough code to make it display. I just broke the code too many times already
Any kind soul that could help me or point me in the right direction?
This it the part I am using in ESPHOME

captive_portal:
sensor:
  - platform: ct_clamp
    sensor: adc_sensor
    name: "Measured Current"
    update_interval: 5s        #You may change this value (in seconds)
    id: measured_current       #Measured in ampere (I)
    filters:
    - calibrate_linear:
          - 0 -> 0
          - 0.49 -> 11.82

  # Example source sensor
  - platform: adc
    pin: A0
    id: adc_sensor
    
  - platform: total_daily_energy
    name: "Total Daily Power Usage"
    power_id: my_power

  - platform: template
    id: my_power
    name: "Measured Power"
    lambda: return id(measured_current).state * 125 / 1000; #Power = V*I/1000. So change 230V to whatever your mains voltage is)
    unit_of_measurement: 'kW'
    update_interval: 5s        #You may change this value (in seconds)

time:
  - platform: sntp
    id: my_time

all pointers are greatly appreciated.

You want measured Power to be in W, not kW? Just take out the division by 1000 and change the unit of measurement to W.

1 Like

damn i totally missed that. That was sad. Must have run out of caffeine.

Abusing of your kindness . I need to make this 2 phase. Could i just copy paste , change the names and use another ADC pin?

Yes and No.

The esp8266 only has one ADC. see Analog To Digital Sensor — ESPHome

Solutions:

  1. use an external ADC - there are several mentioned ESPHome — ESPHome ; or

  2. Use an esp32.

Thanks i forgot to mention I am using a 38 pin esp32 I was able do double the cirtcuit and code.
Im going to try and put 8 clamps on it. thanks for the pointers.

1 Like