Energy Management in Home Assistant

Daily or Total consumption (energy, kWh) would work. Current Consumption is instantaneous power (in Watts) and not suitable, it shouldn’t show up as a choice in the energy configuration.

It depends whether you mean consumption as a an abbreviation for “rate of consumption” or as “total consumed”.

Anyone know how to support Tuya switch with energy consumption? To integrate into ‘energy’

Integrate the power to kWh and add the needed attributes.

Thanks! Do you have any examples of how it should look?

This thread has examples. Read through it :slight_smile:

In the screenshot you can see that the current consumption is in W and the daily and total consumption are in kWh.

Use Total. Daily resets daily and can produce negative values.

1 Like

Will be fixed with next release Add support for total and total_increasing sensor state classes by emontnemery · Pull Request #54523 · home-assistant/co it makes the last reset value obsolete.

1 Like

Hi Mark, thanks for answering so quickly. Unfortunately I do not understand your suggestion. If a template sensor does not work, why would a derived template sensor work ? Could you point to a specific example that will work please ?
One existing sensor I have, that is not available for selection under energy, is:

  - trigger:
    - platform: template
      value_template: >
        {{ '1-0:1.8.2' in states('sensor.energy_meter_serial') }}
    sensor:
      - name: "Energy rate 2 import acc"
        device_class: energy
        state_class: measurement
        unit_of_measurement: "kWh"
        state: >
          {{ states('sensor.energy_meter_serial').split("(")[1].split("*")[0] | float }}

My (maybe mis-) understanding is that old style templates will not work, new-style will.

Sorry @nickrout try this:

Make sure you configuration.yaml has the following structure - where you have template: as a main heading and then sensor can refer to your otherwise working sensor. Have a look at what I have below, but as far as the state bit which I have put in, I am not sure that is right for you (if you weren’t awre, you can use the dev tools - template to tinker until you have it right), in my setup, the template url is http://hassio.lan:8123/developer-tools/template

template:
  sensor:
    - name: "Energy Imported"
      unit_of_measurement: 'kWh'
      device_class: energy
      state_class: measurement
      state: '{{ states('sensor.energy_meter_serial').split("(")[1].split("*")[0] | float }}'
      attributes:
          last_reset: '2018-08-06T00:00:00+00:00'

Hi Mark,
That attributes line did the trick, it works now (I think, no data visible yet) Many thanks!

  • Marcel
1 Like

template:

  • sensor:
    • name: “Solar energy kwh”
      unit_of_measurement: “kWh”
      state_class: measurement
      device_class: energy
      state: >
      {% set phase1 = states(‘sensor.inverter_energy_kwh’) | float %}
      {% set phase2 = states(‘sensor.motor_energy_kwh’) | float %}
      {% set phase3 = states(‘sensor.electric_energy_kwh’) | float %}
      {{ float(phase1) - (float(phase2) + float(phase3)) }}
      attributes:
      last_reset: ‘2021-08-14T00:00:00+00:00’

it working for me
add
attributes:
last_reset: ‘2021-08-14T00:00:00+00:00’

im using tasmota counter on sonoff basic 2
with integration with home assistant
gpio’s and ground connected to ( S0 output ) of my energy meter ( 1600 imp per kWh)


that give the number of impulse per kWh.

then add a template sensor for kwh in configuration.yaml
template:

  • sensor:
    • name: “Inverter energy kwh”

    friendly_name: “inverter Energy (Total)”

    unit_of_measurement: "kWh"
    state_class: measurement
    device_class: energy
    state: "{{ ((states('sensor.tasmota_counter_c1')|float ) / 1600)| round(2) }}" # 1600 is standard for myenergy meter 
    attributes:         
      last_reset: '2021-08-14T00:00:00+00:00'

That’s great, it is a very common problem in this thread, a bit of added documentation would go a long way. It think I read elsewhere in this thread that there is a patch coming which rectifies it?

If you still have no stats, look elsewhere in this thread for my post where I backtracked how the stats are stored via the statistics engine.

with all respect, i to have been struggling with these same tuya plugs since the beta. ~2 weeks now.

power

sensor.tyeb64922f70898d728browd_2 is the Smart Plug_power in W

sensor:


- platform: integration
  source: sensor.tyeb64922f70898d728browd_2
  name: my_ac_energy_spent
  unit_prefix: k
  unit: kWh
  method: left
  round: 2

utility meter:

my_ac_daily:
  source: sensor.my_ac_energy_spent
  name: My Daily AC Energy
  cycle: daily

This seems to be almost right.

Heres the problem though. Changing the values of

  unit_prefix: k
  unit: kWh

Dont make a difference. see here:

power2

- platform: integration
  source: sensor.tyeb6dd24260219cc056buyi_2
  name: cooler_energy_spent
  unit: W
  method: left
  round: 2
cooler_daily:
  source: sensor.cooler_energy_spent
  name: Cooler Daily Energy
  cycle: daily

Now if I open core.restore_state in .storage. I still see…

           "state": {
                "entity_id": "sensor.cooler_energy_spent",
                "state": "14768.19",
                "attributes": {
                    "state_class": "measurement",
                    "last_reset": "1970-01-01T00:00:00+00:00",
                    "source": "sensor.tyeb6dd24260219cc056buyi_2",
                    "unit_of_measurement": "kWh",
                    "friendly_name": "cooler_energy_spent",
                    "icon": "mdi:chart-histogram",
                    "device_class": "energy"

and

           "state": {
                "entity_id": "sensor.cooler_daily_energy",
                "state": "1.63",
                "attributes": {
                    "state_class": "measurement",
                    "last_reset": "1970-01-01T00:00:00+00:00",
                    "source": "sensor.cooler_energy_spent",
                    "status": "collecting",
                    "last_period": "4.58",
                    "meter_period": "daily",
                    "unit_of_measurement": "kWh",
                    "friendly_name": "Cooler Daily Energy",
                    "icon": "mdi:counter",
                    "device_class": "energy"

Sorry for the long post, But no matter what I chage it to in the integration it does not change the entity value.

However, if I edit the file in .storage (i know i know)… it does work, hence the first My Ac at the top of this post…

Not sure if its a bug transitioning from the beta? Ive never been able to get to work with those plugs, except since i messed around in .storage…

cooler_energy_spent appears like its in W but with kWh unit… it should be much, less than the AC one, it uses 1/3 of the ammount of power

There was a post somewhere about transitioning from the beta. Maybe this thread or the 2021.8 release thread.

1 Like

thanks ill have a look.

Another request for Tesla here please?