StealthChesnut / HA-FoxESS-Modbus

Home Assistant Modbus Integration setup for Fox ESS H1 and AC Inverters
79 stars 37 forks source link

Foxess Grid Power inverted #55

Closed wranglatang closed 2 years ago

wranglatang commented 2 years ago

Hello, I have connected my inverted to home assistant using LAN and one of the sensors seems to be backwards:

image

As you will see during the night the value is a Minus but in the day its possitive. I would expect it to be opposite I.E returning to grid should be a negative number.

I have looked at the foxess app and that is reporting Returning to grid correctly. Here is the configuration in HA for the parameter:

    - name: "FoxESS Grid Power"
      scan_interval: 5
      address: 31014
      state_class: measurement
      unit_of_measurement: "kW"
      data_type: int16
      scale: 0.001
      precision: 3
      input_type: holding    
      device_class: power
Daibutt commented 2 years ago

That's the way the number comes out of the inverter via modbus. Negative is import, so your sensor is reporting as designed. The way I like to think about it, if it's positive that's good as I'm making money, if it's negative not so good as I'm losing money! If you really want it round the other way I guess you could always create a new template sensor to multiply by -1. Or possibly change the scale in your code above to -0.001? Not sure if that will work with the scale parameter, and also the losses sensor if you have that configured will then go crazy ape with the change of sign.

StealthChesnut commented 2 years ago

As @Daibutt says - that's best thought of as "grid power exported", so a negative number is importing from grid, positive number is exporting.

Did you rename the sensor at all, or is that the default when it was installed? I thought that sensor was called Grid CT (as in the CT clamp reading, following Fox's naming conventions).

wranglatang commented 2 years ago

Thanks both for your feedback. I have tired setting the scale to -0.001 and it doesn't make any difference.

@StealthChesnut Your explantion makes sense if you look at it as a "Grid Power Export" Sensor. However this behaviour is different to many other devices such as the shelly and a Solax Inverter that I also have. Both of these show positive numbers when consuming from grid and negative when feeding back.

C00K50N commented 2 years ago

@wranglatang I felt the same way, if I've understood you correctly - it seemed to me it reads better the other way round. So I now have this sensor to reverse the grid reading, starting from the sensor named Grid CT as @StealthChesnut describes. This is my code to reverse it...

my_grid_ct:
      friendly_name: "Grid CT Inverse"
      unit_of_measurement: 'kW'
      device_class: power
      value_template: >
        {{ states('sensor.grid_ct') | float(default=0) * -1 }}

And I use it on a statistics graph and this gauge... image (Export negative yellow, Import positive red)

I hope that's of some help.

wranglatang commented 2 years ago

I stand corrected. ive just left my sensor for a bit and setting the Scaling to -0.001 seem to work!! so no need for an additional sensor here!

StealthChesnut commented 2 years ago

This sensor is (as @Daibutt says) just giving the raw data from the inverter as it's supplied. There are also two more sensors that use this as a data source and convert it to more "useable" readings:

  feed_in_power:
      friendly_name: "FeedIn power"
      unit_of_measurement: 'kW'
      device_class: power
      value_template: >
        {% if (states('sensor.grid_ct') | float(default=0) ) > 0 %}
        {{ states('sensor.grid_ct') | float(default=0) * 1 }}  {% else %}
        0 
        {% endif %}
  grid_consumption:
      friendly_name: "Grid consumption"
      unit_of_measurement: 'kW'
      device_class: power
      value_template: >
        {% if (states('sensor.grid_ct') | float(default=0) ) < 0 %}
        {{ states('sensor.grid_ct') | float(default=0) * -1 }}
        {% else %}
        0 
        {% endif %}

If you've followed the install instructions then you should also have these available for more UI-friendly numbers. I won't be changing the underlying sensor as it's what Fox have decided is correct.