audunru / adax2mqtt

MIT License
1 stars 0 forks source link

MQTT user and password .env variables? #22

Open maxbengtzen opened 1 month ago

maxbengtzen commented 1 month ago

Hi!

Thank you for your efforts with this. I've been longing for the official Adax HA integration to report energy statistics for a long time now. This will do fine, until it's officially supported.

I get a log message from the container that the access token was obtained. But the MQTT broker logs a message that it gets an unauthorized connection. I guess it has to do with me using a user and password for Mosquitto?

How do I set the env. variables for the MQTT broker in the docker compose file?

Thank you!

audunru commented 1 month ago

Thanks. This should be possible with version 0.4.0. Use MQTT_USERNAME and MQTT_PASSWORD as the env variables.

I'm still trying to figure which data is the most reliable from Adax's servers. I report both the room energy consumption and device consumption, room energy seems to match what I see in the Adax app on my phone much better.

maxbengtzen commented 1 month ago

MQTT user and password working with 0.4.0 (and 0.4.1) 🥳

Now I'm facing other issues 😅 Logs below.

Obtained access token
Published discovery message to homeassistant/sensor/adax_room_x/config
Published discovery message to homeassistant/sensor/adax_device_x/config
Published energy message {"value":0,"last_reset":"2024-10-21T03:00:00.000Z"} to homeassistant/sensor/adax_room_x/state
Error during refresh of energy data Could not get data from /rest/v1/energy_log: Request failed with status code 502

And I don't see the values reported in HA.

audunru commented 1 month ago
Published energy message {"value":0,"last_reset":"2024-10-21T03:00:00.000Z"} to homeassistant/sensor/adax_room_x/state
Error during refresh of energy data Could not get data from /rest/v1/energy_log: Request failed with status code 502

If these happened right after one another (and not with 10 minutes in between), I think maybe you have more than one "room" in the Adax API and that one of them isn't working. I published 0.4.2 with some additional logging of the room id to see if it has some funny ID like -1 or something.

maxbengtzen commented 4 days ago
Published energy message {"value":0,"last_reset":"2024-10-21T03:00:00.000Z"} to homeassistant/sensor/adax_room_x/state
Error during refresh of energy data Could not get data from /rest/v1/energy_log: Request failed with status code 502

If these happened right after one another (and not with 10 minutes in between), I think maybe you have more than one "room" in the Adax API and that one of them isn't working. I published 0.4.2 with some additional logging of the room id to see if it has some funny ID like -1 or something.

Hi again!

Timestamped logs from Portainer directly after a restart.

The first room in the list (Alf) is publishing kWh to HA successfully. I think it's the next room that doesn't work. I don't see any wierd naming patterns etc. Any suggestions?

2024-11-18T08:44:58.087370970Z Obtained access token
2024-11-18T08:44:58.482030611Z Published discovery message to homeassistant/sensor/adax_room_alf/config
2024-11-18T08:44:58.489175187Z Published discovery message to homeassistant/sensor/adax_room_allrum/config
2024-11-18T08:44:58.491786742Z Published discovery message to homeassistant/sensor/adax_room_gaestrum/config
2024-11-18T08:44:58.494286107Z Published discovery message to homeassistant/sensor/adax_room_koek/config
2024-11-18T08:44:58.497072430Z Published discovery message to homeassistant/sensor/adax_room_master_bedroom/config
2024-11-18T08:44:58.499528268Z Published discovery message to homeassistant/sensor/adax_room_vardagsrum_h/config
2024-11-18T08:44:58.503619300Z Published discovery message to homeassistant/sensor/adax_room_vardagsrum_v/config
2024-11-18T08:44:58.510946109Z Published discovery message to homeassistant/sensor/adax_room_foerrad/config
2024-11-18T08:44:58.513593269Z Published discovery message to homeassistant/sensor/adax_device_gaestrum/config
2024-11-18T08:44:58.515761448Z Published discovery message to homeassistant/sensor/adax_device_master_bedroom/config
2024-11-18T08:44:58.518494586Z Published discovery message to homeassistant/sensor/adax_device_allrum/config
2024-11-18T08:44:58.520763172Z Published discovery message to homeassistant/sensor/adax_device_alf/config
2024-11-18T08:44:58.523232250Z Published discovery message to homeassistant/sensor/adax_device_koek/config
2024-11-18T08:44:58.525523334Z Published discovery message to homeassistant/sensor/adax_device_vardagsrum_v/config
2024-11-18T08:44:58.528240969Z Published discovery message to homeassistant/sensor/adax_device_vardagsrum_h/config
2024-11-18T08:44:58.530621474Z Published discovery message to homeassistant/sensor/adax_device_foerrad/config
2024-11-18T08:44:59.317680397Z Published energy message {"value":0.317,"last_reset":"2024-11-18T03:00:00.000Z"} to homeassistant/sensor/adax_room_alf/state
2024-11-18T08:45:00.015670346Z Error during refresh of energy data Could not get data from /rest/v1/energy_log/749713: Request failed with status code 502
audunru commented 1 day ago

It looks like the first room, adax_room_alf is published successfully, then the next one fails, which causes the loop to exit.

Publishing energy messages for rooms should now continue to the next room if one fails, with v0.4.4. it should make it easier to see if this room fails consistently.