Spritmonitor Vehicle Data Integration!

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
          
  

@Rui_Peixeiro
@dARoB2108

Hello everyone! Thank you for using the integration. As I mentioned, I won’t be able to provide support for now… but it’s still working because I’m invoking the Spritmonitor API. If the API is working, the integration is working.

On another note, there’s a token that I manage directly with Spritmonitor support; I’m not sure if that’s what you’re referring to.

The API documentation is here: Swagger UI
If you share the integration code, any AI can help you understand it. The data input from HA to Spritmonitor was done by another contributor; I’m not familiar with all the possible configuration parameters.

Regards and thanks

Thanks for that! You’re amazing.

Since I already had an automation where I get all the necessary infos to my phone, I added a new action to it and tried it out. However, I receive the attached error (API Errors: 1) without any clear indication of what it is related to.

All other errors I generated before that were clearly described and were easy to troubleshoot. Here is the code snippet I am trying to run.

action: spritmonitor.add_fueling
data:
  tank_id: "2"
  date: "{{ now().date() }}"
  odometer: "{{ states('sensor.robs_leon_odometer_2') | float | round(0) }}"
  quantity: >-
    {{ states('input_number.stromverbrauch_letzter_ladevorgang') | float |
    round(2) }}
  type: full
  fuelsort_id: "19"
  quantity_unit_id: "5"
  note: NoW
  attributes_tires: wintertires
  attributes_driving_style: normal
  attributes_heating: true
  vehicle_device: *REMOVED*
  trip: "22"

Is anyone able to help me with that?

Thanks!

Best regards,
RoB

You need define the latitude and longitude.

A bug in integration make this mandatory.

Thanks!
Working fine now!
Cheers,
RoB

Hi all, just to add, I have published a new beta release (thanks @matbott for adding me as a maintainer).
The new beta contains the fix for optional longitude and latitude. Also, an additional sensor that I used to have setup on my old REST connection from before this integration came along. The sensor is a derivative of the Average Energy Consumption which currently shows kWh per 100 miles/kilometres. The new sensor is a flat out Average Electricity Efficiency mi/kWh (or km/kWh depending on your config)