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

publish charge rate to MQTT #4130

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions lib/teslamate/log/charging_process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule TeslaMate.Log.ChargingProcess do
field :end_ideal_range_km, :decimal, read_after_writes: true
field :start_rated_range_km, :decimal, read_after_writes: true
field :end_rated_range_km, :decimal, read_after_writes: true
field :charge_rate, :integer, read_after_writes: true
field :start_battery_level, :integer
field :end_battery_level, :integer
field :duration_min, :integer
Expand Down Expand Up @@ -42,6 +43,7 @@ defmodule TeslaMate.Log.ChargingProcess do
:end_ideal_range_km,
:start_rated_range_km,
:end_rated_range_km,
:charge_rate,
:start_battery_level,
:end_battery_level,
:duration_min,
Expand Down
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 @@ -39,7 +39,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

@impl true
def handle_info(%Summary{} = summary, state) do
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 charging_state 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
plugged_in scheduled_charging_start_time charge_limit_soc charger_power windows_open charge_rate
doors_open driver_front_door_open driver_rear_door_open passenger_front_door_open passenger_rear_door_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
Expand Down Expand Up @@ -104,6 +104,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),
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 test/teslamate/import_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ defmodule TeslaMate.ImportTest do
address_id: nil,
cost: nil,
duration_min: 70,
charge_rate: decimal(123),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if 123 is a realistic charge rate

Copy link
Author

Choose a reason for hiding this comment

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

It is, if configured in km it would be an equivalent ~17kW

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then charge_rate is not a self explaining variable name. duration_min is clear, but charge_rate is not.

Copy link
Author

Choose a reason for hiding this comment

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

It's the rate in distance/time et which you're effectively charging, it has the same name in the API. It's the number that gets displayed when you switch your cars battery level to distance.

start_battery_level: 57,
end_battery_level: 70,
start_date: ~U[2016-06-26 23:04:32.000000Z],
Expand Down
9 changes: 6 additions & 3 deletions test/teslamate/mqtt/pubsub/vehicle_subscriber_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriberTest do
:charger_power,
:charger_voltage,
:scheduled_charging_start_time,
:time_to_full_charge
:time_to_full_charge,
:charge_rate
] do
topic = "teslamate/cars/0/#{key}"
assert_receive {MqttPublisherMock, {:publish, ^topic, "", [retain: true, qos: 1]}}
Expand Down Expand Up @@ -145,7 +146,8 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriberTest do
ideal_battery_range_km: 230.52,
rated_battery_range_km: 230.52,
scheduled_charging_start_time: DateTime.utc_now() |> DateTime.add(60 * 60 * 10, :second),
time_to_full_charge: 2.5
time_to_full_charge: 2.5,
charge_rate: 123
mat1990dj marked this conversation as resolved.
Show resolved Hide resolved
}

send(pid, summary)
Expand Down Expand Up @@ -251,7 +253,8 @@ defmodule TeslaMate.Mqtt.PubSub.VehicleSubscriberTest do
:time_to_full_charge,
:shift_state,
:geofence,
:trim_badging
:trim_badging,
:charge_rate
] do
topic = "teslamate/account_0/cars/0/#{key}"
assert_receive {MqttPublisherMock, {:publish, ^topic, "", [retain: true, qos: 1]}}
Expand Down
4 changes: 4 additions & 0 deletions test/teslamate/vehicles/vehicle/charging_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ defmodule TeslaMate.Vehicles.Vehicle.ChargingTest do
date: _,
charge_energy_added: 0.1,
rated_battery_range_km: 1.61,
charge_rate: 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

with a charge_rate of 0 no energy would have been added, innit?

Copy link
Author

Choose a reason for hiding this comment

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

If plugged into a charger and using more energy to precondition the cabin than the charger can supply, charge rate becomes 0 when charging. This is why I want to track this specifically.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah understood, but I do want to introduce a separate test case for this.

ideal_battery_range_km: 1.61
}}

Expand All @@ -54,6 +55,7 @@ defmodule TeslaMate.Vehicles.Vehicle.ChargingTest do
date: _,
charge_energy_added: 0.2,
rated_battery_range_km: 3.22,
charge_rate: 2,
Copy link
Collaborator

Choose a reason for hiding this comment

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

these values should set to realisitc values

Copy link
Author

Choose a reason for hiding this comment

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

They're , 2km/h would be equivalent to 300w, attached you can see a 32Amp pull from a charger (7.4kW) but as preconditioning is on, only mere 240W are going to the battery (1 mi/h in this case)
IMG_2895

Copy link
Collaborator

Choose a reason for hiding this comment

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

as before, charge_rate unit is not obvious

ideal_battery_range_km: 3.22
}}

Expand All @@ -64,6 +66,7 @@ defmodule TeslaMate.Vehicles.Vehicle.ChargingTest do
date: _,
charge_energy_added: 0.3,
rated_battery_range_km: 4.83,
charge_rate: 10,
Copy link
Collaborator

Choose a reason for hiding this comment

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

these values should set to realisitc values

Copy link
Author

Choose a reason for hiding this comment

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

As before, realistic value of preconditioning lowering requirement

Copy link
Collaborator

Choose a reason for hiding this comment

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

as before

ideal_battery_range_km: 4.83
}}

Expand All @@ -76,6 +79,7 @@ defmodule TeslaMate.Vehicles.Vehicle.ChargingTest do
date: _,
charge_energy_added: 0.4,
rated_battery_range_km: 6.44,
charge_rate: 10,
Copy link
Collaborator

Choose a reason for hiding this comment

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

these values should set to realisitc values

Copy link
Author

Choose a reason for hiding this comment

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

As before

Copy link
Collaborator

Choose a reason for hiding this comment

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

as before

ideal_battery_range_km: 6.44
}}

Expand Down
1 change: 1 addition & 0 deletions test/teslamate/vehicles/vehicle_sync_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ defmodule TeslaMate.Vehicles.VehicleSyncTest do
charger_phases: :unknown,
charger_power: :unknown,
charger_voltage: :unknown,
charge_rate: :unknown,
display_name: "bar",
doors_open: nil,
elevation: nil,
Expand Down
2 changes: 2 additions & 0 deletions test/teslamate_web/controllers/car_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ defmodule TeslaMateWeb.CarControllerTest do
charger_voltage: 229,
charger_actual_current: 16,
battery_range: 200,
charge_rate: 123,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if 123 is a realistic charge rate

Copy link
Author

Choose a reason for hiding this comment

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

See previous comments

Copy link
Collaborator

Choose a reason for hiding this comment

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

as before

est_battery_range: 180,
ideal_battery_range: 175,
charging_state: "Charging",
Expand Down Expand Up @@ -316,6 +317,7 @@ defmodule TeslaMateWeb.CarControllerTest do
charging_state: "Charging",
charge_energy_added: "4.32",
ideal_battery_range: 200,
charge_rate: 123,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if 123 is a realistic charge rate

Copy link
Author

Choose a reason for hiding this comment

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

See previous comments

Copy link
Collaborator

Choose a reason for hiding this comment

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

as before

time_to_full_charge: 0.33
}
)}
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 @@ -63,6 +63,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 the user configured unit |
| `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
Loading