I don’t suppose anyone would be able to help with a “Time to full” sensor?
I’ve been trying to reverse engineer the above codes but clearly don’t know what im doing…
I don’t suppose anyone would be able to help with a “Time to full” sensor?
I’ve been trying to reverse engineer the above codes but clearly don’t know what im doing…
Someone can create a blueprint with this?
That is quite simple and here is the code. This is in my template.yaml file need template: if adding to config.
#--------------------------------------------------------------------------------------------------
# Battery Energy to Full
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_energy_to_full"
unique_id: "solar_battery_energy_to_full"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 | float(0) %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(0)) / 100.0 | float(0) %}
{% set charge = ((1.0 - percent) * number * energy) | float(0) %}
{{ charge }}
Here is the sensor. I have this in my templates.yaml so if adding it to config your need a templates:
#--------------------------------------------------------------------------------------------------
# Time to Charge Battery to full
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "battery_time_to_full"
unique_id: "battery_time_to_full"
state: >
{% set a = states('sensor.battery_energy_to_full') | float(0.0001) %}
{% set b = states('sensor.power_to_battery') | float(0.0001) %}
{% if b > 0.001 %}
{% set decimal_hours = a / b %}
{% else %}
{% set decimal_hours = 0.0 %}
{% endif %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours| int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
Here is one of my energy displays with time to charge added
Do you have a standalone sensor setup somewhere to measure your daily home energy consumption (the 20.9 kWh on the right)? If so, could you please share how you set that up?
I will share all of my setup around solar. I use multiple files and the initial setup is in configuration.yaml. The value used for KWh is derived from the load_now sensor through a Riemann integral.
In configuration.yaml: ---------------------------------------------------------------------------------------------------
utility_meter: !include utility_meter.yaml
template: !include templates.yaml
sensor: !include sensors.yaml
In my sensors.yaml I have this: …
# ---------------------------------------------------------------------------------------------
# Average produced over the last hour
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Produced Last Hour"
entity_id: sensor.powerwall_solar_now
state_characteristic: mean
max_age:
hours: 1
sampling_size: 720
precision: 3
# ---------------------------------------------------------------------------------------------
# Average over the last 24 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Produced Last 24 Hour"
entity_id: sensor.powerwall_solar_now
state_characteristic: mean
max_age:
hours: 24
sampling_size: 17280
precision: 3
# ---------------------------------------------------------------------------------------------
# Average over the last hour
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Used Last Hour"
entity_id: sensor.powerwall_load_now
state_characteristic: mean
max_age:
hours: 1
sampling_size: 720
precision: 3
# ---------------------------------------------------------------------------------------------
# Average over the last 12 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Used Last 12 Hour"
entity_id: sensor.powerwall_load_now
state_characteristic: mean
max_age:
hours: 12
sampling_size: 8640
precision: 3
# ---------------------------------------------------------------------------------------------
# Average over the last 24 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Average kW Used Last 24 Hour"
entity_id: sensor.powerwall_load_now
state_characteristic: mean
max_age:
hours: 24
sampling_size: 17280
precision: 3
# ---------------------------------------------------------------------------------------------
# Minimum over the last 24 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Minimum kW Used Last 24 Hour"
entity_id: sensor.powerwall_load_now
state_characteristic: value_min
max_age:
hours: 24
sampling_size: 17280
precision: 3
# ---------------------------------------------------------------------------------------------
# Maximum over the last 24 hours
# ---------------------------------------------------------------------------------------------
- platform: statistics
name: "Maximum kW Used Last 24 Hour"
entity_id: sensor.powerwall_load_now
state_characteristic: value_max
max_age:
hours: 24
sampling_size: 17280
precision: 3
# ------------------------------------------------------------------------------------
# Riemann Sum Integrals for specific equipment
# ------------------------------------------------------------------------------------
- platform: integration
source: sensor.wash_power
name: washing_machine_energy
unique_id: "Washing Machine Energy"
round: 3
unit_prefix: k
unit_time: h
- platform: integration
source: sensor.bar_fridge_power
name: bar_fridge_energy
unique_id: "Bar Refrigerator Energy"
round: 3
unit_prefix: k
unit_time: h
- platform: integration
source: sensor.coffee_bar_power
name: coffee_bar_energy
unique_id: "Coffee Bar Energy"
round: 3
unit_prefix: k
unit_time: h
- platform: integration
source: sensor.storage_fridge_power
name: storage_frige_energy
unique_id: "Storage Refrigerator Energy"
round: 3
unit_prefix: k
unit_time: h
- platform: integration
source: sensor.study_monitor_power
name: study_monitor_energy
unique_id: "Study Monitor Energy"
round: 3
unit_prefix: k
unit_time: h
# ------------------------------------------------------------------------------------
# Riemann Sum Integrals for Solar
# ------------------------------------------------------------------------------------
- platform: integration
source: sensor.powerwall_solar_now
name: Solar Energy Produced
unique_id: "Solar Energy Produced"
round: 3
unit_time: h
- platform: integration
source: sensor.powerwall_load_now
name: Energy Consumed
unique_id: "Energy Consumed By House"
round: 3
unit_time: h
- platform: integration
source: sensor.power_to_grid
name: Energy to Grid
unique_id: "Energy to Grid"
round: 3
unit_time: h
- platform: integration
source: sensor.power_from_grid
name: Energy from Grid
unique_id: "Energy from Grid"
round: 3
unit_time: h
- platform: integration
source: sensor.power_to_battery
name: Energy to Battery
unique_id: "Energy to Battery"
round: 3
unit_time: h
- platform: integration
source: sensor.power_from_battery
name: Energy from Battery
unique_id: "Energy from Battery"
round: 3
unit_time: h
# ------------------------------------------------------------------------------------
# Retrieve individual power from sensors via attributes
# ------------------------------------------------------------------------------------
- platform: template
sensors:
wash_power:
friendly_name_template: "washing machine power"
value_template: "{{ states('sensor.sonoff_100153b37b_power') | float(0.0) }}"
unit_of_measurement: W
unique_id: "Washing machine power"
bar_fridge_power:
friendly_name_template: "bar fridge power"
value_template: "{{ states('sensor.sonoff_100153c633_power') | float(0.0) }}"
unit_of_measurement: W
unique_id: "Bar Refrigerator Power"
coffee_bar_power:
friendly_name_template: "coffee bar power"
value_template: "{{ states('sensor.sonoff_100153b891_power') | float(0.0) }}"
unit_of_measurement: W
unique_id: "Coffee Bar Power"
storage_fridge_power:
friendly_name_template: "storage fridge power"
value_template: "{{ states('sensor.sonoff_100153a3fc_power') | float(0.0) }}"
unit_of_measurement: W
unique_id: "Storage Refrigerator Power"
study_monitor_power:
friendly_name_template: "study monitor power"
value_template: "{{ states('sensor.sonoff_100153c279_power') | float(0.0) }}"
unit_of_measurement: W
unique_id: "Study Monitor Power"
#-----------------------------------------------------------------------------------------------------------------------
#
# Start the powercalc sensors. Units are in kWh
#
#-----------------------------------------------------------------------------------------------------------------------
- platform: powercalc
entity_id: light.study_cans_current_value
create_energy_sensor: true
energy_sensor_unit_prefix: 'k'
mode: 'fixed'
linear:
min_power: 0.0
max_power: 0.068
attribute: input_number.brightness
In my templates.yaml file I have: ---------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
# Time to Charge Battery to full
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "battery_time_to_full"
unique_id: "battery_time_to_full"
state: >
{% set a = states('sensor.solar_battery_energy_to_full') | float(0.0001) %}
{% set b = states('sensor.power_to_battery') | float(0.0001) %}
{% if b > 0.001 %}
{% set decimal_hours = a / b %}
{% else %}
{% set decimal_hours = 0.0 %}
{% endif %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours| int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
#--------------------------------------------------------------------------------------------------
# Battery Life at Current Power Draw
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_life"
unique_id: "solar_battery_life"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 | float(0) %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(5)) / 100.0 %}
{% set charge = ((percent - reserve) * number * energy) | float(0) %}
{% set a = states('sensor.powerwall_solar_now') | float(0.0001) %}
{% set b = states('sensor.powerwall_site_now') | float(0.0001) %}
{% set c = states('sensor.powerwall_battery_now') | float(0.0001) %}
{% set current_power = a + b + c %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours| int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
#--------------------------------------------------------------------------------------------------
# Battery Life at Average 1 hr Power Draw
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_life_1_hr"
unique_id: "solar_battery_life_1_hr"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 | float(0) %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(5)) / 100.0 %}
{% set charge = ((percent - reserve) * number * energy) | float(0) %}
{% set current_power = states('sensor.average_kw_used_last_hour') | float(0.0001) %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours| int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
#--------------------------------------------------------------------------------------------------
# Battery Life at Average 12 hr Power Draw
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_life_12_hr"
unique_id: "solar_battery_life_12_hr"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 | float(0) %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(5)) / 100.0 %}
{% set charge = ((percent - reserve) * number * energy) | float(0) %}
{% set current_power = states('sensor.average_kw_used_last_12_hour') | float(0.0001) %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours| int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
#--------------------------------------------------------------------------------------------------
# Battery Life at Average 24 hr Power Draw
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_life_24_hr"
unique_id: "solar_battery_life_24_hr"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 | float(0) %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(5)) / 100.0 %}
{% set charge = ((percent - reserve) * number * energy) | float(0) %}
{% set current_power = states('sensor.average_kw_used_last_24_hour') | float(0.0001) %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours | int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
#--------------------------------------------------------------------------------------------------
# Battery Life at Minimum 24 hr Power Draw - longest battery life
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_life_minimum_24_hr"
unique_id: "solar_battery_life_minimum_24_hr"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0.01) / 100.0 %}
{% set number = states('input_number.number_of_batteries') | float(2) %}
{% set energy = 13.5 | float(13.5) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(5)) / 100.0 %}
{% set charge = ((percent - reserve) * number * energy) | float(0) %}
{% set current_power = states('sensor.minimum_kw_used_last_24_hour') | float(0.01) %}
{% if current_power <= 0.0001 %}
{% set current_power = 0.5 %}
{% endif %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours | int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
#--------------------------------------------------------------------------------------------------
# Battery Life at Maximum 24 hr Power Draw - shortest battery life
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_life_maximum_24_hr"
unique_id: "solar_battery_life_maximum_24_hr"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0.01) / 100.0 %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(5)) / 100.0 %}
{% set charge = ((percent - reserve) * number * energy) | float(0) %}
{% set current_power = states('sensor.maximum_kw_used_last_24_hour') | float(0.0001) %}
{% if current_power <= 0.0001 %}
{% set current_power = 0.5 %}
{% endif %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours | int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
#--------------------------------------------------------------------------------------------------
# Battery Life at Battery Power Draw - Life at Current Power Draw
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_life_battery_power"
unique_id: "solar_battery_life_battery_power"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 | float(0) %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(5)) / 100.0 %}
{% set current_power = states('sensor.powerwall_battery_now') | float(0.0001) | abs %}
{% if current_power < 0.1 %}
{% set current_power = 0.1 %}
{% endif %}
{% if states('sensor.powerwall_battery_now') | float(0) < -0.001 %}
{% set charge = ((1.0 - percent) * number * energy) | float(0) %}
{% else %}
{% set charge = ((percent - reserve) * number * energy) | float(0) %}
{% endif %}
{% set decimal_hours = charge / (current_power + 0.0001) %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{% set decimal_hours = decimal_hours | int(0) %}
{% if minutes <= 9 %}
{% set min = '0' ~ minutes | string %}
{% else %}
{% set min = minutes | string %}
{% endif %}
{{ decimal_hours ~ ':' ~ min }}
#--------------------------------------------------------------------------------------------------
# Battery energy stored currently
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_energy_available"
unique_id: "solar_battery_energy_available"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 | float(0) %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(0)) / 100.0 | float(0)%}
{% set charge = ((percent - reserve) * number * energy) | float(0) %}
{{ charge }}
#--------------------------------------------------------------------------------------------------
# Battery Energy to Full
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_battery_energy_to_full"
unique_id: "solar_battery_energy_to_full"
state: >
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 | float(0) %}
{% set number = states('input_number.number_of_batteries') | float(0) %}
{% set energy = 13.5 | float(0) %}
{% set reserve = (states('sensor.powerwall_backup_reserve') | float(0)) / 100.0 | float(0) %}
{% set charge = ((1.0 - percent) * number * energy) | float(0) %}
{{ charge }}
#----------------------------------------------------------------------------------------------------------------------------------------------------
#
# This section is for power and energy based on Tesla gateway. I convert all negative to positive
# I set to 0.0 when energy is not flowing in the correct direction for the sensor.
# Sensors Available
# sensor.powerwall_solar_now - solar power being produced
# sensor.powerwall_site_now - grid power to or from
# sensor.powerwall_battery_now - battery power to or from
# sensor.powerwall_load_now - house power usage
# sensor.grid_to_home_energy_price
# sensor.solar_to_grid_energy_price
#
# These sensors in turn drive the following integrations for energy
# Sensors Available
# sensor.solar_energy_produced
# sensor.energy_consumed
# sensor.energy_to_grid
# sensor.energy_from_grid
# sensor.energy_to_battery
# sensor.energy_from_battery
#----------------------------------------------------------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
# For Grid to Home/Battery pricing - Usage price I pay from the grid
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "grid_to_home_energy_price"
unique_id: "Grid to Home Energy_Price"
state: >-
{% if states('sensor.powerwall_site_now') | float(0) > 0.001 %}
{{ state('input_number.kwh_cost_from_grid') }}
{% else %}
0.000
{% endif %}
unit_of_measurement: "USD/kWh"
#--------------------------------------------------------------------------------------------------
# For Solar to Grid pricing - Generation price I sell to the grid
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "solar_to_grid_energy_price"
unique_id: "Solar to Grid Energy_Price"
state: >-
{% if states('sensor.powerwall_site_now') | float(0) < -0.001 %}
{{ states('input_number.kwh_revenue_to_grid') }}
{% else %}
0.000
{% endif %}
unit_of_measurement: "USD/kWh"
#--------------------------------------------------------------------------------------------------
# Power to Grid - Make Positive
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Power to Grid"
unique_id: "Power to Grid"
state: >-
{% if states('sensor.powerwall_site_now') | float(0) < -0.0001 %}
{{ states('sensor.powerwall_site_now') | float(0) | abs}}
{% else %}
0.000
{% endif %}
unit_of_measurement: "kW"
#--------------------------------------------------------------------------------------------------
# Power from Grid - Make Positive
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Power from Grid"
unique_id: "Power From Grid"
state: >-
{% if states('sensor.powerwall_site_now') | float(0) > 0.001 %}
{{ states('sensor.powerwall_site_now') }}
{% else %}
0.000
{% endif %}
unit_of_measurement: "kW"
#--------------------------------------------------------------------------------------------------
# Power to Battery - Make Positive sensor.powerwall_battery_now
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Power to Battery"
unique_id: "Power to Battery"
state: >-
{% if states('sensor.powerwall_battery_now') | float(0) < -0.001 %}
{{ states('sensor.powerwall_battery_now') | float(0) | abs}}
{% else %}
0.000
{% endif %}
unit_of_measurement: "kW"
#--------------------------------------------------------------------------------------------------
# Power from Battery - Make Positive sensor.powerwall_battery_now
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Power from Battery"
unique_id: "Power from Battery"
state: >-
{% if states('sensor.powerwall_battery_now') | float(0) > 0.001 %}
{{ states('sensor.powerwall_battery_now') }}
{% else %}
0.000
{% endif %}
unit_of_measurement: "kW"
#--------------------------------------------------------------------------------------------------
# AC Upstairs Energy - sensor.phase_1_a_c_upstairs_energy
# Power and Energy is only being measured on one phase - Need to Double for 230v
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Upstairs AC Energy"
unique_id: "Upstairs AC Energy"
state: "{{ states('sensor.phase_1_a_c_upstairs_energy') | float(0) * 2.000 }}"
unit_of_measurement: "kWh"
#--------------------------------------------------------------------------------------------------
# AC Downstairs Energy - sensor.phase_1_a_c_downstairs_energy
# Power and Energy is only being measured on one phase - Need to Double for 230v
#--------------------------------------------------------------------------------------------------
- sensor:
- name: "Downstairs AC Energy"
unique_id: "Downstairs AC Energy"
state: "{{ states('sensor.phase_1_a_c_down_energy') | float(0) * 2.000 }}"
unit_of_measurement: "kWh"
In my utility_meters.yaml file I have this: ---------------------------------------------------------------------------------
# ------------------------------------------------------------------------------------
# Energy Consumed
# ------------------------------------------------------------------------------------
daily_energy:
source: "sensor.energy_consumed"
name: "Daily kWh Usage"
cycle: daily
weekly_energy:
source: "sensor.energy_consumed"
name: "Weekly kWh Usage"
cycle: weekly
monthly_energy:
source: "sensor.energy_consumed"
name: "Monthly kWh Usage"
cycle: monthly
yearly_energy:
source: "sensor.energy_consumed"
name: "Yearly kWh Usage"
cycle: yearly
# ------------------------------------------------------------------------------------
# Solar Energy Produced
# ------------------------------------------------------------------------------------
daily_energy_produced:
source: "sensor.solar_energy_produced"
name: "Daily kWh Produced"
cycle: daily
weekly_energy_produced:
source: "sensor.solar_energy_produced"
name: "Weekly kWh Produced"
cycle: weekly
monthly_energy_produced:
source: "sensor.solar_energy_produced"
name: "Monthly kWh Produced"
cycle: monthly
yearly_energy_produced:
source: "sensor.solar_energy_produced"
name: "Yearly kWh Produced"
cycle: yearly
# ------------------------------------------------------------------------------------
# Energy to Battery
# ------------------------------------------------------------------------------------
daily_energy_battery_to:
source: "sensor.energy_to_battery"
name: "Daily kWh to Battery"
cycle: daily
weekly_energy_battery_to:
source: "sensor.energy_to_battery"
name: "Weekly kWh to Battery"
cycle: weekly
monthly_energy_battery_to:
source: "sensor.energy_to_battery"
name: "Monthly kWh to Battery"
cycle: monthly
yearly_energy_battery_to:
source: "sensor.energy_to_battery"
name: "Yearly kWh to Battery"
cycle: yearly
# ------------------------------------------------------------------------------------
# Energy from Battery
# ------------------------------------------------------------------------------------
daily_energy_battery_from:
source: "sensor.energy_from_battery"
name: "Daily kWh from Battery"
cycle: daily
weekly_energy_battery_from:
source: "sensor.energy_from_battery"
name: "Weekly kWh from Battery"
cycle: weekly
monthly_energy_battery_from:
source: "sensor.energy_from_battery"
name: "Monthly kWh from Battery"
cycle: monthly
yearly_energy_battery_from:
source: "sensor.energy_from_battery"
name: "Yearly kWh from Battery"
cycle: yearly
# ------------------------------------------------------------------------------------
# Energy to Grid
# ------------------------------------------------------------------------------------
daily_energy_grid_to:
source: "sensor.energy_to_grid"
name: "Daily kWh to Grid"
cycle: daily
weekly_energy_grid_to:
source: "sensor.energy_to_grid"
name: "Weekly kWh to Grid"
cycle: weekly
monthly_energy_grid_to:
source: "sensor.energy_to_grid"
name: "Monthly kWh to Grid"
cycle: monthly
yearly_energy_grid_to:
source: "sensor.energy_to_grid"
name: "Yearly kWh to Grid"
cycle: yearly
# ------------------------------------------------------------------------------------
# Energy from Grid
# ------------------------------------------------------------------------------------
daily_energy_grid_from:
source: "sensor.energy_from_grid"
name: "Daily kWh from Grid"
cycle: daily
weekly_energy_grid_from:
source: "sensor.energy_from_grid"
name: "Weekly kWh from Grid"
cycle: weekly
monthly_energy_grid_from:
source: "sensor.energy_from_grid"
name: "Monthly kWh from Grid"
cycle: monthly
yearly_energy_grid_from:
source: "sensor.energy_from_grid"
name: "Yearly kWh from Grid"
cycle: yearly
And finally here is the setup on the card - one for the powere and one for the energy: ----------------------
type: custom:power-flow-card
entities:
battery: sensor.powerwall_battery_now
battery_charge: sensor.powerwall_charge
grid: sensor.powerwall_site_now
solar: sensor.powerwall_solar_now
max_flow_rate: 2
watt_threshold: 0
kw_decimals: 2
title: Power Flow
For the Energy Card: ----------------------------------------------------------------------------------------------------------------
type: custom:power-flow-card
title: Energy kWh
entities:
battery:
consumption: sensor.daily_kwh_from_battery
production: sensor.daily_kwh_to_battery
battery_charge: sensor.powerwall_charge
grid:
consumption: sensor.daily_kwh_from_grid
production: sensor.daily_kwh_to_grid
solar: sensor.daily_kwh_produced
max_flow_rate: 2
watt_threshold: 0
kw_decimals: 2
Thanks for sharing this! This is going to get me to re-think my setup entirely…
However, I still think I’m missing something in regard to the home energy usage sensor.
So you use sensor.powerwall_load_now
as the source for a Riemann integral to create sensor.energy_consumed_by_house
. And then use that Riemann integral sensor as the source for sensor.energy_consumed
?
And then what specifically is populating that information in the Energy kWh power-flow-card? I don’t see sensor.energy_consumed
listed in your Energy kWh yaml above. Does the power-flow-card calculate this daily home usage automatically or am I missing something else?
Transparently, I’m trying to figure out why my daily home energy usage Utility Meter with sensor.powerwall_load_import
as the source is not matching the Tesla app as I outlined in this thread. I hadn’t tried using a Riemann integral for this, so I’m wondering if that’s why it’s not working…however the difference in values in the history ofsensor.powerwall_load_import
from now to the previous midnight matches up with the value in the Tesla app, but not in the Utility Meter I built off of it.
The Riemann Integral is for converting power to energy. I monitor both the power and energy in the card.
The card uses the inputs and outputs and then calculates the house load as an energy or power balance.
Unless you have all the energy configured the utility meters and the powerwall will not match. The usage will.
Hope this helps
So you only have the value for home energy usage within the power-flow-card and do not have a sensor outside of it that reports the same number? This is what I’m looking for since a Utility Meter on sensor.powerwall_load_import
is not properly calculating the value and I haven’t been able to find a solution to this yet. Thanks for the info.
many thanks @ all.
this is my battery card (Huawei luna2000 - 20kWh + custom button card + custom code )
charging:
discharging:
full charge:
Looks great, Michele! Do you use the FusionSolar integration for the sensors? Would you mind sharing your custom code?
hi, I use this integration for huawei luna2000 & sun2000: GitHub - wlcrs/huawei_solar: Home Assistant integration for Huawei Solar inverters via Modbus
here you can find yaml code & custom button card for lovelace: mickmmm/Huawei Luna 2000 Battery Time charge at main · MicheleMercuri/mickmmm · GitHub
Thank you very much, Michele! Your fast reply and uploadimg of your code is very much appreciated!
Could someone assist me in understanding the sensors used. I don’t have a tesla powerwall so am trying to adapt this to my specific setup.
If I copy this code and apply my sensors, the data is incorrect. See my comments
#--------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
#--------------------------------------------------------------------------------------------------
** UPDATE ** I think I solved the problem. I changed the charging power from watts to kw. The time remaining looks correct.
I’ve created a new sensor off my rundown sensor to project the rundown time onto the current time. I can now estimate what time my batteries will be depleted.
That looks great! Could you share the yaml or what you did to get those type of cars in your view?
Also @AllHailJ thanks again for sharing your yaml to create the sensors. Have you done anything so the updates don’t pollute your logbook? It seems like every minute I get a new logbook update of the change x 3 sensors. I’ve tried adding some lines to my configuration to filter those out, but they still show for me. Curious if this bothers anyone else and/or if there’s a recommended workaround.
@ziptbm, I used a combination of Mushroom Cards with the Room Card (GitHub - marcokreeft87/room-card: Show multiple entity states, attributes and icons in a single card in Home Assistant's Lovelace UI). I typically use the Mushroom-Template Card as it allows flexibility with the data that can be shown as well as varying icons / colours based on states etc.
I have not had any problem like you have described here. I have upgraded many times and it just happens. Sorry I can be of no help.
To clarify, I was referring to updates in the logbook (literally every time expected remaining changes, it adds an entry to the logbook), not updates to Home Assistant. Sorry for the lack of clarity.
An example here’s a screenshot of my logbook. If you notice the PW + Reserve @ Current Power
sensor that updated twice in 30 seconds. I was curious if you did anything to filter these types of events from the logbook since the utility of the update frequency is minimal.
My understanding is that this happens for all sensors, real or virtual. It’s part of the core system. If I have this behavior wrong, I hope someone will correct me. I do not filter the log book in any manner. My understanding is also that anytime an input to a sensor changes, the sensor changes and that is causing the sensor recalculation. Again if I have this wrong…
Sorry not much help!
I read in the logbook documentation that you can exclude an entity from being recorded. Maybe that’s what you are looking for so it doesn’t flood your logbook?