Custom Component: IoTaWatt Energy Monitor integration

I know there has been a bit of churn regarding the sensor names over the past few releases. Which then creates more overhead. And the historical data is lost.

Now with the 0.1.1 release the custom component version and the official Home Assistant integration should have the same sensor names. Which should be an easier transition in the future.

I updated to 2021.9 and switched to using the non-hacs iotawatt, however, none of the readings are accurate at all aside from the total_grid_consumption. Since setting that up this morning it shows 17kWh consumption, which seems accurate based on what I was getting before upgrading. However, everything else is all jacked up, for example, the ac_wh is showing 486,094 Wh. Just my office is showing 75,146 Wh. In Iotawatt when I look at the graph+ stats, it says my AC is 27.9 kWh, and office is 5.57 kWh. Not sure what is going on, wish I had looked at this thread before upgrading to .9, since the iotawatt hacs was working great. Anyone else who’s upgrading seeing these crazy large numbers on the sensors? Am I missing something?

@Na3blis Where are you seeing the values? In the Energy Dashboard?

Did you create integration sensors in your configuration.yaml for each of your input and output sensors? What does the confit look like?

I did not, I had 17 sensors automatically created, the only one I manually created was the mainsexport (which I don’t actually need) and mainsconsumption. So the sensor.ac_wh I assumed is created like it was in the hacs version. I have:

sensor iotawatt:
  - platform: integration
    source: sensor.mainsexport
    name: Total Grid Export
    unit_prefix: k
  - platform: integration
    source: sensor.mainsconsumption
    name: Total Grid Consumption
    unit_prefix: k

And then in my template.yaml I have several sensors like this:

- sensor:
    - name: "AC kWh"
      unit_of_measurement: "kWh"
      state:  "{{ (states('sensor.ac_wh')| float / 1000) | round(2) }}"

The energy dashboard did not allow me to import any of the sensors that iotawatt generated. But I’m seeing these when I click on the entity, then click the icon in the top right that displays the value and the chart. here’s a screenshot

Reading through the entries I’m uncertain if I should transition from custom component to the integration or not.

Are the instructions on the integration page still current? Do I still need to configure iotawatt?

This is what I currently have in sensor.yaml using the custom component. Is there anything I need to change?

- platform: integration
  source: sensor.iotawatt_input_mainspower
  name: energy_used
  unit_prefix: k
  round: 2
  method: left

Do I just install the new integration and delete the one from HACS? There seems to quite a few changes, so I am a bit uncertain about changing over.

There seems to be some confusion with the documentation that is on the HA website IoTaWatt intergration.

The sensors mainsexport and mainsconsumption are just examples. These examples are based on the other example that is shown on the website that creates two Outputs in the IoTaWatt web interface.

I didn’t author the website, but am trying to put something together this weekend.

This gist is if you are running HA 2021.9.0 (or 2021.9.1 as of today) and using the official integration (not the HACS integration) and if you have one IoTaWatt input monitoring a circuit that is for your solar panels, this circuit is doing both importing and exporting energy. This means positive and negative values could be sent from IoTaWatt to Home Assistant. To mitigate this issue the user first needs to configure two Outputs in the IoTaWatt web interface, as is shown in the graphic in the link I referenced above. Then from in Home Assistant you need to create two sensors, this is where mainsexport and mainsconsumption comes to light. If you followed the example and named the Outputs in IoTaWatt as per the example they need to match in the configuration in Home Assistant. If you named the Outputs differently then well use your names.

Now the above is if you have solar. If you don’t have solar, not monitoring solar, or monitoring solar but don’t have both import and export energy through a single CT clamp (Input) attached to an IoTaWatt then you can ignore the above. But there is more!

Now for any sensors (Input or Output) from the IoTaWatt with a unit type of Watts that you want Home Assistant to use in the Energy Dashboard you have to create an entry in your configuration for each sensor. If you have a total of 30 sensors you need to create 30 entries.

In your case from your template file I assume you have a sensor named sensor.ac. This should be the sensor from the IoTaWatt but with a type of Watts You would need to add this entry (you can change the Name to whatever you want I just gave it Main AC) in your configuration file to have the Energy Dashboard accept it.

sensor iotawatt:
  - platform: integration
    source: sensor.ac
    name: Main AC
    unit_prefix: k

If you actually don’t have sensors with the name of sensor.mainsexport or sensor.mainsconsumption you can remove those from your config.

I know this is very long! And I’m sorry but some things are out of my control. Anyway I have released a beta release of the HACS custom_component for IoTaWatt that supports HA 2021.9. Still be tested but it only needs a sensors added to the configuration if you have solar and need to split the import and export into seperate sensors.

3 Likes

@currest2620 I think you read my very long post! But I wanted to follow up anyway. If you are running HA 2021.9 and want to move from HACS custom_component to the official release, you would have to have an entry in the config file for each sensor you want to appear in the Energy Dashboard. As well I think some are looking for the entities in the Entities when it’s filter by the IoTaWatt integration. After moving to the official version the Entities page may appear to not have your sensors, but if you clear the filter the sensors will be seen just they appear as with the integration name of Sensor. The beta version will also have this too as I wanted to be a bit consistent with HA until the Unique ID issue is resolved.

Thanks for that. I think I get it. My setup is as simple as it gets. I just have volts and power for one zone / whole house. Should be pretty straight forward I think.

1 Like

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?