Open kodek opened 2 years ago
This issue happened to me too - I think it was a HA update as well. The fix looks good to me, and works. Want to raise a PR to fix the example, or shall I?
Hello, I've had the same issue and I solved as suggested in this topic. But after than I have opposite sign of current flow, positive for production and negative for consumption. Example: my Powerwall2 is feeding house with 1kw of power, the card shows that:
Before updating Hassio, negative values were find only on battery during the charge phase and on grid when solar current was more than enough.
My sensor configuration is:
`tesla_card_grid_consumption: friendly_name: "Tesla Card Grid Consumption" value_template: "{{ [ (states('sensor.powerwall_site_now') | float), 0 ] | max | round(1) }}" device_class: power unit_of_measurement: kW
tesla_card_grid_feed_in:
friendly_name: "Tesla Card Grid Feed In"
value_template: "{{ [ (states('sensor.powerwall_site_now') | float), 0 ] | min | abs | round(1) }}"
device_class: power
unit_of_measurement: kW
tesla_card_solar_consumption:
friendly_name: "Tesla Card Solar Consumption"
value_template: "{{ ((states('sensor.powerwall_solar_now') | float) - (states('sensor.tesla_card_grid_feed_in') | float ) - (states('sensor.tesla_card_battery_charging') | float) ) | round(1) }}"
device_class: power
unit_of_measurement: kW
tesla_card_battery_consumption:
friendly_name: "Tesla Card Battery Consumption"
value_template: "{{ [ (states('sensor.powerwall_battery_now_2') | float), 0 ] | min | round(1) }}"
device_class: power
unit_of_measurement: kW
tesla_card_battery_charging:
friendly_name: "Tesla Card Battery Charging Inside"
value_template: "{{ [ (states('sensor.powerwall_battery_now_2') | float), 0 ] | max | abs | round(1) }}"
device_class: power
unit_of_measurement: kW`
The recommended template picks min/max values as follows:
This leads to a startup error. max() expects an Iterable, and it's receiving a single float value.
I can confirm that the following works:
This might be related to Home Assistant updating the Jinja dependency in 2022.4, but I actually couldn't confirm the root cause.
If anyone could confirm why this broke, whether my workaround is idiomatic, or if there's a more idiomatic solution, I'd appreciate it!