Fronius inverter integration

power_units: ‘W’ <- This determines the fronius_house_load sensor to be in W right?
I’ve used all the codes in your package but not sure why the figures are incorrect.

I checked the sensor state and they are already set to kWh.

Yes, based on what you have shown here it should be ok. Yet it looks like your consumed/sold from the smartmeter is 1000 times too high.

It could also be something with the utility meter. Have you looked at the history graph for the two sensors grid_sold_energy_day and grid_consumed_energy_day and checked if they are reset to zero every night?

When I upgraded HA from 0.103.* to 0.106.* the utility meter “broke” some of my utility sensor at every restart of HA. It applied the current state on top of the current state so I got totally wrong values. That said, it has been stable for me since I updated HA to the latest 0.106.* version.

Could you check what your smartmeter actually reports?
Open this URL, replace ip_address with your inverters IP. You should see those values there and you can compare them with what you see in HA.

http://ip_address/solar_api/v1/GetMeterRealtimeData.cgi?Scope=System

I realised the values are showing up correctly during the start of the day.
image

However, when it reaches a certain value (i’ve not establish what value yet), it started to reported values in thousands.

image

Below is the value i extract from my inverter.
{
“Body” : {
“Data” : {
“0” : {
“Current_AC_Phase_1” : 13.548,
“Current_AC_Sum” : 13.548,
“Details” : {
“Manufacturer” : “Fronius”,
“Model” : “Smart Meter 63A-1”,
“Serial” : “xxxxx”
},
“Enable” : 1,
“EnergyReactive_VArAC_Phase_1_Consumed” : 145800,
“EnergyReactive_VArAC_Phase_1_Produced” : 3648710,
“EnergyReactive_VArAC_Sum_Consumed” : 145800,
“EnergyReactive_VArAC_Sum_Produced” : 3648710,
“EnergyReal_WAC_Minus_Absolute” : 1229902,
“EnergyReal_WAC_Phase_1_Consumed” : 640743,
“EnergyReal_WAC_Phase_1_Produced” : 1229902,
“EnergyReal_WAC_Plus_Absolute” : 640743,
“EnergyReal_WAC_Sum_Consumed” : 640743,
“EnergyReal_WAC_Sum_Produced” : 1229902,
“Frequency_Phase_Average” : 50.100000000000001,
“Meter_Location_Current” : 0,
“PowerApparent_S_Phase_1” : 3340.9299999999998,
“PowerApparent_S_Sum” : 3340.9299999999998,
“PowerFactor_Phase_1” : -0.97999999999999998,
“PowerFactor_Sum” : -0.97999999999999998,
“PowerReactive_Q_Phase_1” : -308.88,
“PowerReactive_Q_Sum” : -308.88,
“PowerReal_P_Phase_1” : -3295.5500000000002,
“PowerReal_P_Sum” : -3295.5500000000002,
“TimeStamp” : 1585535950,
“Visible” : 1,
“Voltage_AC_Phase_1” : 246.59999999999999
}
}
},
“Head” : {
“RequestArguments” : {
“DeviceClass” : “Meter”,
“Scope” : “System”
},
“Status” : {
“Code” : 0,
“Reason” : “”,
“UserMessage” : “”
},
“Timestamp” : “2020-03-30T13:39:11+11:00”
}
}

Hmm, so something weird is happening with the utility sensors for consumed/sold then :frowning:
That sensor is supposed to add the difference between each reading to the sensor. And apart from the glitches I had during a couple of upgrades they have been working flawlessly for me.

It could be that there are some bad readings that trips the sensor off. Do you keep your inverter in logging mode 24/7 or does it shut off during night?

Could you also post your utility sensor configs?

Could you also post a view of the history graph of the source sensors for those two utility sensors? That might give us a clue if there are some bad readings.

Yes, my inverter is setup for logging during night-time hours

##
## Energy Calculations
###################################################
utility_meter:
  ### daily data ###
  # calculate daily energy used
  house_energy_day:
    source: sensor.energy_used_hour
    cycle: daily

  # calculate daily energy consumed from grid
  grid_consumed_energy_day:
    source: sensor.fronius_smartmeter_energy_ac_consumed
    cycle: daily

  # calculate daily energy sold to grid
  grid_sold_energy_day:
    source: sensor.fronius_smartmeter_energy_ac_sold
    cycle: daily

  ### monthly data ###
  # calculate monthly energy used
  house_energy_month:
    source: sensor.energy_used_hour
    cycle: monthly

  # calculate monthly energy consumed from grid
  grid_consumed_energy_month:
    source: sensor.fronius_smartmeter_energy_ac_consumed
    cycle: monthly

  # calculate monthly energy sold to grid
  grid_sold_energy_month:
    source: sensor.fronius_smartmeter_energy_ac_sold
    cycle: monthly

  # calculate monthly panel production since that is not available from the inverter
  fronius_month_energy:
    source: sensor.energy_panel_hour
    cycle: monthly

  ### yearly data ###
  # calculate yearly energy used
  house_energy_year:
    source: sensor.energy_used_hour
    cycle: yearly

  # calculate yearly energy consumed from grid
  grid_consumed_energy_year:
    source: sensor.fronius_smartmeter_energy_ac_consumed
    cycle: yearly

  # calculate yearly energy sold to grid
  grid_sold_energy_year:
    source: sensor.fronius_smartmeter_energy_ac_sold
    cycle: yearly

image

image

image

image

It looks like you are getting a lot of zero readings. That might be what is tripping the utility meter.

This is how the two sensors for sold energy looks like for me (and the consumed energy looks similar):
image
image

On the other hand I get zero readings for the fronius_day_energy sensor. But since that value is used as-is and not fed into a utility sensor it doesn’t cause any issues.

image

I wonder why the inverter is returning bad data…I will see if I can figure out why.

Could you try to locate the following piece of code in sensor.py and comment out the two lines at the end that I have commented out? I’m curious if that makes a difference in this case because then the integration will return “None” and not “0” so the utility sensor might discard it and use the next value when it is a “valid” value.

        # convert and round the result
        if state is not None:
            if self._convert_units == "energy":
                _LOGGER.debug("Converting energy ({}) to {}".format(state, self._units))
                if self._units == "MWh":
                    self._state = round(state / 1000000, 2)
                elif self._units == "kWh":
                    self._state = round(state / 1000, 2)
                else:
                    self._state = round(state, 2)
            elif self._convert_units == "power":
                _LOGGER.debug("Converting power ({}) to {}".format(state, self._units))
                if self._units == "MW":
                    self._state = round(state / 1000000, 2)
                elif self._units == "kW":
                    self._state = round(state / 1000, 2)
                else:
                    self._state = round(state, 2)
            elif self._json_key == "DAY_ENERGY":
                # day energy always gets converted to kWh
                _LOGGER.debug("Converting day energy to kWh ({})".format(state))
                self._state = round(state / 1000, 2)
            else:
                _LOGGER.debug("Rounding ({}) to two decimals".format(state))
                self._state = round(state, 2)
# comment out these two lines
#        else:
#            self._state = 0
        _LOGGER.debug("State converted ({})".format(self._state))

Below is the extract of my sensor.py.

        # convert and round the result
        if state is not None:
            if self._convert_units == "energy":
                _LOGGER.debug("Converting energy ({}) to {}".format(state, self._units))
                if self._units == "MWh":
                    self._state = round(state / 1000000, 2)
                elif self._units == "kWh":
                    self._state = round(state / 1000, 2)
                else:
                    self._state = round(state, 2)
            elif self._convert_units == "power":
                _LOGGER.debug("Converting power ({}) to {}".format(state, self._units))
                if self._units == "MW":
                    self._state = round(state / 1000000, 2)
                elif self._units == "kW":
                    self._state = round(state / 1000, 2)
                else:
                    self._state = round(state, 2)
            else:
                _LOGGER.debug("Rounding ({}) to two decimals".format(state))
                self._state = round(state, 2)
        else:
            self._state = 0
        _LOGGER.debug("State converted ({})".format(self._state))

I noticed it is missing the below extract. will this be the problem?

            elif self._json_key == "DAY_ENERGY":
                # day energy always gets converted to kWh
                _LOGGER.debug("Converting day energy to kWh ({})".format(state))
                self._state = round(state / 1000, 2)

No, that part is only to correct the conversion of day energy so that it is always converted to kWh regardless of what you have specified in “units”.

But you should have that part too…but I think he released a new version a few hours ago after I submitted a pull-request to add this. So update to the latest version first and then try to comment out those lines.

OK. I’ve just updated the file to the latest version.

Just back to the graphs.

They are not really zero values

image

image

image

The “dips” in the graphs that goes to zero are zero. Otherwise the graphs would never have “spikes” that goes down to zero. I have also noticed on my day energy that lovelace displays zero sometimes which confirms that it actually is zero. But since that value is never used for any “calculation/summary” in any other sensor it doesn’t matter.

I have no knowledge of the internals of the utility meter. But I can imagine that it will have issues if the source sensor sometimes returns zero.
That is all I can come up with that could cause the behavior you see.

There is another thread I have been checking that involves similar issues…and the issues I mentioned above.

Is it possible that the reading shows zero when the inverter’s connection drops out from the wireless connection?

Could be. Although I have a wired connection to mine so there should be no connection issues for me. And afaik the integration should log an error if it cannot connect to the inverter or if it returns no data. But I have not been able to see any such issues in my log.

So something is causing the inverter to return “bad” data sometimes. Or this integration has some issues parsing out the data correctly. We just need to figure out why it happens :stuck_out_tongue:

OK. My inverter does have a weak wireless reception. I will relocate my wireless AP closer to the inverter for a better signal strength and see how it goes.

It’s just doing my head in having to see the correct figures in the morning thinking everything works fine and in the arvo it plays up again.

BTW commenting out the two lines did not make a difference so far.

Yup, it one of those errors that really annoys you :expressionless:

Try leaving it this way until tomorrow. It probably needs a “reset” of the utility meter, which happens on daily basis, before we can see if it still acts weird.

What you could check until then is to see how the history graph looks like.

Alright. I will keep you posted again tomorrow. Appreciate your help so far. Thanks!

1 Like

Do you know how can I get ?

  • Daily Energy Sent to Newtork (KWh)
  • Daily Energy Get from the Network (KWh)
  • Daily consumed Energy (KWh)

I think we might have hit the jackpot! :slightly_smiling_face: Been monitoring it all day and the figures seems correct now.

image
image
image
image
image

Also, I’ve been trying to setup a monthly and yearly stats but i don’t think the figures are populating correctly.

Below are extract of my cards.

cards:
  - entity: sensor.house_energy_month
    scale: 22px
    style: |
      ha-card {
        background: {% if states('ensor.house_energy_month') | float < states('sensor.grid_sold_energy_month') | float %} green {% else %} darkred {% endif %};
      }
    title: Total Consumption
    type: 'custom:bignumber-card'
  - entity: sensor.fronius_month_energy
    scale: 22px
    style: |
      ha-card {
        background: {% if states('sensor.fronius_month_energy') | float > states('sensor.house_energy_month') | float %} green {% else %} darkred {% endif %};
      }
    title: Panel Generation
    type: 'custom:bignumber-card'
  - entity: sensor.grid_consumed_energy_month
    scale: 22px
    style: |
      ha-card {
        background: {% if states('sensor.fronius_grid_usage') | float < 0 %} green {% else %} darkred {% endif %};
      }
    title: Energy Bought
    type: 'custom:bignumber-card'
  - entity: sensor.grid_sold_energy_month
    scale: 22px
    style: |
      ha-card {
        background: {% if states('sensor.grid_sold_energy_month') | float > states('sensor.grid_consumed_energy_month') | float %} green {% else %} darkred {% endif %};
      }
    title: Energy Sold
    type: 'custom:bignumber-card'
title: Monthly Stats
type: horizontal-stack
cards:
  - entity: sensor.house_energy_year
    scale: 22px
    style: |
      ha-card {
        background: {% if states('sensor.house_energy_year') | float < states('sensor.grid_sold_energy_year') | float %} green {% else %} darkred {% endif %};
      }
    title: Total Consumption
    type: 'custom:bignumber-card'
  - entity: sensor.fronius_year_energy
    scale: 22px
    style: |
      ha-card {
        background: {% if states('sensor.fronius_year_energy') | float > states('sensor.house_energy_year') | float %} green {% else %} darkred {% endif %};
      }
    title: Panel Generation
    type: 'custom:bignumber-card'
  - entity: sensor.grid_consumed_energy_year
    scale: 22px
    style: |
      ha-card {
        background: {% if states('sensor.fronius_grid_usage') | float < 0 %} green {% else %} darkred {% endif %};
      }
    title: Energy Bought
    type: 'custom:bignumber-card'
  - entity: sensor.grid_sold_energy_year
    scale: 22px
    style: |
      ha-card {
        background: {% if states('sensor.grid_sold_energy_year') | float > states('sensor.grid_consumed_energy_year') | float %} green {% else %} darkred {% endif %};
      }
    title: Energy Sold
    type: 'custom:bignumber-card'
title: Yearly Stats
type: horizontal-stack

I suspected that this was the reason. The utility meter thinks that since one reading was 0 and the next one “normal” it will apply that diff, which is why your readings started going sky high. But if the state is “None” it will just discard the value and use the next one that comes in.

The change to returning 0 instead on None was done because in the case when logging is disabled at night (which is the default), or when you restart HA when sun is down, there will be sensors with unknown state until sun comes back up again. The Fronius API returns Null value, or omits some readings, when the inverter is not producing power. So it’s tricky to know which way is the right one to choose.

Ideally I would like to understand when/why we get Null/Zero values for some sensors when they really should have a “valid” value. It might have something to do with how the requests are sent towards the inverter. Or it is the inverter that sometimes actually returns Null. I started running my integration with some debug logs but so far I have not found anything. Yet I can see that I am getting 0 sometimes for some sensors when I look at the history graph.

So if you could continue running your HA with the current setting and also try to observe how some sensors looks like when sun is down that would be good feedback.