# EVCC config with custom charger bridged through HA REST API
#
# Use this when EVCC can't directly connect to a charger (TLS cert issues,
# API changes, device on unreachable VLAN) but the native HA integration works.
#
# Replace __HA_URL__ with http://10.0.30.10:8123 (internal HA IP)
# Replace __HA_TOKEN__ with a long-lived access token from HA
#
# Installation: Stop HA VM (qm stop 106), mount RBD disk, write to
# /mnt/haos/supervisor/homeassistant/evcc.yaml, unmount, start VM.
# Then restart EVCC add-on via Supervisor API.

network:
  schema: http
  host: 0.0.0.0
  port: 7070

log: info
interval: 30s

chargers:
  - name: wallbox
    type: custom
    status:
      source: http
      uri: __HA_URL__/api/states/sensor.ev_charger_schon_status_ladevorgang
      headers:
        Authorization: "Bearer __HA_TOKEN__"
      jq: 'if .state == "active_mode" then "C" elif .state == "sleep_mode" then "B" elif .state == "not_connected" then "A" else "F" end'
    enabled:
      source: http
      uri: __HA_URL__/api/states/switch.ev_charger_schon_manuelle_ladefreigabe
      headers:
        Authorization: "Bearer __HA_TOKEN__"
      jq: '.state == "on"'
    enable:
      source: http
      uri: __HA_URL__/api/services/switch/{{ if .enable }}turn_on{{ else }}turn_off{{ end }}
      method: POST
      headers:
        Authorization: "Bearer __HA_TOKEN__"
        Content-Type: application/json
      body: '{"entity_id": "switch.ev_charger_schon_manuelle_ladefreigabe"}'
    maxcurrent:
      source: http
      uri: __HA_URL__/api/services/number/set_value
      method: POST
      headers:
        Authorization: "Bearer __HA_TOKEN__"
        Content-Type: application/json
      body: '{"entity_id": "number.ev_charger_schon_ac_strom_begrenzung", "value": {{.maxcurrent}}}'
    power:
      source: http
      uri: __HA_URL__/api/states/sensor.ev_charger_schon_leistung_ladestation
      headers:
        Authorization: "Bearer __HA_TOKEN__"
      jq: '.state | tonumber'
    energy:
      source: http
      uri: __HA_URL__/api/states/sensor.ev_charger_schon_zahlerstand_ladestation
      headers:
        Authorization: "Bearer __HA_TOKEN__"
      jq: '.state | tonumber'
      scale: 0.001

loadpoints:
  - title: Wallbox
    charger: wallbox
    mode: pv
    phases: 0
    mincurrent: 6
    maxcurrent: 16
    enable:
      threshold: 0
      delay: 1m
    disable:
      threshold: 500
      delay: 3m
