Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/teslamate/mqtt/pubsub/vehicle_subscriber.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.


def handle_info(%Summary{} = summary, state) do
summary
Expand Down
3 changes: 2 additions & 1 deletion lib/teslamate/vehicles/vehicle/summary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule TeslaMate.Vehicles.Vehicle.Summary do
car display_name state since healthy latitude longitude heading battery_level usable_battery_level
ideal_battery_range_km est_battery_range_km rated_battery_range_km charge_energy_added
speed outside_temp inside_temp is_climate_on is_preconditioning locked sentry_mode
plugged_in scheduled_charging_start_time charge_limit_soc charger_power windows_open doors_open
plugged_in scheduled_charging_start_time charge_limit_soc charger_power charge_rate windows_open doors_open
odometer shift_state charge_port_door_open time_to_full_charge charger_phases
charger_actual_current charger_voltage version update_available update_version is_user_present geofence
model trim_badging exterior_color wheel_type spoiler_type trunk_open frunk_open elevation power
Expand Down Expand Up @@ -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?

charge_port_door_open: charge(vehicle, :charge_port_door_open),
charger_actual_current: charge(vehicle, :charger_actual_current),
charger_phases: charge(vehicle, :charger_phases),
Expand Down
1 change: 1 addition & 0 deletions website/docs/integrations/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Copy link

Choose a reason for hiding this comment

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

Hi @parkr , are you sure? As for the odometer the value extracted from the API does not change based on the gui_distance_units (always in miles), I believe it only indicates what is shown on the dashboard (gui).
I did not check for tirepressure or charge-rate, but I can imagine the API delivers the basic units, and the gui is only an indication of what is shown in the car...

Choose a reason for hiding this comment

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

Since this PR seemed abandoned and I want to have this feature I've redonde some of the changes in this new PR: #4130
Can you please review it there? I'm not 100% sure it's correct

Copy link

Choose a reason for hiding this comment

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

Hi, I'm not a user of Teslamate, so I cannot judge the PR you are proposing.
I was looking for places where charge_rate was used, and this seemed the most detailed and relevant :-)
I checked today, and with 3 phase ~13A charging (so 230x13x3 = ~8.5kW), the charge_rate indicated ~24. If assuming the car uses 0.2kWh/km (200Wh/km as indicated on the dashboard), the charge rate is 8.5 / 0.2 = 43 km/h (car indicating 40km/h, probably taking into account efficiency (~95%?). 43 km/h ~ 24.8 mi/h, which is the number indicated. This seems to confirm my previous statement that, similar to odometer, the charge_rate from the API is always provided in mi/h.

Choose a reason for hiding this comment

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

Charge rate is effectively always in mph. And your discrepancy is not only efficiency, is energy not going into the battery but being used for other things. Charge rate is a very good indicator of how the energy coming from the charge port is being used:
Plugged in using 32A * 240v = 7.68kW, car and API reporting 32A 8kw. Charge rate = 0.... I'm cooling down the cabin at 40ºC to 20ºC, no energy going into the battery! Then later it reports charge rate = 5 mph, this means in my car, 1400W only going into the battery.
This metric is so important and not being used in teslamate! Teslafi uses this to calculate energy spent cooling as you can directly calculate it.

| `teslamate/cars/$car_id/charge_port_door_open` | true | Indicates if the charger door is open |
| `teslamate/cars/$car_id/charger_actual_current` | 2.05 | Current amperage supplied by charger |
| `teslamate/cars/$car_id/charger_phases` | 3 | Number of charger power phases (1-3) |
Expand Down