Hi @dARoB2108 , I already have the submission of data to Spritmonitor working!
Matbott stopped updating this integration and no information was added on how to send charging data to Spritmonitor, but fortunately everything still works.
Here is my complete Package (/homeassistant/packages/spritmonitor.yaml) for submitting the data.
To obtain the energy, I use a Tongou Smart circuit breaker (TO-Q-SY2-163JZT). My Renault Zoe has HA integration, but I don’t have much data available.
To save the initial value, I use the charging cable plug-in (sensor.zoe_plug_state) as a trigger, and to submit the data, the cable unplugging. I have the condition consumed > 0.5 kWh to avoid submitting empty charges or when charging outside the home.
In cars that provide charging energy data, it is possible to change the automation to also submit charges outdoors.
# Temporary for save energy at the start charge
input_number:
zoe_charge_start_energy:
name: Zoe Energia início sessão
min: 0
max: 99999
step: 0.001
mode: box
unit_of_measurement: kWh
template:
- sensor:
# Calc energy per charge session, from Power Metter
- name: "Zoe Energia por Sessão"
unique_id: zoe_energia_por_sessao
unit_of_measurement: "kWh"
device_class: energy
state_class: total
state: >
{% set total = states('sensor.evse_power_energy') | float(0) %}
{% set inicio = states('input_number.zoe_charge_start_energy') | float(0) %}
{% set diff = (total - inicio) | float(0) %}
{{ (0 if diff < 0 else diff) | round(2) }}
# Current Battery Capacity (Constant)
- name: "Zoe Capacidade Utilizavel"
state: 33.62 # 41 kWh * 0.82 SOH
unit_of_measurement: "kWh"
icon: "mdi:battery-heart-variant"
# energy on car battery
- name: "Zoe Energia na Bateria"
unit_of_measurement: "kWh"
device_class: ENERGY_STORAGE
state_class: measurement
state: >
{% set bl = states('sensor.zoe_battery_level') | float %}
{% set bt = states('sensor.zoe_capacidade_utilizavel') | float %}
{% set consumption = 0 %}
{% set consumption = (bl * bt) / 100 %}
{{ consumption | round(2, default=0) }}
automation:
# Automation to save to temporary the energy at the charge start
- alias: Zoe - Guardar energia início sessão
mode: single
trigger:
- platform: state
entity_id: sensor.zoe_plug_state
from: "unplugged"
to: "plugged"
condition:
# Check if the current is 0 before proceeding.
- condition: state
entity_id: sensor.evse_power_current
state: "0"
action:
# Saves the initial energy value.
- service: input_number.set_value
target:
entity_id: input_number.zoe_charge_start_energy
data:
value: "{{ states('sensor.evse_power_energy') | float(0) }}"
# Automation to submit the charge to Spritmonitor
- alias: Zoe - Submeter carregamento Spritmonitor
mode: single
trigger:
- platform: state
entity_id: sensor.zoe_plug_state
from: "plugged"
to: "unplugged"
condition:
# Optional: only if you have consumed > 0.5 kWh, for example.
- condition: template
value_template: >
{{ states('sensor.zoe_energia_por_sessao') | float(0) > 0.5 }}
action:
- service: spritmonitor.add_fueling
data:
vehicle_device: d63db98cf1tr56456456801c1eff956655a
tank_id: "1"
date: "{{ now().date() }}"
quantity: "{{ states('sensor.zoe_energia_por_sessao') | float(0) | round(2) }}"
type: >
{% if states('sensor.zoe_battery_level') | int(0) == 100 %}
full
{% else %}
notfull
{% endif %}
fuelsort_id: "19"
quantity_unit_id: "5"
odometer: "{{ states('sensor.zoe_mileage') | int(0) }}"
trip: >
{% set odo = states('sensor.zoe_mileage') | float(0) %}
{% set last = states('sensor.renault_zoe_last_refuel_odometer') | float(0) %}
{{ (odo - last) | round(1) }}
price: "0.05"
currency_id: "0"
pricetype: "1"
percentage: "{{ states('sensor.zoe_battery_level') | int(0) }}"
charge_info_source: source_wallbox
streets:
- city
- land
attributes_tires: summertires
attributes_driving_style: normal
attributes_ac: true
attributes_heating: true
latitude: "{{ state_attr('zone.home', 'latitude') | float | round(6) }}"
longitude: "{{ state_attr('zone.home', 'longitude') | float | round(6) }}"
- service: persistent_notification.create
data:
title: "Spritmonitor"
message: >
Carregamento enviado para Spritmonitor:
{{ states('sensor.zoe_energia_por_sessao') }} kWh,
bateria {{ states('sensor.zoe_battery_level') }}%,
odómetro {{ states('sensor.zoe_mileage') }} km.
# Desliga o switch do EVSE
- service: switch.turn_off
target:
entity_id: switch.evse_power
