I used a few sensors/helpers and automations to achieve this
First I created few input_datetime helpers to track the trip start time, trip end time, and duration.
Few input_number / sensors for tracking consumption, kwh used, battery start, battery end %, odometer start km, odometer end km.
Then I created an automation to track the start of the trip.
It will be triggered when moving_status changes from False to true, or if odometer value changes.
Once its triggered I will set a counter to 1 to identify that trip is started, and will start trip again only if this counter is reset.
If this condition matches, I will set current time as trip_start time, current battery level as trip start level, and current odometer as trip start odometer.
alias: Trip_start_parameters_set
description: ""
trigger:
- platform: state
entity_id:
- sensor.e2008_odometer
id: "1"
- platform: state
entity_id:
- sensor.e2008_battery_level
id: "2"
- platform: state
entity_id:
- sensor.moving_status
from: "False"
to: "True"
id: "3"
condition:
- condition: state
entity_id: counter.trip_start_counter
state: "0"
- condition: template
value_template: >-
{{ trigger.from_state.state != "unavailable" and trigger.to_state.state !=
"unavailable" }}
- condition: state
entity_id: sensor.e2008_preconditioning_status
state: Disabled
- condition: state
entity_id: sensor.e2008_charging_status
state: Disconnected
action:
- service: input_datetime.set_datetime
data:
timestamp: "{{ as_timestamp(now()) }}"
target:
entity_id: input_datetime.trip_start_time
- if:
- condition: trigger
id:
- "1"
then:
- service: input_number.set_value
data:
value: >-
{{ states.sensor.e2008.attributes["timed_odometer"]["mileage"] |
float - 0.1 }}
target:
entity_id: input_number.trip_start_odometer
else:
- service: input_number.set_value
data:
value: >-
{{ states.sensor.e2008.attributes["timed_odometer"]["mileage"] |
float }}
target:
entity_id: input_number.trip_start_odometer
- if:
- condition: trigger
id:
- "2"
then:
- service: input_number.set_value
data:
value: >-
{{ (states.sensor.e2008.attributes["energy"][0]["level"] | int) - 1
}}
target:
entity_id: input_number.trip_start_battery_level
else:
- service: input_number.set_value
data:
value: "{{ states.sensor.e2008.attributes[\"energy\"][0][\"level\"] }}"
target:
entity_id: input_number.trip_start_battery_level
- service: input_text.set_value
data:
value: >-
{{ states.sensor.e2008_position.state.split(", ")[1] | replace("[","") |
replace("]","") | float() }} , {{
states.sensor.e2008_position.state.split(", ")[0] | replace("[","") |
replace("]","") | float() }}
target:
entity_id: input_text.trip_start_position
- service: counter.set_value
data:
value: 1
target:
entity_id: counter.trip_start_counter
- service: notify.mobile_app_pixel_7_pro
data:
message: Trip started at {{ states.input_datetime.trip_start_time.state }}
mode: single
Something like this
and end the trip like this
alias: trip_end_parameters_set
description: ""
trigger:
- platform: template
value_template: >-
{{ now() > ((states.sensor.e2008_odometer.last_updated | as_local) +
timedelta(minutes=5)) }}
condition:
- condition: template
value_template: "{{ states.sensor.e2008_odometer.state != \"unavailable\" }}"
- condition: state
entity_id: counter.trip_start_counter
state: "1"
- condition: template
value_template: >-
{{ now() > ((states.sensor.e2008_odometer.last_updated | as_local) +
timedelta(minutes=5)) }}
action:
- service: counter.reset
data: {}
target:
entity_id: counter.trip_start_counter
- service: input_datetime.set_datetime
data:
timestamp: >-
{{ (as_timestamp(states.sensor.e2008_odometer.last_updated | as_local))
}}
target:
entity_id: input_datetime.trip_end_time
- service: input_number.set_value
data:
value: "{{ states.sensor.e2008.attributes[\"energy\"][0][\"level\"] }}"
target:
entity_id: input_number.trip_end_battery_level
- service: input_number.set_value
data:
value: "{{ states.sensor.e2008.attributes[\"timed_odometer\"][\"mileage\"] }}"
target:
entity_id: input_number.trip_end_odometer
- service: input_text.set_value
data:
value: >-
{{ states.sensor.e2008_position.state.split(", ")[1] | replace("[","") |
replace("]","") | float() }} , {{
states.sensor.e2008_position.state.split(", ")[0] | replace("[","") |
replace("]","") | float() }}
target:
entity_id: input_text.trip_end_position
- service: google_sheets.append_sheet
data:
config_entry: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
data:
Start time: "{{ states.input_datetime.trip_start_time.state }}"
End time: "{{ states.input_datetime.trip_end_time.state }}"
Duration: "{{ states.sensor.e2008_trip_duration.state }}"
start latitude: >-
{{ states.input_text.trip_start_position.state.split(",")[1] |
replace("[","") | replace("]","") | float() }}
start longitude: >-
{{ states.input_text.trip_start_position.state.split(",")[0] |
replace("[","") | replace("]","") | float() }}
end latitude: >-
{{ states.input_text.trip_end_position.state.split(",")[1] |
replace("[","") | replace("]","") | float() }}
end longtitude: >-
{{ states.input_text.trip_end_position.state.split(",")[1] |
replace("[","") | replace("]","") | float() }}
Average Speed: "{{ states.sensor.e2008_trip_average_speed.state}}"
Start Odometer: "{{ states.input_number.trip_start_odometer.state }}"
End odometer: "{{ states.input_number.trip_end_odometer.state }}"
Total km: "{{ states.sensor.e2008_trip_total_km.state }}"
Start Battery level: "{{ states.input_number.trip_start_battery_level.state }}"
End Battery level: "{{ states.input_number.trip_end_battery_level.state }}"
Total battery used: "{{ states.sensor.e2008_trip_total_battery_used.state }}"
Trip consumption: "{{ states.sensor.e2008_trip_consumption.state }}"
- service: notify.mobile_app_pixel_7_pro
data:
message: >-
Trip completed at {{ states.input_datetime.trip_end_time.state }} {{-
'\n' -}} Trip KM {{ states.sensor.e2008_trip_total_km.state | round (2)
}} km {{- '\n' -}} Trip duration {{
states.sensor.e2008_trip_duration.state }} {{- '\n' -}} Trip Consumption
{{ states.sensor.e2008_trip_consumption.state | round (2) }} kwh/100km
mode: single
You need to install google sheets integration to add to google sheets and there are good documentations available on how to do that.
Similiarly you can do for charging data also
Now you can make a glance card for these sensors or helpers to display these values in dashboard