reptilex / tesla-style-solar-power-card

Home assistant power card mimicking the one tesla provides for the powerwall app.
211 stars 59 forks source link

Tesla template fails with "TypeError: 'float' object is not iterable" #114

Open kodek opened 2 years ago

kodek commented 2 years ago

The recommended template picks min/max values as follows:

{{ states('sensor.powerwall_site_now') | float | max(0) | round(1) }}

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:

{{ [ (states('sensor.powerwall_site_now') | float), 0 ] | max | round(1) }}

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!

shadow7412 commented 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?

superforno commented 2 years ago

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`