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

Expose Charging Rate (Amps) #93

Closed
jherby2k opened this issue Oct 29, 2021 · 15 comments
Closed

Expose Charging Rate (Amps) #93

jherby2k opened this issue Oct 29, 2021 · 15 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@jherby2k
Copy link

jherby2k commented Oct 29, 2021

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.

@alandtse alandtse added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Oct 29, 2021
@alandtse
Copy link
Owner

Dupe of #86, but that was closed. Some of the earlier discussion from there is relevant.

@jherby2k
Copy link
Author

I'm taking a stab at this, but i'm still at the "extremely confused" stage of HA development.

@IIDemoniaKII

This comment has been minimized.

@alandtse

This comment has been minimized.

@alandtse
Copy link
Owner

alandtse commented Nov 4, 2021

What about this? https://github.com/tmjo/charger-card

@alandtse
Copy link
Owner

alandtse commented Nov 4, 2021

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:
image

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.

@purcell-lab
Copy link
Contributor

Playing with some templates and the config has gotten me this far today.

image

@purcell-lab
Copy link
Contributor

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:
tmjo/charger-card#12
tmjo/charger-card#6

Using the following HA Customs Components:

EV Charger Card
Tesla Style Power Card
Tesla Custom Component
SolarEdge MODBUS

Screenshot 2021-11-21 14 14 08

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

@increato
Copy link

increato commented Jan 6, 2022

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...

@marcospg75
Copy link

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! :)

@Olen
Copy link
Contributor

Olen commented Jan 17, 2022

@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
Copy link
Owner

@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?

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.

@Olen
Copy link
Contributor

Olen commented Jan 17, 2022

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

@marcospg75
Copy link

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 :)

@Olen
Copy link
Contributor

Olen commented Jan 18, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants