Custom Component: IoTaWatt Energy Monitor integration

Found it: https://github.com/home-assistant/core/pull/86834

1 Like

I am still using the custom integration which is pretty much working fine for me. However, I have noticed a couple of wanings in the logs about a sensor being of state_class total_increasing but its value not strictly increasing.

The sensor in question is my B phase which has my solar attached so the power reading goes negative.

I have customised the sensors now (sensor.phaseb_wh and sensor.phaseb_wh_accumulated) as state_class total which obviously stops the warning but I am left wondering if that is a bug? I am not sure exactly whether the wh totals should be going up and down? In my mind I think I am using them as imported values so should I make a change to sensor.py to fix this? I am thinking:

    def _handle_coordinator_update(self) -> None:
        """Handle updated data from the coordinator."""
        assert (
            self._accumulated_value is not None
        ), "async_added_to_hass must have been called first"
        value = float(self._sensor_data.getValue())
        if (value > 0 ):
          self._accumulated_value += value
        super()._handle_coordinator_update()

Thoughts?

Is your IoTaWatt setup correctly with Integrators for your inputs that can go negative (such as the solar if the inverter is a hybrid and pulls a few watts overnight in standby, and the mains/grids feeds that will show negative when exporting to the grid)?

See: Integrators — IoTaWatt 02_03_20 documentation

If you only wanted your phase B sensor to be counting the 'positive values (i.e. import from grid), then your setup the integrator and then use ‘.pos’ to only output positive values. conversely .net would give you the net value of the phase (i.e. import minus export) and .neg would only give the negative vales (i.e. export to grid).

The B phase power needs to go positive and negative. I am talking about the energy values that the integration calculates.

but then it’s not longer total_increasing type which is what HA requires.

What you want to do here, is have two output setup instead, one containing the (input_b max 0) abs for the negative energy.
and one that is input_b min 0

OK but what is the value or use of tracking this? It isn’t the export as I have to add the other two phases first (which I do with a different sensor).

And the question remains is the integration doing the right thing by calculating an “accumulated” value which includes negative values (in my case)?

Also I don’t know why I am seeing this:

Entity sensor.grid_consumption_wh from integration iotawatt has state class total_increasing, but its state is not strictly increasing. Triggered by state 5909503 (5909.517) with last_updated set to 2023-08-05T00:34:22.690424+00:00. Please report it to the custom integration author.

When my iotawatt output is setup like this:

grid_consumption Watts = (PhaseA + PhaseB + PhaseC) max 0

I ignore these errors, I get them with zwavejs as well because my main breaker is monitored with a zwave meter (purchased before my iotawatt), and I have it set to net metering.

There are two things here. Most importantly for me I don’t know why the value is going down when the output from iotawatt should be minimum zero.

Secondly, if the values can go up and down then is the state_class incorrect?

If you export to the grid, the Wh should go backwards in a net metering setup.

I don’t recall if iotawatt has a feature to not net meter.

That might be so but still doesn’t explain why my grid consumption is going backwards when it should be minimum zero. It also suggests as I thought that the state class is probably incorrect…

I’m continuing to look at this but I don’t know where the problem lies. Looking at the iotawatt output it seems to be working perfectly with min 0 for the grid consumption

BUT when you look at the values HA is obtaining then you can see a 12-14wh reduction every 30secs.

I added this to the code and indeed the value is negative a lot but the sensor below is the phase with solar so it should be going negative.

    def _handle_coordinator_update(self) -> None:
        """Handle updated data from the coordinator."""
        assert (
            self._accumulated_value is not None
        ), "async_added_to_hass must have been called first"
        value = float(self._sensor_data.getValue())
        self._accumulated_value += value
        if (value < 0 ):
          _LOGGER.warning("Sensor Value is Negative: %s %s", self._attr_unique_id, value)
        super()._handle_coordinator_update()

image

I am not seeing warnings related to sensor.grid_consumption_wh but the HA sensor is going backwards

To start I would use the official iotawatt integration. You’re not going to get more help from any of the dev considering the old custom integration hasn’t been updated in years.

OK I have just put it on my test system. It looks like there are no accumulation sensors now. I assume you have to create your own? Is this post of yours the answer? Custom Component: IoTaWatt Energy Monitor integration - #275 by jyavenard

s
yes and that is what I used now, precisely because they have removed the accumulated sensors (despite my argument to do otherwise) and now the energy sensors are useless as they reset at midnight

Should I be able to run the integration and this in parallel? I ask because I monitor all my sub circuits and having them all appear on the individual devices card is something I would like to retain?

of course, you can name the new sensors anything you like. It’s using the REST integration.
In my example I have them all prefixed with iotawatt_

Actually I just realised that I need to extend the rest sensor to include all of the circuits I need!

Not sure what I am doing wrong as the values are not changing except for the range?

  - platform: rest
    name: IoTaWatt_select
    unique_id: IoTaWatt_select
    resource: http://192.168.1.233/query?select=[grid_export,grid_consumption,Solar,Light2A,Oven,Power4C,PhaseA,PhaseB,PhaseC]&begin=y&end=m&group=all&header=yes
    json_attributes:
      - labels
      - data
    value_template: "on"

Typing the url into my browser I get:

{"range":[1672495200,1693268100],"labels":["grid_export","grid_consumption","Solar","Light2A","Oven","Power4C","PhaseA","PhaseB","PhaseC"],
"data":[[0,1122.6,461.3,47.6,27,243.9,263.8,467.9,391]]}

Just to confirm I see the range value changing but the data values do not?

you are querying the average of the power from the beginning of the year to the start of the current minute. I don’t expect the average to change much from one minute to the next.