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

Implement TWC vitals API #77

Open
skrul opened this issue Jan 8, 2025 · 16 comments
Open

Implement TWC vitals API #77

skrul opened this issue Jan 8, 2025 · 16 comments
Labels
enhancement New feature or request

Comments

@skrul
Copy link

skrul commented Jan 8, 2025

evcc now has direct support for configuring a tesla vehicle using TeslaBleHttpProxy (thanks @wimaha!), but those the use the mobile charger (rather than a TWC) still need to configure a custom charger in evcc that uses the TeslaBleHttpProxy endpoints (see my config here).

I was wondering if TeslaBleHttpProxy has enough information in order to implement the TWC vitals API? If so, mobile charger users could use the built in evcc TWC charger support, but configure it to talk to TeslaBleHttpProxy instead of a real TWC. Much of the functionality of the built-in TWC support delegates to the vehicle, but it does make use of the following fields from the vitals response:

  • contactor_closed
  • vehicle_connected
  • session_energy_wh
  • grid_v
  • currentA_a
  • currentB_a
  • currentC_a
  • voltageA_v
  • voltageB_v
  • voltageC_v

Unfortunately I don't have a TWC so I don't know if these fields map to what is available through TeslaBleHttpProxy. It seems like this should be possible since I am able to create a custom charger in evcc that uses the TeslaBleHttpProxy endpoints.

@wimaha if the mappings exist, I can do the implementation if you think this would be a useful addition to the project!

@wimaha
Copy link
Owner

wimaha commented Jan 11, 2025

Via ble we don't have the current and voltage for each phase. We only have the sum. This is maybe no issue for the use case.
I'm open for this enhancement!

@wimaha wimaha added the enhancement New feature or request label Jan 11, 2025
@skrul
Copy link
Author

skrul commented Jan 11, 2025

@wimaha thanks! I think it could work although I'm not sure if it is the right thing to do. Alternatively I could just contribute my charger config to evcc as a template. One advantage to using the built-in TWC support is that it would make fewer requests to the proxy -- when using the custom charger config, evcc will query the proxy separately for each field, where the TWC plug in would just make one for the various fields. This excessive querying of the proxy could be helped with adding a short cache inside the proxy though.

@skrul
Copy link
Author

skrul commented Jan 11, 2025

Oh I see there is already work being done on a cache here #80 fantastic!

@MrBLJ
Copy link

MrBLJ commented Jan 12, 2025

Just my 2 cents since I'm very interested in this topic. I've been using twc3teslamate so far, to use my mobile charger with EVCC. From my limited understanding, it uses data from teslamate to emulate a TWC.

Having to rely on another service increases the risk of issues, so it'd be best to replicate this functionality using TeslaBleHttpProxy !

@skrul
Copy link
Author

skrul commented Jan 12, 2025

@MrBLJ consider using my custom charger definition for your evcc config https://github.com/skrul/evcc-config/blob/main/evcc.yaml.template#L78 -- this has worked pretty well for me so far. I may just contribute this to evcc rathe than create the vitals API. Please let me know if this is helpful!

@skrul
Copy link
Author

skrul commented Jan 12, 2025

@wimaha @MrBLJ FYI evcc-io/evcc#18194

@MrBLJ
Copy link

MrBLJ commented Jan 14, 2025

@MrBLJ consider using my custom charger definition for your evcc config https://github.com/skrul/evcc-config/blob/main/evcc.yaml.template#L78 -- this has worked pretty well for me so far. I may just contribute this to evcc rathe than create the vitals API. Please let me know if this is helpful!

Thanks a lot for sharing. I've implemented this on my end. I see that you are currently discussing about turning this into an actual EVCC template, this would be great ! Let me know if I can be of any help, for example if you need logs or data.

@MrBLJ
Copy link

MrBLJ commented Jan 20, 2025

@MrBLJ consider using my custom charger definition for your evcc config https://github.com/skrul/evcc-config/blob/main/evcc.yaml.template#L78 -- this has worked pretty well for me so far. I may just contribute this to evcc rathe than create the vitals API. Please let me know if this is helpful!

I've been using your charger definition for a few days now. One issue : my cars do not go to sleep anymore.

I have a 3 and a Y. I switched the 3 at first using your charger config :

- name: my_charger
    type: custom
    power:
      source: http
      uri: "${TESLA_BLE_PROXY}:8080/api/1/vehicles/${TESLA_VIN}/vehicle_data?endpoints=charge_state"
      method: GET
      jq: .response.response.charge_state.charger_voltage * .response.response.charge_state.charger_actual_current
      timeout: 30s
    status:
      source: http
      uri: "${TESLA_BLE_PROXY}:8080/api/1/vehicles/${TESLA_VIN}/vehicle_data?endpoints=charge_state"
      method: GET
      jq: >
        if (.response.response.charge_state.charging_state == "Charging" 
            and .response.response.charge_state.charger_power > 0) then "C"
        elif (.response.response.charge_state.charging_state == "Charging") then "B"
        elif (.response.response.charge_state.charging_state == "Stopped") then "B"
        elif (.response.response.charge_state.charging_state == "NoPower") then "B"
        elif (.response.response.charge_state.charging_state == "Complete") then "B"
        elif (.response.response.charge_state.charging_state == "Starting") then "B"
        else "A" end
      timeout: 30s
    enabled:
      source: http
      uri: "${TESLA_BLE_PROXY}:8080/api/1/vehicles/${TESLA_VIN}/vehicle_data?endpoints=charge_state"
      method: GET
      jq: (.response.response.charge_state.charging_state == "Charging" 
           and .response.response.charge_state.charger_power > 0)
      timeout: 30s
      cache: 25s
    enable:
      source: http
      uri: "${TESLA_BLE_PROXY}:8080/api/1/vehicles/${TESLA_VIN}/command/{{if .enable}}charge_start{{else}}charge_stop{{end}}"
      method: POST
      body: ""
      timeout: 30s
      cache: 25s
    maxcurrent:
      source: http
      uri: "${TESLA_BLE_PROXY}:8080/api/1/vehicles/${TESLA_VIN}/command/set_charging_amps"
      method: POST
      body: '{"charging_amps": "{{.maxcurrent}}"}'
      timeout: 30s

(all fields where adapted).

The charger works fine, no issues with it. Seeing that the model 3 would not go to sleep, I reverted back to the original config (using data from Teslamate) which solved the issue. I thought at first it could be vehicle related, so I switched the charger for the Y, and got the same result.

So somehow, on my end, this causes trouble. I have no other 3rd party services that connect to my car (no widget, no app on my watch or whatever).

I can't find a way to determine what is causing my car to stay awake, I'll look into that.

@wimaha
Copy link
Owner

wimaha commented Jan 20, 2025

Since evcc must poll some status values, the car will be always await with this config.

I think it is possible to change that with the right configuration.

Unfortunately I can look into this from mid February because I’m on a long vacation trip right know.

@giss69
Copy link

giss69 commented Feb 10, 2025

@MrBLJ
I've the same problem, evcc+[TeslaBleHttpProxy] and two cars and they don't sleep anymore.
is hier any chance to fix that because for the time being is it useless.
however I'm using recommended config:

vehicles:
  - name: tesla_white
    type: template
    template: tesla-ble
    title: tesla_white
    url: http://192.168.1.33
    port: 8080 # Wird in der Benutzeroberfläche angezeigt # Optional
    vin: XPxxxxxxxxxx # Erforderlich, wenn mehrere Fahrzeuge des Herstellers vorhanden sind # Optional
    capacity: 79 # Akku-Kapazität in kWh # Optiona
  - name: tesla_grey
    type: template
    template: tesla-ble
    title: tesla_grey
    url: http://192.168.1.33
    port: 8080 # Wird in der Benutzeroberfläche angezeigt # Optional
    vin: LRxxxxxxxxxx # Erforderlich, wenn mehrere Fahrzeuge des Herstellers vorhanden sind # Optional
    capacity: 79 # Akku-Kapazität in kWh # Optional
# site describes the EVU connection, PV and home battery

@MrBLJ
Copy link

MrBLJ commented Feb 10, 2025

@MrBLJ I've the same problem, evcc+[TeslaBleHttpProxy] and two cars and they don't sleep anymore. is hier any chance to fix that because for the time being is it useless. however I'm using recommended config:

For what it's worth, here's my current config. Works well, both cars go to sleep (as confirmed by teslamate and the fact that I have no longer vampire drain on the battery) :

# ------------------------------------------------------------------------------
# 8. Vehicle Definitions
# Documentation: https://docs.evcc.io/en/docs/reference/configuration/vehicles
# Template : https://docs.evcc.io/en/docs/devices/vehicles#tesla-ble
# ------------------------------------------------------------------------------
vehicles:
  # Model Y --------------------------------------------------------------------
  - name: modelY                                                                # Reference used in the config
    type: template                                                              # EVCC interface type
    template: tesla-ble                                                         # EVCC template reference
    title: Chonk                                                                # Name displayed in the UI
    capacity: 57                                                                # Battery capacity
    vin: XXXXXXXXXXXXXXXXX                                                      # VIN number
    url: http://192.168.20.149                                                  # URL of the Tesla BLE HTTP Proxy
    port: 8080                                                                  # Port of the Tesla BLE HTTP Proxy
  # Model 3 --------------------------------------------------------------------
  - name: model3                                                                # Reference used in the config
    type: template                                                              # EVCC interface type
    template: tesla-ble                                                         # EVCC template reference
    title: Titine                                                               # Name displayed in the UI
    capacity: 57                                                                # Battery capacity
    vin: XXXXXXXXXXXXXXXXX                                                      # VIN number
    url: http://192.168.20.149                                                  # URL of the Tesla BLE HTTP Proxy
    port: 8080                                                                  # Port of the Tesla BLE HTTP Proxy
# ------------------------------------------------------------------------------
# 6. Charger Definitions
# Documentation:https://docs.evcc.io/en/docs/reference/configuration/chargers
# See also : https://github.com/Haveacry/twc3teslamate
# ------------------------------------------------------------------------------
chargers:
  # Model Y charger ------------------------------------------------------------
  - name: modelY_charger                                                        # Reference used in the config
    type: template                                                              # EVCC interface type
    template: twc3                                                              # EVCC template reference
    host: 192.168.20.149:8002                                                   # IP address
    
  # Model 3 charger ------------------------------------------------------------
  - name: model3_charger                                                        # Reference used in the config
    type: template                                                              # EVCC interface type
    template: twc3                                                              # EVCC template reference
    host: 192.168.20.149:8001                                                   # IP address

The charger defined using TeslaBleHttpProxy was keeping the cars awake, in my experience. I'm afraid that with the recent API changes, Teslamate won't be reliable as a source to pull data for the car. Wait and see I guess.

@giss69
Copy link

giss69 commented Feb 10, 2025

@MrBLJ
do you defined charger url as TeslaBleHttpProxy? and what port 8001 and 8002 are meaning?

@MrBLJ
Copy link

MrBLJ commented Feb 10, 2025

@MrBLJ do you defined charger url as TeslaBleHttpProxy? and what port 8001 and 8002 are meaning?

Check the url I specified in my config : # See also : https://github.com/Haveacry/twc3teslamate

This is a pretty nice tool. I have two containers running, one for each car, on different ports. This emulates two tesla wall chargers, although I'm using a mobile connector and a dumb wallbox.

@skrul
Copy link
Author

skrul commented Feb 10, 2025

I've been going down this road over on the evcc repo and my current sense is that it is not possible to use TeslaBleHttpProxy as an evcc "charger" without constantly waking up the car (see evcc-io/evcc#18194 (comment)). I've since purchased a TWC and have a similar setup as @MrBLJ and it works great.

@giss69
Copy link

giss69 commented Feb 11, 2025

@MrBLJ

it works! Thank you very much!
when teslamate won't work anymore because of the new fleet api it stops to work as well?

@MrBLJ
Copy link

MrBLJ commented Feb 13, 2025

when teslamate won't work anymore because of the new fleet api it stops to work as well?

That's the current concern, but so far it looks like Teslamate could operate with the new fleet API pricing, using the base plan. Guess we'll see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants