Custom Component: IoTaWatt Energy Monitor integration

Thanks for the info. That makes more sense, and adding that allowed me to add it to the energy config. I’ll try this out a bit more, but may go back to the hacs version since I do like the auto-configured sensors. Less yaml config is better imo. Thanks for the info and all the work!

1 Like

I’m hoping to release the updated HACS integration (0.2.0) that supports HA 2021.9 in a day.

It’s available as a Pre-Release, so you have to do some extra steps to install it but in my setup running HA 2021.9.0 with Inputs and Outputs (no solar) I am getting data just need to wait and see if the Energy Dashboard gets updated

2 Likes

Might wait for that then…

Hi @gregtd

On the Iotawatt forum I described the same approach as the one you describe above, for configuring Iotawatt and HA Energy in the case of solar panels.
The post has screenshots for all steps.
Hope this is an added value. Don’t hesitate to use this in documentation if you want.

Link: Home Assistant Energy - Return to grid not working - #10 by michaelpiron - Support - IoTaWatt User Community

3 Likes

The next version of the HACS version will bring back the ability to edit the output sensors.
In order to update to this version without having to delete sensors and rename new ones following the following steps as per the pull request:

The HACS version has the advantage in that you don’t need to combine it with the Riemann Sum integration you can directly use the sensors with the energy screen and the results will be much more accurate than those obtained via integration (including the ability to retrieve data the iotawatt collected while HA was offline or when connectivity between the HA and the iotawatt got interrupted)

If the iotawatt sensors you use are negative (like solar or export typically would) you can use a template sensor to calculate the absolute value like so:

- platform: template
  sensors:
    solar_wh_accumulated_abs:
      friendly_name: "Solar Energy"
      unit_of_measurement: Wh
      device_class: energy
      value_template: "{{ states('sensor.solar_wh_accumulated')|float|abs }}"
      availability_template: "{{ states('sensor.solar_wh_accumulated') not in ['unavailable', 'unknown', 'none' ] }}"
      attribute_templates:
        state_class: "{{ state_attr('sensor.solar_wh_accumulated', 'state_class') }}"

Note the use of the availability_template above, it’s required as otherwise during a restart, if the template runs before the source sensor is available it will read 0 which is utterly confuse the energy screen (see https://github.com/home-assistant/core/issues/55630 which apparently will never be fixed :frowning: )

1 Like

Just a question, as someone who made the change to the “official” integration and is now regretting/debating switching back. Why are the two not functionally the same with regards to things like the need for the Riemann sum? The only reason I had switched was because I had assumed that it was the same and that the official one would be the way to go in the future. This was also the first time I had used HACS, so I’m sorry if this is a common thing that happens when integrations go from HACS->HA and I didn’t realize.

EDIT: To be clear, I was assuming that the maintainer of the HACS plugin would be the one maintaining it for the HA integration and that the codebases would be pretty much the same (maybe with some lagtime on the HA side while changes are pending a merge)

2 Likes

That is the case.
And now the one in HACS is 99% identical to the one in the HA tree.

Having to use the riemann sum integration is an unfortunate consquence of the main HA developer making a nonsensical last minute change attempting to get around limitation of their energy code. That last one is very fragile in dealing with data it can’t understand. It’s very easy to completely mess it up and completely screw your history.

I have attempted to open bugs about it, but they were dismissed with a resolution akin to “you’re holding your phone wrong”

You can go from HA to HACS easily and not lose your data or history. Uninstall the integration in HA ; restart. Install the HACS module , re-install the integration (they have the same name) and that is it.

I have three phase power at the house and single phase solar. Just want to confirm the best way to go with setting up sensors for the energy dashboard since the latest changes to the integration and since this post Custom Component: IoTaWatt Energy Monitor integration - #113 by jyavenard

Firstly I assume I need to use the ACCUMULATED sensors for the dashboard?

Second, is it best to get the IotaWatt to do the calcs or HA? For example, for total consumption should I setup an output for PhaseA+PhaseB+PhaseC (and then use the provided accumulated sensor) or do that in HA?

For grid export I assume that has to be done in HA as I need to only count it if the total is negative but I am thinking I need to use the watts sensors in this case and then send it to an integration sensor?

The best would be to place the solar CT in a way that the main phase CT aren’t impacted by it.

So imagine the following diagram
CB is circuit breaker
CT is current transformer

Main CB (3 phases)
  A   B   C
  |   |   |____CB__CT4__SOLAR
  CB  CB  CB
  |   |   |
  CT1 CT2 CT3
  |   |   |

That your main usage is CT1+CT2+CT3
And Import output is (CT1+CT2+CT3-CT4) max 0
and Export output is ((CT1+CT2+CT3-CT4) min 0) ABS

If you want to use the individual energy counters for CT1, CT2, CT3 and CT4 ; you don’t have to use accumulated.

For Import and Export you do need to use the Accumulated energy counter.

Note that this assumes you use the HACS version; with the official HA iotawatt integration, only the “Accumulated” sensor are usable for the energy screen (which is super silly)

How you define your outputs in the iotawatt will depend on how you setup your CT
The diagram I present above makes it the easiest to calculate solar vs consumption individually; and what I recommend you do

Thanks. Fortunately my setup is as you have described! So I think from what you have written the sensors will be:

      - name: "Grid Consumption"
        unit_of_measurement: "Wh"
        state_class: "total_increasing"
        device_class: "energy"
        unique_id: grid_consumption
        state: >
          {{ ((states.sensor.phasea_wh_accumulated.state | float
             + states.sensor.phaseb_wh_accumulated.state | float
             + states.sensor.phasec_wh_accumulated.state | float
             - states.sensor.solar_wh_accumulated.state | float) | max(0)) | abs
          }}
            
      - name: "Return to Grid"
        unit_of_measurement: "Wh"
        state_class: "total_increasing"
        device_class: "energy"
        unique_id: return_to_grid
        state: >
          {{ ((states.sensor.phasea_wh_accumulated.state | float
             + states.sensor.phaseb_wh_accumulated.state | float
             + states.sensor.phasec_wh_accumulated.state | float
             - states.sensor.solar_wh_accumulated.state | float) | min(0)) | abs
          }}

which is different to what you described here Custom Component: IoTaWatt Energy Monitor integration - #91 by jyavenard I think because the integration is supplying the accumulated totals now so integration is not required and since I have to make a new sensor anyway to do the abs then I thought I would dispense with the iotawatt sensor that you created. Is this all ok?

This will not work, at all.

You are doing the calculation on the total values since the recording started. Export will read 0 pretty quickly

It must be done on the iotawatt or you need to use the integration on the power values.

If you do the ABS calculation on the iotawatt also, you don’t need to worry about setting the state_class.

There’s no need to run abs on “Grid Consumption” as it will always be positive (minimum is 0)

The other issue here is that if the iotawatt isn’t responsive ; those two sensors will read 0 which will completely mess up the Energy screen; so at the very least add
availability_template: "{{ states('sensor.solar_wh_accumulated') not in ['unavailable', 'unknown', 'none' ] }}"
to your sensor template

No happy to do the calc on the iotawatt just trying to work out what is best. So what you have written in Custom Component: IoTaWatt Energy Monitor integration - #91 by jyavenard is still the way to do it? Except now you don’t need the integration because the accumulated sensor will be generated automatically?

So all I have to do then is on the IotaWatt set up two outputs:
grid_consumption = (PhaseA + Phase B + Phase C - Solar) max 0
grid_export = (PhaseA + Phase B + Phase C - Solar) min 0 abs

Is that it?

yes, assuming the Solar input is configured to return a positive value.

The post you quoted was required at the time I wrote it. Since then iotawatt HA integration has received a major overall that made most if it unnecessary.

You create the outputs as you’ve written; in HA a grid_consumption_wh_accumulated and grid_export_wh_accumulated will automatically be created which you can directly use in the energy config.

For the solar, you can use either solar_wh or solar_wh_integrated ; personally I would use solar_wh_integrated because this value only ever increase, while the solar_wh is that amount of energy produced since the beginning of the current year and will reset on January 1st every year. I don’t know how well the energy screen will handle that, in theory it should.

Thanks. It would appear to me that the energy dashboard use of the term “grid consumption” is not really correct for those who export. I think it really should be “house consumption” because when I am exporting my GRID consumption is zero?

My solar was showing as negative but I had my sensors around the wrong way so it is now positive and my PhaseB goes negative when I am generating anything signficant. So my IotaWatt sensors as I see it should be:
grid_consumption = (PhaseA + Phase B + Phase C + Solar) max 0
grid_export = (PhaseA + Phase B + Phase C + Solar) min 0 abs

I am currently pulling the solar from Pvoutput as I have for many years been uploading my generation data to there. I am debating whether to switch to what IotaWatt is sensing. My inverter is showing about 100W more than IotaWatt. Not sure which is more correct.

P.S. I think you meant sensor.solar_wh_accumulated ?

That’s right. Grid consumption is what you purchase, if you’re exporting, you’re not drawing from the grid

If solar is positive, then why changed to an addition? With that export will always be 0 as min(0, anything positive) is always zero

If CT_B may read negative, then what you wired isn’t as I described above nor what you confirmed earlier. The outputs must be defined completely differently. As phaseB CT reads now consumption_phase_b-solar and is signed (make sure to configure that in the settings)

So consumption_phase_b = (SOLAR+CT_B) max 0
Your export is now (CT_A+CT_B+CT_C min 0) abs
Import is (CT_A+CT_B+CT_C) max 0

You should move this discussion to the iotawatt forum

What wiring did they use? Too thin and you have voltage losses?
Or is your voltage sensor not properly calibrated?

You need to measure with a voltmeter and adjust accordingly, otherwise everything will read under

First post so I hope the image and code blocks work.
Running HA 2021.9.6
HACS IoTaWatt Integration 0.2.1

I have been struggling with this setup for a few days now. I have read this post and the post on the IoTaWatt forum but have clearly missed something. I migrated from the HACS version to the HA Integration and back again in an attempt to get it working but failed dismally.

I have the following IoTaWatt Outputs setup

Export Mains min 0
ExportAbs (Mains min 0) abs -done from advice here
Import Mains max 0
SolarTotal SMASolar + FroniusSolar (Two Inverters)
Self Consumption (SMASolar + FroniusSolar) + (Mains min 0)
I have tried just using the HACS accumulated values and the solar shows correctly but the Energy use doesn’t (see the screenshot below)… I have also tried the Riemann Sum on the w values and this got close but but for whatever reason the calculated export entity will not show HA Energy Config. Hoping someone can tell me where i have gone wrong.
Here are the Calculated values I tried

  - platform: integration
    source: sensor.import
    name: import_wh_calculated
    unit_prefix: k
    round: 2
  - platform: integration
    source: sensor.exportabs
    name: export_wh_calculated
    unit_prefix: k
    round: 2
  - platform: integration
    source: sensor.solartotal
    name: solar_wh_calculated
    unit_prefix: k
    round: 2

And the output of using the HACS Accumulated values. The solar matches Iotawatt pretty well.

And the same day in IoTaWatt

I followed the instructions with this integration here:

added the two outputs and the sensor iotawatt in the configuration. Still I cannot select anything related to IotaWatt in the energy management tooling.

Please go to Developer Tools and select one of the sensors you are trying to show on the dashboard and post all the attributes for us to see.

Nevermind, I didn’t realize there would be another sensor total grid consumption also created by those.

Thanks