flixlix / power-flow-card-plus

A power distribution card inspired by the official Energy Distribution card for Home Assistant
603 stars 75 forks source link

[BUG] When Individual power consumption is NaN, it breaks the calculation of home consumption when substracting #112

Closed jailway closed 1 year ago

jailway commented 1 year ago

When an individual power consumption sensor is not available (like a pool heater disconnected during winter) and using the option to substract individual appliances power consumption from home consumption, it breaks the calculation and the home consumption is also displayed as NaN. I'd suggest to replace missing numbers with zeroes in such a case so as to not break the calculation.

Steps to reproduce the behavior: And individual consumption entity, disconnect the entity, enable subtraction from home consumption.

Expected behavior Missing consumption should be treated as zero.

Screenshots image

(using version 0.1beta)

jailway commented 1 year ago

Hi, replaced the .js file, restarted, cleared cache, refreshed and it's still behaving the same. Maybe I should add that the sensor causing this is disconnected and homeassistant reports it as "unavailable".

flixlix commented 1 year ago

Ok, I'll have to implement some more type checking later today, I'll let you know when I've implemented and tested. Sorry for the inconvenience

jailway commented 1 year ago

No worries, this is not a support forum, let me know if I can help

flixlix commented 1 year ago

power-flow-card-plus.js.zip Can you please try this js file, works now on my end 😅 Commit: https://github.com/flixlix/power-flow-card-plus/commit/d8eac7dfb242ea6097f60d16b365728d40246b2d

jailway commented 1 year ago

Works great now, thanks for a quick fix!

jailway commented 1 year ago

Hi Luca, I checked in the morning with the boiler actually running and consuming some power and I noticed another bug - with the new fix, it looks like the appliance consumption is subtracted twice from the home total, so the estimated home consumption is negative: image

flixlix commented 1 year ago

Can you please send me your configuration?

jailway commented 1 year ago

You mean this?

 type: custom:power-flow-card-plus
 title: Toky elektƙiny
 entities:
   battery:
     entity: sensor.solax_battery_power
     state_of_charge: sensor.solax_battery_soc
     color_circle: true
   grid:
     entity: sensor.solax_grid_power
     name: ČEZ
     color_circle: true
   solar:
     entity: sensor.solax_pv_power
     display_zero_state: true
     name: Sluníčko
     secondary_info:
       icon: ''
       unit_white_space: true
       color_value: true
       display_zero: false
     color_value: false
     color_icon: false
   home:
     subtract_individual: true
     override_state: false
     secondary_info:
       icon: ''
       color_value: true
       display_zero: true
       unit_white_space: true
     entity: sensor.solax_consumption
   individual1:
     entity: sensor.nous1_energy_power
     name: Boiler
     icon: mdi:thermometer-water
     color_value: false
     color_icon: false
     color: lightgreen
     display_zero: true
     display_zero_state: false
   individual2:
     name: Bazén
     icon: mdi:pool-thermometer
     display_zero: true
     color:
       - 112
       - 181
       - 255
     display_zero_state: true
     color_icon: false
     entity: sensor.nous2_energy_power
   fossil_fuel_percentage:
     entity: sensor.co2_signal_grid_fossil_fuel_percentage
     unit_white_space: true
     display_zero_state: true
     display_zero: true
     color_icon: false
     state_type: power
 clickable_entities: true
 display_zero_lines: false
 use_new_flow_rate_model: false
 inverted_entities: battery, grid
 w_decimals: 0
 kw_decimals: 2
 max_expected_power: 4000
 min_expected_power: 0
 watt_threshold: 10000
 max_flow_rate: 10
 min_flow_rate: 0.1
flixlix commented 1 year ago

Thank you for that.

power-flow-card-plus.js.zip

Turns out it was just a small copy&paste typo on my end. https://github.com/flixlix/power-flow-card-plus/commit/a2a188c1efd94bd3c43215dc4d46e9f3d7ed4261

jailway commented 1 year ago

Works nicely, thanks and cheers!