Tesla Wall Connector: Calculate EV charging cost using Home Assistant

published on in category , Tags: tesla ev homeassistant

Tesla’s Wall Connector (3rd Gen) does not have a integration in the Tesla App and while the cost for your monthly charge can be displayed as part of the car’s charging details, it does not exactly do a great job of displaying details and stats. Since I’m running Home Assistant, I’ve integrated some sensors to read the energy consumption of the Wallbox and set up some automations to notify me about ongoing costs and to provide a monthly summary.

Here’s the config:

sensor:
  - platform: rest
    name: wall_charger_total_wh
    resource: http://192.168.7.111/api/1/lifetime # Wall Connector IP
    scan_interval: 600 # 10min
    value_template: '{{ value_json.energy_wh | float }}'
    unit_of_measurement: Wh
    device_class: energy
    state_class: total_increasing

utility_meter:
  wall_charger_monthly:
    source: sensor.wall_charger_total_wh
    cycle: monthly
  wall_charger_daily:
    source: sensor.wall_charger_total_wh
    cycle: daily

template:
  - sensor:
    - name: wall_charger_monthly_cost
      device_class: monetary
      unit_of_measurement: EUR
      state: >
        {% set energy = states('sensor.wall_charger_monthly') | float %}
        {{ ((energy / 1000) * 0.28) | round(2, default=0) }}
    - name: wall_charger_daily_cost
      device_class: monetary
      unit_of_measurement: EUR
      state: >
        {% set energy = states('sensor.wall_charger_daily') | float %}
        {{ ((energy / 1000) * 0.28) | round(2, default=0) }}
    - name: wall_charger_yesterday_cost
      device_class: monetary
      unit_of_measurement: EUR
      state: >
        {% set energy = state_attr('sensor.wall_charger_daily', 'last_period') | float %}
        {{ ((energy / 1000) * 0.28) | round(2, default=0) }}
    - name: wall_charger_last_month_cost
      device_class: monetary
      unit_of_measurement: EUR
      state: >
        {% set energy = state_attr('sensor.wall_charger_monthly', 'last_period') | float %}
        {{ ((energy / 1000) * 0.28) | round(2, default=0) }}

automation:
- id: '1656416188951'
  alias: Wallbox Cost Notification (daily)
  description: ''
  trigger:
  - platform: time
    at: '21:00:00'
  condition: []
  action:
  - service: notify.notify
    data:
      title: Wallbox cost
      message: 'Cost today: {{ ''%.2f'' | format(states.sensor.wall_charger_daily_cost.state | float) }} EUR

        Cost yesterday: {{ ''%.2f'' | format(states.sensor.wall_charger_yesterday_cost.state| float) }} EUR'
  mode: single
- id: '1656416188912'
  alias: Wallbox Cost Notification (monthly)
  description: ''
  trigger:
  - platform: time
    at: '17:00:00'
  condition:
  - condition: template
    value_template: '{{ now().day == 1 }}'
  action:
  - service: notify.notify
    data:
      title: Wallcharger Summary
      message: 'Cost last month: {{ ''%.2f'' | format(states.sensor.wall_charger_last_month_cost.state | float) }} EUR.'
  mode: single

I admit it’s a bit janky and does not use the built-in HA Wall Connector integration, but I figured that’s good enough and gives me a bit more control about raw data, update intervals etc. The 0.28 is the utility price per kWh which could also be a separate entity, but I didn’t bother since it does not change that often.

Home Assistant Notification showing the EV charging cost