Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add charge_rate to MQTT broker #2952

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jonnylangefeld
Copy link

I'm switching from the Home Assistant Tesla integration to TeslaMate. I had a dashboard where I displayed the charge_rate. This was the only value I was missing in the mqtt topics from TeslaMate.

I was wondering if there was a reason why it was not exported? It is covered by the vehicle state api call:
https://github.com/adriankumpf/teslamate/blob/7a9c6b9ad1b2b03f424f46f652a53b831df73697/lib/tesla_api/vehicle/state.ex#L38

I'd love to see this added.

I'm switching from the Home Assistant Tesla integration to TeslaMate. I had a dashboard where I displayed the `charge_rate`. This was the only value I was missing in the mqtt topics from TeslaMate.

I was wondering if there was a reason why it was not exported?
It is covered by the vehicle state api call:
https://github.com/adriankumpf/teslamate/blob/7a9c6b9ad1b2b03f424f46f652a53b831df73697/lib/tesla_api/vehicle/state.ex#L38

I'd love to see this added.
@mat1990dj
Copy link

This is exactly what I mentioned here #2280 !
I really miss this one

@mat1990dj
Copy link

@adriankumpf Is there a possibility of merging this? I miss this metric since day 1 of switching from teslafi to teslamate

@Dulanic Dulanic assigned Dulanic and unassigned Dulanic Nov 13, 2023
@Dulanic
Copy link
Collaborator

Dulanic commented Nov 13, 2023

@NirKli Do you think you can take a look at this? Once I get more up to date /w my understanding of the processes/elixir, maybe I can review basic stuff like this. Do you know if just adding it here is good enough or is there areas, we may need to add it to? I still have a few outstanding things I need to learn about how the whole process works :)

@mat1990dj
Copy link

❣️

@@ -45,7 +45,8 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriber do

@always_published ~w(charge_energy_added charger_actual_current charger_phases
charger_power charger_voltage scheduled_charging_start_time
time_to_full_charge shift_state geofence trim_badging)a
time_to_full_charge shift_state geofence trim_badging
charge_rate)a
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as my knowledge extends, if the goal of this PR is to add a new field to MQTT that only gets updated when its value changes, then changes to the VehicleSubscriber module might be unnecessary. The existing logic in this module already handles conditional publishing based on whether field values have changed. Therefore, just adding the new field to the Summary struct should be sufficient, provided it's not included in the @always_published list, which forces fields to be published regardless of value changes.

@@ -58,6 +58,7 @@ Vehicle data will be published to the following topics:
| `teslamate/cars/$car_id/plugged_in` | true | If car is currently plugged into a charger |
| `teslamate/cars/$car_id/charge_energy_added` | 5.06 | Last added energy in kWh |
| `teslamate/cars/$car_id/charge_limit_soc` | 90 | Charge Limit Configured in Percentage |
| `teslamate/cars/$car_id/charge_rate` | 0.0 | Charge rate in km per hour |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://developer.tesla.com/docs/fleet-api?python#vehicle_data, charge_rate could be mi/hr or km/hr. The field gui_settings defines it:

Screenshot 2023-11-13 at 9 02 28 AM

Is this always km/hr and Teslamate converts it to the user's desired units, or is km/hr your experience because your GUI settings reflect that?

@@ -87,6 +87,7 @@ defmodule TeslaMate.Vehicles.Vehicle.Summary do
charge_current_request_max: charge(vehicle, :charge_current_request_max),
charge_energy_added: charge(vehicle, :charge_energy_added),
charge_limit_soc: charge(vehicle, :charge_limit_soc),
charge_rate: charge(vehicle, :charge_rate),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a test to one of the following would be good:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fields added to the Summary module are typically published to MQTT. Have you verified that the new field is pushed correctly in various vehicle states such as driving, charging, and idling?

@parkr
Copy link

parkr commented Nov 13, 2023

@Dulanic Once tests are added, the test GitHub Actions should be run for this PR.

@@ -45,7 +45,8 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriber do

@always_published ~w(charge_energy_added charger_actual_current charger_phases
charger_power charger_voltage scheduled_charging_start_time
time_to_full_charge shift_state geofence trim_badging)a
time_to_full_charge shift_state geofence trim_badging
charge_rate)a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as my knowledge extends, if the goal of this PR is to add a new field to MQTT that only gets updated when its value changes, then changes to the VehicleSubscriber module might be unnecessary. The existing logic in this module already handles conditional publishing based on whether field values have changed. Therefore, just adding the new field to the Summary struct should be sufficient, provided it's not included in the @always_published list, which forces fields to be published regardless of value changes.

@JakobLichterfeld JakobLichterfeld added enhancement New feature or request kind:documentation Adds or improves documentation area:teslamate Related to TeslaMate core labels Nov 16, 2023
@mat1990dj
Copy link

Is there anything preventing this branch to be merged?

@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented Feb 7, 2024

Is there anything preventing this branch to be merged?

Yes, we do not have any CI test running on this PR. Please update the branch to include latest master

@JakobLichterfeld JakobLichterfeld removed the kind:documentation Adds or improves documentation label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:teslamate Related to TeslaMate core enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants