MrIceman11 / e3dc-homeassistant

ADD e3dc Data to your HomeAssistant
41 stars 12 forks source link

Warning in the system log: battery_discharge_power has non-numeric value: (<class 'str'>); #3

Closed micky-bamboleo closed 1 year ago

micky-bamboleo commented 1 year ago

Hello there,

I am pretty happy about your integration, thank you very much. One little issue though: I'm constantly getting this Warning for the battery_discharge_power sensor (only for that one as far as I see):

Logger: homeassistant.components.sensor Source: components/sensor/init.py:597 Integration: Sensor (documentation, issues) First occurred: 10:35:00 (2 occurrences) Last logged: 10:43:15

Sensor sensor.e3dc_battery_discharge_power has device class power, state class None and unit W thus indicating it has a numeric value; however, it has the non-numeric value: (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+template%22 Sensor sensor.e3dc_battery_charge_power has device class power, state class None and unit W thus indicating it has a numeric value; however, it has the non-numeric value: (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+template%22

Interesting thing is, that the sensor does nevertheless send data: image Is this thus a warning to be ignored? Sorry I wrote that in the issues, I don't know where else to put it best.

Best regards Micky

MrIceman11 commented 1 year ago

Hi Micky,

thanks for letting me know about the warning.

I may have a solution for you.

Could you replace the following things in your config and tell me if the warning is gone?

Both you have to change in the sensors.yaml. Please pay attention to the correct indentation!

e3dc_battery_charge_power:
  unique_id: e3dc_battery_charge_power
  friendly_name: E3DC Battery Charging Power
  unit_of_measurement: W
  device_class: power
  value_template: >
    {% set power = states('sensor.e3dc_battery_power') | float(0) %}
    {% if power >= 0 %}
      {{ power }}
    {% else %}
      {% set charge_power = states('sensor.e3dc_battery_charge_power') | float(0) + power %}
      {{ charge_power if charge_power > 0 else 0 }}
    {% endif %}

and

e3dc_battery_discharge_power:
  unique_id: e3dc_battery_discharge_power
  friendly_name: E3DC Battery Discharging Power
  unit_of_measurement: W
  device_class: power
  value_template: >
    {% set power = states('sensor.e3dc_battery_power') | float(0) %}
    {% if power <= 0 %}
      {{ power | abs }} 
    {% else %}
      {% set discharge_power = states('sensor.e3dc_battery_charge_power') | float(0) - power %}
      {{ discharge_power if discharge_power > 0 else 0 }}
    {% endif %}

Best regards Julian

micky-bamboleo commented 1 year ago

Hi Julian, Thank you so much for your quick response and individual help here, wow! 😀 I just made your suggested changes and for the moment it looks really good! I guess you could consider this as solved. 😉👍 Best regards, Micky

Roemer commented 1 year ago

Do you mind quickly explaining what was the idea of that change? I don't fully get it. Wouldn't it be also possible tu just use {% else %} 0 so that it always has a value?