Dielee / volvo2mqtt

Home Assistant addon for connecting AAOS Volvos
MIT License
127 stars 25 forks source link

Configuration Issue vccapikey - kubernetes manifest #113

Closed hasselrot closed 8 months ago

hasselrot commented 8 months ago

Describe the bug Hi!

Im trying to run volvo2mqtt in my kubernetes environment. But running into configuration issues with the ENV Variables.

% kubectl logs volvo-deployment-65755cc76-kv6t6 -n home
Oct 21 21:08:21 volvo2mqtt [1] - INFO: Starting volvo2mqtt version v1.8.8
Traceback (most recent call last):
  File "/volvoAAOS2mqtt/./main.py", line 11, in <module>
    validate_settings()
  File "/volvoAAOS2mqtt/util.py", line 147, in validate_settings
    setting_keys = settings.volvoData["vccapikey"]
TypeError: string indices must be integers

Im sure it is something with the vccapikey that I am misunderstanding. I have added the primary and secondary keys that I created on the volvo developer page.

To Reproduce:
My kubernetes configuration here, with bogus vccapikeys.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: volvo-deployment
  namespace: home
spec:
  replicas: 1
  selector:
    matchLabels:
      app: volvo
  template:
    metadata:
      name: volvo
      namespace: home
      labels:
        app: volvo
    spec:
      containers:
      - name: volvo-container
        image: ghcr.io/dielee/volvo2mqtt:latest
        imagePullPolicy: Always
        env:
        - name: CONF_updateInterval
          value: "300"
        - name: CONF_babelLocale
          value: "sv_SE"
        - name: CONF_mqtt
          value: '{"broker": "10.3.0.51", "username": "", "password": "", "port": 8182}'
        - name: CONF_volvoData
          value: '{"username": "EMAILHERE", "password": "PASSWORDHERE", "vin": "VINHERE", "vccapikey": ["f9112312364666162f","ab31234bebe3234"], "odometerMultiplier": 1, "averageSpeedDivider": 1, "averageFuelConsumptionMultiplier": 1}'
        - name: TZ
          value: "Europe/Berlin"

Would very much appreciate any help! Thanks!

Dielee commented 8 months ago

The dynaconf can't load the settings as JSON. As docker container, the setting env should be something like this: @json {"username": "", "password": "", "vin": "", "vccapikey": ["key1", "key2"], "odometerMultiplier": 1, "averageSpeedDivider": 1, "averageFuelConsumptionMultiplier": 1}.

So try adding @json in front of your value.

hasselrot commented 8 months ago

Still having some issues with this in kubernetes, so I thought I would give it a try just as your documentation:

docker run -d --pull=always -e CONF_debug=true -e CONF_updateInterval=300 -e CONF_babelLocale='sv_SE' -e CONF_mqtt='@json {"broker": "10.3.0.51", "username": "", "password": "", "port": 8182}' -e CONF_volvoData='@json {"username": "EMAIL", "password": "PASSWORD", "vin": "VINHERE", "vccapikey": ["secretapikey1", "secretapikey2"], "odometerMultiplier": 1, "averageSpeedDivider": 1, "averageFuelConsumptionMultiplier": 1}' -e TZ='Europe/Berlin' --name volvo2mqtt ghcr.io/dielee/volvo2mqtt:latest

But the container only crashes. Logs:

hasselrot@ubuntu-01:~$ docker logs 16231acd1659
Oct 22 07:24:21 volvo2mqtt [1] - INFO: Starting volvo2mqtt version v1.8.8
Traceback (most recent call last):
  File "/volvoAAOS2mqtt/./main.py", line 14, in <module>
    connect()
  File "/volvoAAOS2mqtt/mqtt.py", line 40, in connect
    client.loop_start()
  File "/usr/local/lib/python3.9/site-packages/paho/mqtt/client.py", line 1799, in loop_start
    self._thread.start()
  File "/usr/local/lib/python3.9/threading.py", line 899, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread
Dielee commented 8 months ago

It looks like the container can't connect to your mqtt broker...

hasselrot commented 8 months ago

Thanks! I do see the connection in my mqtt broker:

1697976079: New connection from 172.17.0.2 on port 1883.
1697976079: New client connected from 172.17.0.2 as volvoAAOS2mqtt_lars (p2, c1, k60).
1697976079: Socket error on client volvoAAOS2mqtt_lars, disconnecting.
Dielee commented 8 months ago

Which docker version you are running?

hasselrot commented 8 months ago

Docker version 20.10.7, build f0df350

Dielee commented 8 months ago

Then I have no more ideas, sorry. As I can't reproduce this behavior...

hasselrot commented 8 months ago

@Dielee Thanks for the help! Upgraded Docker version did the trick!