Hello there, the Tesla Automation by https://github.com/alandtse/tesla Alandtse provides enough data to track trip and consumption.
I set up six input number helpers:
- battery trip start
- battery trip end
- odometer trip start
- odometer trip end
- datetime trip start
- datetime trip end
I populate this helpers listing for change in shift status. From P to D an automation populates the "trip start" helpers, from D to P another automation popluates the "trip ends" .
I could easily create another helper where store the consumption for a trip, but this would be limited because (i) I can store only one value (consumption or date, I'd need two helpers but I'd never be able to "link" date and consumption data) and (ii) I'm not sure how HomeAssistant would store this information.
I asked ChatGPT and it suggested to create a input_text helper to create a JSON file with the information and append the data at every run of the automation, but the code doesn't work.
here it is:
action: - service: input_text.set_value data_template: entity_id: input_text.tesla_trip_log value: > "distance_km": "{{ (states('input_number.tesla_trip_odometer_end') | float - states('input_number.tesla_trip_odometer_start') | float) | round(2) }}" } %} {% set current_log = states('input_text.tesla_trip_log') %} {% if current_log != 'unknown' %} {{ current_log + '\n' + new_trip | tojson }} {% else %} {{ new_trip | tojson }} {% endif %} {% set new_trip = { "timestamp": "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}",
Any help?