Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # EV Charging Cost Calculator Blueprint
- # -------------------------------------
- # Project Description:
- # This blueprint is designed to calculate the **cheapest hour** to charge your electric vehicle (EV)
- # based on electricity prices fetched from the Nordpool integration.
- # It also provides calculations for:
- # - The total cost of charging at the current hour
- # - The total cost of charging at the cheapest hour
- # - Potential savings if you wait for the cheapest hour
- # - Energy needed to fully charge the EV (kWh)
- # - Number of hours required to fully charge the EV
- #
- # The results are stored in helper entities (input_text), which can then be displayed
- # on a Home Assistant dashboard (Lovelace) for easy monitoring and decision-making.
- #
- # Purpose:
- # This blueprint allows EV owners to optimize their charging schedules to save money
- # by charging during the cheapest electricity hours.
- # It considers additional costs like VAT and extra fees per kWh.
- #
- # Key Features:
- # - Automatically calculates the **cheapest charging window**.
- # - Displays **savings** when comparing current charging costs to the cheapest hour.
- # - Updates results dynamically when electricity prices or battery level changes.
- # - Allows integration into Lovelace dashboards for real-time cost tracking.
- #
- # -------------------------------------
- # Installation Instructions:
- # 1. Copy this blueprint YAML file and place it in the 'blueprints/automation/[YourFolderName]' directory in Home Assistant.
- # 2. Reload the automations or restart Home Assistant.
- # 3. Navigate to the Automations section in Home Assistant.
- # 4. Create a new automation, select 'Blueprints', and choose 'EV Charging Cost Calculator'.
- # 5. Configure the required inputs:
- # - Nordpool Price Entity (sensor)
- # - Battery Percentage Entity (sensor)
- # - Battery Capacity (kW)
- # - Charger Capacity (kW)
- # - VAT Percentage (%)
- # - Extra Cost per kWh (kr)
- # - Default Cost per kWh (kr)
- # - Helper Entities (input_text) for:
- # - Cheapest Start Hour
- # - Cheapest Cost
- # - Current Cost
- # - Savings
- # - Energy Needed
- # - Hours Needed
- # 6. Save the automation and it will begin calculating based on the Nordpool prices and your EV configuration.
- # 7. Add the helper entities to your Lovelace dashboard for monitoring.
- #
- # Disclaimer:
- # -------------------------------------------------------------
- # This blueprint is provided "as is" without any guarantees or warranties.
- # I take no responsibility for any issues, damages, or inaccuracies that
- # may occur as a result of using this blueprint.
- #
- # This was my first blueprint and was created as a fun project.
- # There may be calculation errors, bugs, or logical mistakes.
- #
- # **Use it at your own risk.** You are responsible for verifying
- # all results and ensuring it meets your needs. This blueprint
- # is not professionally tested, and I cannot provide support.
- #
- # If something goes wrong, or the numbers seem incorrect,
- # double-check all calculations and configurations.
- # -------------------------------------------------------------
- blueprint:
- name: EV Charging Cost Calculator
- description: Calculate the cheapest hour and cost to charge your EV based on Nordpool prices.
- domain: automation
- input:
- nordpool_entity:
- name: Nordpool Price Entity
- selector:
- entity:
- domain: sensor
- battery_percentage_entity:
- name: Battery Percentage Entity
- selector:
- entity:
- domain: sensor
- battery_capacity:
- name: Battery Capacity (kW)
- default: 40
- selector:
- number:
- min: 1
- max: 200
- charger_capacity:
- name: Charger Capacity (kW)
- default: 3.6
- selector:
- number:
- min: 1
- max: 22
- vat_percentage:
- name: VAT Percentage
- default: 25
- selector:
- number:
- min: 0
- max: 100
- extra_cost_per_kwh:
- name: Extra Cost per kWh (kr)
- default: 0.05
- selector:
- number:
- min: 0
- max: 5
- default_cost_per_kwh:
- name: Default Cost per kWh (kr)
- default: 0.5
- selector:
- number:
- min: 0
- max: 5
- cheapest_start_hour_entity:
- name: Cheapest Start Hour Helper
- selector:
- entity:
- domain: input_text
- cheapest_cost_entity:
- name: Cheapest Cost Helper
- selector:
- entity:
- domain: input_text
- current_cost_entity:
- name: Current Cost Helper
- selector:
- entity:
- domain: input_text
- savings_entity:
- name: Savings Helper
- selector:
- entity:
- domain: input_text
- energy_needed_entity:
- name: Energy Needed Helper
- selector:
- entity:
- domain: input_text
- hours_needed_entity:
- name: Hours Needed Helper
- selector:
- entity:
- domain: input_text
- trigger:
- - platform: state
- entity_id: !input nordpool_entity
- - platform: state
- entity_id: !input battery_percentage_entity
- variables:
- nordpool_entity: !input nordpool_entity
- battery_percentage_entity: !input battery_percentage_entity
- default_cost_per_kwh: !input default_cost_per_kwh
- today_prices: >
- {{ state_attr(nordpool_entity, 'today') | default([default_cost_per_kwh]) | list }}
- tomorrow_prices: >
- {{ state_attr(nordpool_entity, 'tomorrow') | default([default_cost_per_kwh]) | list }}
- combined_prices: >
- {{ today_prices + tomorrow_prices }}
- vat: !input vat_percentage
- extra_cost: !input extra_cost_per_kwh
- battery_capacity: !input battery_capacity
- charger_capacity: !input charger_capacity
- battery_percentage: >
- {{ states(battery_percentage_entity) | float(0) }}
- energy_needed_kwh: >
- {{ ((100 - battery_percentage) / 100) * battery_capacity }}
- hours_needed: >
- {{ (energy_needed_kwh / charger_capacity) | round(0, 'ceil') }}
- current_hour: >
- {{ now().hour }}
- this_cheapest_price: >
- {% set ns = namespace(min_cost=None, start_hour=None) %}
- {% for i in range(current_hour, combined_prices | length - hours_needed + 1) %}
- {% set hourly_cost = combined_prices[i:i+hours_needed] | sum %}
- {% if ns.min_cost is none or hourly_cost < ns.min_cost %}
- {% set ns.min_cost = hourly_cost %}
- {% set ns.start_hour = i %}
- {% endif %}
- {% endfor %}
- {% if ns.start_hour is not none %}
- {% if ns.start_hour < 24 %}
- {{ ns.start_hour }}
- {% else %}
- {{ (ns.start_hour - 24) | string.zfill(2) }} (Tomorrow)
- {% endif %}
- {% else %}N/A{% endif %}
- this_cheapest_cost: >
- {% set ns = namespace(min_cost=None) %}
- {% for i in range(current_hour, combined_prices | length - hours_needed + 1) %}
- {% set hourly_cost = combined_prices[i:i+hours_needed] | sum %}
- {% if ns.min_cost is none or hourly_cost < ns.min_cost %}
- {% set ns.min_cost = hourly_cost %}
- {% endif %}
- {% endfor %}
- {{ ((ns.min_cost + hours_needed * extra_cost) * (1 + vat / 100)) | round(2) if ns.min_cost is not none else 'N/A' }}
- this_current_cost: >
- {% set now_hour = current_hour %}
- {% if now_hour + hours_needed <= combined_prices | length %}
- {% set current_cost = combined_prices[now_hour:now_hour+hours_needed] | sum %}
- {{ ((current_cost + hours_needed * extra_cost) * (1 + vat / 100)) | round(2) }}
- {% else %}N/A{% endif %}
- this_saving: >
- {% set cheapest_cost = this_cheapest_cost | float(0) %}
- {% set current_cost = this_current_cost | float(0) %}
- {{ (current_cost - cheapest_cost) | round(2) if cheapest_cost != 'N/A' and current_cost != 'N/A' else 'N/A' }}
- action:
- - service: input_text.set_value
- data:
- entity_id: !input energy_needed_entity
- value: >
- {{ energy_needed_kwh | round(2) }}
- - service: input_text.set_value
- data:
- entity_id: !input hours_needed_entity
- value: >
- {{ hours_needed }}
- - service: input_text.set_value
- data:
- entity_id: !input cheapest_start_hour_entity
- value: >
- {{ this_cheapest_price }}
- - service: input_text.set_value
- data:
- entity_id: !input cheapest_cost_entity
- value: >
- {{ this_cheapest_cost }}
- - service: input_text.set_value
- data:
- entity_id: !input current_cost_entity
- value: >
- {{ this_current_cost }}
- - service: input_text.set_value
- data:
- entity_id: !input savings_entity
- value: >
- {{ this_saving }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement