tesla
tesla copied to clipboard
Expose Charging Rate (Amps)
Is your feature request related to a problem? Please describe. I would like to be able to directly control the car's charging rate. THis is now possible via the new API endpoint CHARGING_AMPS (requires vehicle 2021.36.5+).
Describe the solution you'd like A number entity that lets you set the current, from 5 amps to the vehicle maximum (too tricky? Could just use 48, but some cars won't take more than 32).
Describe alternatives you've considered Just calling the custom api via the below from an automation triggered by an input_number works well, but it would be nice to be able to rate limit it, check for errors etc.
service: tesla_custom.api
data:
command: CHARGING_AMPS
parameters:
path_vars:
vehicle_id: '{{ state_attr(''binary_sensor.<car_name>_online_sensor'', ''id'') }}'
charging_amps: 16
Additional context Until now i've been using TWCManager to control the charge rate using the wall charger itself. The use case being to track solar production and charge your car using solar power exclusively. TWCManager is somewhat error prone. The codebase is a bit unstable, and it requires a hardware hack i'd just as soon eliminate if possible.
Dupe of #86, but that was closed. Some of the earlier discussion from there is relevant.
I'm taking a stab at this, but i'm still at the "extremely confused" stage of HA development.
Hello,
Does not work here
Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/tesla_custom/services.py:89 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 22:18:15 (3 occurrences) Last logged: 22:19:44
[140691402245792] Error handling message: Unknown error Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 523, in handle_execute_script await script_obj.async_run(msg.get("variables"), context=context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1243, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 353, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 371, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 571, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service await handler.job.target(service_call) File "/config/custom_components/tesla_custom/services.py", line 43, in async_call_tesla_service await api(service_call) File "/config/custom_components/tesla_custom/services.py", line 89, in api return await controller.api(name=command, path_vars=path_vars, **parameters) File "/usr/local/lib/python3.9/site-packages/teslajsonpy/controller.py", line 167, in wake_up result = await wrapped(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/teslajsonpy/controller.py", line 1195, in api return await self.__connection.post( File "/usr/local/lib/python3.9/site-packages/teslajsonpy/connection.py", line 167, in post return await self.__open( File "/usr/local/lib/python3.9/site-packages/teslajsonpy/connection.py", line 218, in __open raise TeslaException(resp.status_code) teslajsonpy.exceptions.TeslaException
Does not work here
This is not the right thread to report in. See #72
What about this? https://github.com/tmjo/charger-card
I played around with it a bit. It probably needs some work to support us natively, but you can get something like this pretty easy:
Their entities/limits are hardcoded in the javascript, but it probably can be generalized or a local copy can be modified. They already have a lot of handling and the fact you can defined attributes as sensors should allow the constants to be rewritten so that it's accepted as a stats object instead of an entity name. Their limit only supports fixed multiples, but that may be enough initially.
Playing with some templates and the config has gotten me this far today.
Great EV charging tracking solar production which was up and down during the day. (Need to switch from teslafi sensors to tesla custom component sensors).
Cross posting: https://github.com/tmjo/charger-card/issues/12 https://github.com/tmjo/charger-card/issues/6
Using the following HA Customs Components:
EV Charger Card Tesla Style Power Card Tesla Custom Component SolarEdge MODBUS
sensors.yaml: [ Create template values in the same structure as required via Easee Charger card ]
easee_charger_status:
friendly_name: "Easee EV Charger - TeslaFi"
value_template: '{{ states("sensor.teslafi_charging_state") }}'
attribute_templates:
name: '{{ states("sensor.teslafi_carname") }}'
sessionEnergy: '{{ states("sensor.teslafi_energy_added_kw") }}'
totalPower: '{{ states("sensor.teslafi_power") }}'
ratedCurrent: '32'
siteKey: 'XXX'
easee_charger_power:
friendly_name: "Easee Power"
value_template: '{{ states("sensor.ev_power") }}'
unit_of_measurement: W
easee_charger_session_energy:
friendly_name: "Easee Energy"
unit_of_measurement: kWh
value_template: '{{ states("sensor.teslafi_energy_added_kw") }}'
easee_charger_online:
friendly_name: "Easee Onine"
value_template: '{{ states("binary_sensor.duka_online_sensor") }}'
easee_charger_smart_charging:
friendly_name: "Easee Smart Charging"
value_template: '{{ states("switch.duka_charger_switch") }}'
easee_charger_current:
friendly_name: "Easee Current"
unit_of_measurement: A
value_template: '{{ states("sensor.teslafi_charger_actual_current") }}'
easee_charger_voltage:
friendly_name: "Easee Voltage"
unit_of_measurement: V
value_template: '{{ states("sensor.teslafi_charger_voltage") }}'
easee_charger_update_available:
friendly_name: "Easee Update Available"
unit_of_measurement: V
value_template: '{{ states("binary_sensor.duka_update_available_sensor") }}'
Card Configuration: [ Configure Charger Card and include buttons to charger switch and solar tracking ]
type: custom:charger-card
entity: sensor.easee_charger_status
chargerImage: Anthracite
compact_view: false
show_stats: true
stats:
default:
- entity_id: sensor.duka_charging_rate_sensor
attribute: charger_actual_current
subtitle: Actual Current
unit: A
- entity_id: sensor.duka_charging_rate_sensor
attribute: charge_current_request
subtitle: Requested Current
unit: A
- entity_id: sensor.duka_charging_rate_sensor
attribute: time_left
subtitle: Time Left
unit: h
- entity_id: switch.duka_charger_switch
subtitle: Charger Switch
- entity_id: automation.tesla_charging
subtitle: Solar Tracking
shortcuts:
- name: Tesla High
service: script.tesla_high
icon: mdi:solar-power
service_data: '16'
show_name: true
show_leds: true
show_status: true
show_collapsibles: true
show_toolbar: true
customCardTheme: theme_default
automation.tesla_charging [Every minute, if car is charging, during daylight call script to set desired charging current]
alias: Tesla Charging
description: ''
trigger:
- platform: time_pattern
minutes: '*'
condition:
- condition: state
entity_id: binary_sensor.duka_charger_sensor
state: Charging
attribute: charging_state
for:
hours: 0
minutes: 0
seconds: 0
milliseconds: 0
- condition: sun
before: sunset
after: sunrise
action:
- service: script.tesla_solar
mode: single
script.tesla_solar: [ Call tesla_custom.api to set CHARGING_AMPS = PV generation / Voltage / Phases ]
alias: Tesla Solar
sequence:
- service: tesla_custom.api
data:
command: CHARGING_AMPS
parameters:
path_vars:
vehicle_id: '{{ state_attr(''binary_sensor.duka_online_sensor'', ''id'') }}'
charging_amps: >-
{{ (states('sensor.modbus_generation')|int /
states('sensor.ev_phases')|int /
states('sensor.ev_voltage')|int)|int}}
mode: single
Really would love to see this feature being added, since I have no access to the charger itself (being a Powerdale Nexxtender, that was installed by my employer). So if I can find a way to consume my solar energy by automatically adjusting the charging amps of the Tesla that would be the best way for me...
It would be a great new feature as you can create a smart charger with only a plug, the OEM Tesla charger and Home Assisstant! as you can adapt the charge rate to the home consuming power in real time! :)
@alandtse Do you think it makes sense to create "shortcut" service calls for some of the things that can be done to the car?
E.g. this setting of charge_amps
, and the same for setting charge_limit_soc
and possibly a few more that are not already switches etc. It is possible to do it using the general service tesla_custom.api
today, but would it be better if we added more service calls like tesla_custom.set_charge_limit_soc
and tesla_custom.set_charge_amps
or do you feel that is redundant when the whole API is already exposed?
@alandtse Do you think it makes sense to create "shortcut" service calls for some of the things that can be done to the car?
E.g. this setting of
charge_amps
, and the same for settingcharge_limit_soc
and possibly a few more that are not already switches etc. It is possible to do it using the general servicetesla_custom.api
today, but would it be better if we added more service calls liketesla_custom.set_charge_limit_soc
andtesla_custom.set_charge_amps
or do you feel that is redundant when the whole API is already exposed?
I exposed the API so everything was available. But I didn't want to try to expose everything via HA UI or by writing hundreds of service calls. Perhaps there's an easy way to automate the generation of service calls. I'm not opposed but each custom one increases the maintenance burden particularly if Tesla changes the call. As you can tell I'm only bug fixing this now as I'm working on other projects. Feel free to take on what is interesting to you.
I tend to agree with you. It is pretty easy to write a script to send the correct API-calls, and use that in automations, so maybe we should just add a few examples in the Wiki.
I have this for setting charge_limit:
tesla_set_charge_limit_soc:
alias: Tesla Set Charge Limit SOC
mode: restart
sequence:
- service: tesla_custom.api
data:
command: CHANGE_CHARGE_LIMIT
parameters:
path_vars:
vehicle_id: "{{ state_attr('binary_sensor.my_car_online_sensor', 'id') }}"
percent: "{{ states('input_number.my_car_charge_limit') | int(default=90) }}"
wake_if_asleep: true
It uses an input_number
as the source for the limit:
my_car_charge_limit:
name: My Car Charge Limit
min: 0
max: 100
step: 5
icon: mdi:battery
unit_of_measurement: '%'
This is now pretty easy to trigger in an automation, just adjusting the input_number and calling the service script.tesla_set_charge_limit_soc
I can undertand... but keep in mind that not all Home Assistant users have the right skills to write a script to solve this. IMHO people will be grateful to have this important parameter editable in a simpler way :)
I understand that. Please feel free to add a PR.
In the mean time, I added the example above, with some more info, to the Wiki https://github.com/alandtse/tesla/wiki/Modify-Charge-Limit
This could also be used as a starting point for creating either a blueprint in HA or just another wiki page winth a similar example for charge amps.