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

TeslaMate crashed, halting add-on; Cannot index string with string "title" #32

Closed
swa72 opened this issue Aug 22, 2024 · 14 comments · Fixed by #37
Closed

TeslaMate crashed, halting add-on; Cannot index string with string "title" #32

swa72 opened this issue Aug 22, 2024 · 14 comments · Fixed by #37

Comments

@swa72
Copy link

swa72 commented Aug 22, 2024

I've fiddled around with both the PostgresSQL add-on and the Grafana add-on (was working fine with InfluxDB before) but cannot get Teslamate to even start. Anyone any hint?

Log files says ...

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun nginx (no readiness notification)
services-up: info: copying legacy longrun teslamate (no readiness notification)
s6-rc: info: service legacy-services successfully started
[19:59:34] INFO: Checking for Grafana folder: TeslaMate
jq: error (at <stdin>:1): Cannot index string with string "title"
[20:59:34] ERROR: TeslaMate crashed, halting add-on
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

I start Grafana with

plugins:
  - natel-discrete-panel
  - grafana-googlesheets-datasource
  - grafana-piechart-panel
  - pr0ps-trackmap-panel
  - natel-plotly-panel
custom_plugins:
  - name: panodata-map-panel
    url: >-
      https://github.com/panodata/panodata-map-panel/releases/download/0.16.0/panodata-map-panel-0.16.0.zip
    unsigned: true
env_vars:
  - name: GF_SECURITY_ADMIN_USER
    value: xxx
  - name: GF_SECURITY_ADMIN_PASSWORD
    value: xxx
ssl: true
certfile: fullchain.pem
keyfile: privkey.pem

Teslamate starts with ...

database_user: yyy
database_pass: yyy
database_name: teslamate
database_host: 29b65938-postgres
database_port: 5432
database_ssl: false
grafana_import_dashboards: true
grafana_folder_name: TeslaMate
grafana_host: a0d7b954-grafana
grafana_port: 3000
grafana_user: xxx
grafana_pass: xxx
disable_mqtt: true
mqtt_host: core-mosquitto
mqtt_user: ""
mqtt_pass: ""
mqtt_tls: false
mqtt_tls_accept_invalid_certs: false
mqtt_namespace: ""
timezone: Europe/London
import_dir: /share/teslamate
default_geofence: ""
encryption_key: 0b28f92c3fe07efa13755c25481c5dd375aade396d03f7d2e861901abc45e29d
env_vars: []
@lildude
Copy link
Owner

lildude commented Aug 23, 2024

This will be failing on this command:

FLD=$(curl --silent --show-error \
--user "$LOGIN" -H "Content-Type: application/json" \
$URL/api/folders | jq ".[] | select(.title==\"$FOLDER_NAME\")")

This suggests the call to the Grafana API isn't returning data in the expected format.

Is Grafana definitely running and accessible on port 3000 and accessible by the user you've defined?

What do you get if you SSH into your HA and run (replace $USER:$PASS with your configured Grafana username and password):

curl --silent --show-error \
    --user "$USER:$PASS" \
    -H "Content-Type: application/json" \     
    http://a0d7b954-grafana:3000/api/folders

As an aside, it looks like I’ve got another location to make things more robust. This shouldn’t stop the whole plugin from starting.

@swa72
Copy link
Author

swa72 commented Aug 23, 2024

Thanks for the quick reply. It shows

➜  config git:(main) curl --silent --show-error --user "xxx:xxx" -H "Content-Type: application/json" http://a0d7b954-grafana:3000/api/folders 
{"extra":null,"message":"Invalid username or password","messageId":"password-auth.failed","statusCode":401,"traceID":""}

Odd, I thought I start Grafana with

env_vars:
  - name: GF_SECURITY_ADMIN_USER
    value: xxx
  - name: GF_SECURITY_ADMIN_PASSWORD
    value: xxx

Lets assume, I follow "Note that the security admin password and usernames can only [...] or remove the add-on and re-add it.". Will I lose all my dashboard data, etc. or is this stored somewhere in InfluxDB?

@lildude
Copy link
Owner

lildude commented Aug 23, 2024

Will I lose all my dashboard data, etc. or is this stored somewhere in InfluxDB?

You'll only lose the dashboards which aren't provided by TeslaMate. The addon will add them back once access can be gained. The data that's used to generate them will be safe in InfluxDB.

Take a backup before you do to be safe.

@swa72
Copy link
Author

swa72 commented Aug 23, 2024

Well, losing all other dashboards is not an option and backing up inside the Grafana container is a bit complicated.
But, nonetheless, I've made some progress ;-)

The Grafana add-on reads "Note: As the addon now supports both Ingress and direct access, the default admin user has a password of hassio. Due to the implementation the password cannot be changed, however you can delete and create a new user, if so please ensure to update the grafana_ingress_user option."

Using

grafana_import_dashboards: true
grafana_folder_name: TeslaMate
grafana_host: a0d7b954-grafana
grafana_port: 3000
grafana_user: admin
grafana_pass: hassio

gets me past Grafana and into PostgresSQL.

Teslamate's log now shows ...

[...]
[08:26:18] INFO: ... RESTORED charge-details.json
[08:26:18] INFO: ... RESTORED drive-details.json
[08:26:18] INFO: Finished Importing Grafana Dashboards
[08:26:18] INFO: Creating database 'teslamate' on 29b65938-postgres
psql: error: connection to server at "29b65938-postgres" (172.30.33.8), port 5432 failed: FATAL:  password authentication failed for user "swa"
psql: error: connection to server at "29b65938-postgres" (172.30.33.8), port 5432 failed: FATAL:  password authentication failed for user "swa"
[08:26:18] ERROR: Failed to create database teslamate
[09:26:18] ERROR: TeslaMate encountered an error, halting add-on
[...]

I start the database with

user: swa
password: "123456789"
database: teslamate

and Teslamate with (excerpt)

database_user: swa
database_pass: "123456789"
database_name: teslamate
database_host: 29b65938-postgres
database_port: 5432
database_ssl: true

@swa72
Copy link
Author

swa72 commented Aug 23, 2024

I should add that PostgresSQL is complaining about "roles"?

2024-08-23 09:33:52.652 CEST [7] LOG:  database system is ready to accept connections
2024-08-23 09:35:45.200 CEST [42] FATAL:  password authentication failed for user "root"
2024-08-23 09:35:45.200 CEST [42] DETAIL:  Role "root" does not exist.
	Connection matched pg_hba.conf line 99: "host all all all md5"
2024-08-23 09:35:45.244 CEST [43] FATAL:  password authentication failed for user "swa"
2024-08-23 09:35:45.244 CEST [43] DETAIL:  Role "swa" does not exist.
	Connection matched pg_hba.conf line 99: "host all all all md5"
2024-08-23 09:35:45.287 CEST [44] FATAL:  password authentication failed for user "swa"
2024-08-23 09:35:45.287 CEST [44] DETAIL:  Role "swa" does not exist.
	Connection matched pg_hba.conf line 99: "host all all all md5"

@lildude
Copy link
Owner

lildude commented Aug 23, 2024

🤔 that would suggest something is awry with your PostgresSQL database user or the command we're running to check if the DB exists.

Are you able to run this command, replacing the variables:

$(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -Atqc "\list $DATABASE_NAME"

@swa72
Copy link
Author

swa72 commented Aug 23, 2024

Err, where would I run this command? I reckon inside the docker container? I got into it with docker exec -it $(docker ps -f name=addon_29b65938_postgres -q) bash and run a simple psql with the result of

bash-5.0# psql
psql: error: FATAL:  role "root" does not exist

Shouldn't your $(PGPASSWORD="$DATABASE_PASS" be somewhere after the command psql (if psql is the actual command) - I've never user PostgresSQL before.

@lildude
Copy link
Owner

lildude commented Aug 23, 2024

Oh sorry. Yes, it needs to be run from within the either the TeslaMate or PostgresSQL containers - they both have the psql command.

Shouldn't your $(PGPASSWORD="$DATABASE_PASS" be somewhere after the command psql (if psql is the actual command) - I've never user PostgresSQL before.

Nope. This is how you pass in the password non-interactively as the psql command will read the $PGPASSWORD env var being set just before the command runs.

It's the same as running:

$ export PGPASSWORD="$DATABASE_PASS"
$ psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -Atqc "\list $DATABASE_NAME"

I've just noticed that you appear to be using the PostgresSQL addon that used to live at https://github.com/matt-FFFFFF/hassio-addon-postgres. This is no longer maintained and has been removed. I used to reference this addon from my addons repo by removed it because it's so old and Matt didn't want to maintain it anymore.

IIRC this addon only created a single user when it started and that's the user you need to use for TeslaMate and the psql command, else you need to manually create a new user.

If you're not using the PostgresSQL addon for anything else yet, I recommend switching to https://github.com/alexbelgium/hassio-addons/tree/master/postgres

If you want to test things as they are you could try things interactively from within the PostgresSQL container:

$ psql -U "$DATABASE_USER" postgres -Atqc "\list $DATABASE_NAME"

This should return something like this:

bash-5.0# psql -U "$DATABASE_USER" postgres -Atqc "\list teslamate"
teslamate|$DATABASE_USER|UTF8|en_US.utf8|en_US.utf8|
bash-5.0#

If you still get the roles error, I think it indicates you're using the wrong username so will need to correct this or manually create a new user.

@swa72
Copy link
Author

swa72 commented Aug 23, 2024

Thanks, I followed your recommendation, removed the PostgresSQL add-on and installed https://github.com/alexbelgium/hassio-addons/tree/master/postgres instead. I fired up this add-on with the configuration

POSTGRES_PASSWORD: homeassistant

which is the default config (default user is postgres).

And voila with the updated configuration of Teslamate (see below), the add-on started just fine.

database_user: postgres
database_pass: homeassistant
database_name: teslamate
database_host: db21ed7f-postgres
database_port: 5432
database_ssl: true
grafana_import_dashboards: true
grafana_folder_name: TeslaMate
grafana_host: a0d7b954-grafana
grafana_port: 3000
grafana_user: admin
grafana_pass: hassio
disable_mqtt: true
mqtt_host: core-mosquitto
mqtt_user: ""
mqtt_pass: ""
mqtt_tls: false
mqtt_tls_accept_invalid_certs: false
mqtt_namespace: ""
timezone: Europe/London
import_dir: /share/teslamate
default_geofence: ""
encryption_key: 0b28f92c3fe07efa13755c25481c5dd375aade396d03f7d2e861901abc45e29d
env_vars: []

So far so good. I've generated tokens as well.

Can I expect to see only future data in the Grafana dashboard or also past data? Currently, I get nothing ;-) Well, not nothing but a "Templating Failed to upgrade legacy queries" warning.

@swa72
Copy link
Author

swa72 commented Aug 24, 2024

Regarding "Templating Failed to upgrade legacy queries", I noticed that I need to configure a data source. Your page /hassio/addon/6be3d3da_teslamate/documentation does not include the instructions to do so (broken screenshot)

image

@lildude
Copy link
Owner

lildude commented Aug 24, 2024

Regarding "Templating Failed to upgrade legacy queries", I noticed that I need to configure a data source. Your page /hassio/addon/6be3d3da_teslamate/documentation does not include the instructions to do so (broken screenshot)

image

Whoops. Fixed in #33

@swa72
Copy link
Author

swa72 commented Aug 24, 2024

Ok, researched further and found https://github.com/lildude/ha-addon-teslamate/blob/main/imgs/grafana-postgres.png.
You may want to change the host address (pointed to the old address) and add some more info to the process of setting up Grafana.

I got mine going now with

  • Grafana
  • Menu | Connections
  • Add new connection
  • Search for PostgresSQL
    • Name: TeslaMate
    • Host URL *: db21ed7f-postgres
    • Database name *: teslamate
    • Username *: postgres
    • Password *: homeassistant
    • TLS/SSL Mode: disabled (that's the way the server was started)

@lildude
Copy link
Owner

lildude commented Aug 30, 2024

The screenshot has all the info needed I think and I've fixed the path to that so it renders.

The latest release now includes improvements to handle situations where there are problems importing the dashboards which won't stop the addon from starting and will report more info on failure.

@swa72
Copy link
Author

swa72 commented Aug 30, 2024

Great, thanks again for your support!

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

Successfully merging a pull request may close this issue.

2 participants