Replacing a tasmota socket for a constant W and converting that to kWh

Dear all,

I am breaking my head trying to replace a tasmota measuring socket, into a constant W sensor which then converts to daily kWh.

Setup:
I have a smart meter where I get the continuous electrical usage of my house, I have started monitoring the usage per device, where the only big thing I cannot measure is the induction plates (does anyone have ideas around 3 phase tasmota measurements?)

Anyways, I currently monitor 25 Tasmota sockets, and I realized that some are always measuring the same output, so I wanted to redeploy them and create constants so that I dont miss those measurements.

Eg. the ventilation system of the house is always using 13W hour for a total of 0.333 kWh a day.
I would like to have a sensor showing 13W all the time, and a kWh sensor that starts at 0 at 00:00 in the night, and ends at 0.333 at 23:59:59.

I have created the following test but no luck unfortunately, code compiles etc. I know i still miss the utility meter template for night restart, but the basics are still not in place.

When I look at sensor.total_ventilation_watts I get 13, if I plot it in grafana, I get a nice constant line at 13. However sensor.total_ventilation_kwh shows 0.00. I have tried raising the value from 13 to 20000 so that i would not have to wait for the kWh to start recording, but it doesnt matter. the kWh constant remains at 0.00, even after 12 hours of 20000 W “usage”.

I was hopping you could help. thx!

sensor:

  • platform: template
    sensors:
    total_ventilation_watts:
    value_template: ‘{{ 13 }}’
    friendly_name: ‘Total ventilation Power Use’
    unit_of_measurement: ‘W’

  • platform: integration
    source: sensor.total_ventilation_watts
    name: total ventilation kwh
    unit_prefix: k
    round: 2
    unit_time: s
    method: left

Welcome.

Look at the Shelly EM3. Not Tasmota, but it does local mqtt without the need for re-flashing.

This is because the power sensor is never updating and to perform the integration the integral sensor needs a time interval.

Add a sensor.time entity to your power sensor. This will update it every minute.

platform: template
sensors:
  total_ventilation_watts:
    entity_id: sensor.time
    value_template: '{{ 13 }}'
    friendly_name: 'Total ventilation Power Use'
    unit_of_measurement: 'W'

Also please format your code correctly. That was a pain in the arse to copy and correct. See point 11 here: How to help us help you - or How to ask a good question

Hi Tom,

Thanks so much for your quick reply, and apologies on the formatting.

I will check the Shelly and also with my electrician to see how easy is to replace the current 3phase fuse for this. It looks exactly what I need :slight_smile:

I tried running the code but after 5 minutes the value at kWh remains 0.00.
I have verified that sensor.time is changing every minute, should the integration platform have unit_time minutes?

Thanks again!

sensor:
  - platform: template
    sensors:
        total_ventilation_watts:
        entity_id: sensor.time
        value_template: '{{ 13 }}'
        friendly_name: 'Total ventilation Power Use'
        unit_of_measurement: 'W'
        
  - platform: integration
      source: sensor.total_ventilation_watts
      name: total ventilation kwh
      unit_prefix: k
      round: 2
      unit_time: s
      method: left

Your indentation seems to be a bit off. Try this first:

sensor:
  - platform: template
    sensors:
      total_ventilation_watts: ## This was indented too far see how correct formatting helps?
        value_template: '{{ 13 }}'
        friendly_name: 'Total ventilation Power Use'
        unit_of_measurement: 'W'
        
  - platform: integration
    source: sensor.total_ventilation_watts  ## same here and below
    name: total ventilation kwh
    unit_prefix: k
    round: 2
    unit_time: s
    method: left

Then add back the time sensor if this does not help.

Hi, and thx again for coming back so fast.

I have tried with the new indentation but it made no change. total_ventilation_watts shows 13W (I have now increased it back to 20000) and total_ventilation_kwh remains at 0.

will add back the total_ventilation_watts sensor.