tomasmcguinness / homeassistant-mixergy

Add support for Mixergy's smart water tank into Home Assistant
MIT License
31 stars 8 forks source link

Unable to load any Entities #3

Closed emsworth22 closed 1 year ago

emsworth22 commented 1 year ago

I have been able to install and login but after multiple attempts it is not showing any entities

image

Home Assistant 2022.10.1 Supervisor 2022.09.1 Operating System 9.0 Frontend 20221006.0 - latest

tomasmcguinness commented 1 year ago

Hi. Do you see any errors in the HomeAssistant logs?

emsworth22 commented 1 year ago

Error while setting up mixergy platform for sensor 22:01:28 – (ERROR) Sensor - message first occurred at 22:00:04 and shows up 5 times Unexpected error fetching sensor data: 'heat_source' 22:01:28 – (ERROR) Mixergy (custom integration) - message first occurred at 22:00:04 and shows up 5 times

2022-10-06 22:00:04.251 ERROR (MainThread) [custom_components.mixergy.sensor] Unexpected error fetching sensor data: 'heat_source' File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement 2022-10-06 22:00:04.296 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mixergy platform for sensor File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement File "/config/custom_components/mixergy/sensor.py", line 29, in async_setup_entry 2022-10-06 22:01:08.875 ERROR (MainThread) [custom_components.mixergy.sensor] Unexpected error fetching sensor data: 'heat_source' File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement 2022-10-06 22:01:08.880 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mixergy platform for sensor File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement File "/config/custom_components/mixergy/sensor.py", line 29, in async_setup_entry 2022-10-06 22:01:15.998 ERROR (MainThread) [custom_components.mixergy.sensor] Unexpected error fetching sensor data: 'heat_source' File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement 2022-10-06 22:01:16.007 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mixergy platform for sensor File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement File "/config/custom_components/mixergy/sensor.py", line 29, in async_setup_entry 2022-10-06 22:01:23.963 ERROR (MainThread) [custom_components.mixergy.sensor] Unexpected error fetching sensor data: 'heat_source' File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement 2022-10-06 22:01:23.969 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mixergy platform for sensor File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement File "/config/custom_components/mixergy/sensor.py", line 29, in async_setup_entry 2022-10-06 22:01:28.442 ERROR (MainThread) [custom_components.mixergy.sensor] Unexpected error fetching sensor data: 'heat_source' File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement 2022-10-06 22:01:28.449 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mixergy platform for sensor File "/config/custom_components/mixergy/sensor.py", line 24, in async_update_data File "/config/custom_components/mixergy/tank.py", line 233, in fetch_data File "/config/custom_components/mixergy/tank.py", line 214, in fetch_last_measurement File "/config/custom_components/mixergy/sensor.py", line 29, in async_setup_entry

On 6 Oct 2022, at 22:28, Tomas McGuinness @.**@.>> wrote:

Hi. Do you see any errors in the HomeAssistant logs?

— Reply to this email directly, view it on GitHubhttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftomasmcguinness%2Fhomeassistant-mixergy%2Fissues%2F3%23issuecomment-1270717916&data=05%7C01%7C%7C3c655c1f2add4f90bec108daa7e1c17a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638006885307817505%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=lU2X0DGttV8ZuHM5zRWaXBqs0Fj9%2BWMPIHD0o8Oc5M4%3D&reserved=0, or unsubscribehttps://nam12.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FA3OZ2UGJ7TVPISGJGGLYT3DWB5AA7ANCNFSM6AAAAAAQ7AGJU4&data=05%7C01%7C%7C3c655c1f2add4f90bec108daa7e1c17a%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638006885307817505%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=TmzhzIlb%2F4jhYeHaTrth4MUMVhyYV%2FO%2FnH1K3wTQNvU%3D&reserved=0. You are receiving this because you authored the thread.Message ID: @.***>

tomasmcguinness commented 1 year ago

Ah, it looks like they have changed their API again, without bumping the version :( They have done this before.

I'll have a look as soon as I can. This will take some investigation and a new version.

DirkFace commented 1 year ago

Mine is working fine tomas. Maybe it's not the API?

tomasmcguinness commented 1 year ago

I've just checked the API calls coming back for my tank and heat_source is where it is supposed to be.

image

@emsworth22 Is your tank very new? Would you be able to test the API yourself using something like PostMan?

emsworth22 commented 1 year ago

It's actually very old, 3 years old (number 515). I just removed the Mixergy Integration from Home Assistant , and the repository from HACS. I re-installed it all, (restarting each time) logged back in OK to Mixergy, restarted again and it does no present any devices, services or entities. Now I am very new to homes assistant so if's I've missed a step I apologise in advance. Here are the latest errors from the logs and the screen shot of where I am up to ;

2022-10-07 09:11:02.645 ERROR (MainThread) [custom_components.mixergy.sensor] Unexpected error fetching sensor data: 'heat_source' 2022-10-07 09:11:02.682 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mixergy platform for sensor

image

image

tomasmcguinness commented 1 year ago

Cool. I’ve had mine about 18 months now.

The code does lots before it gets to “heat_source”, such as loading the top and bottom temperatures.

This means the response has most of what it needs.

Do you have a heat_pump warming the water?

Do you use Windows or MacOS?

emsworth22 commented 1 year ago

My Mixergy does not have a Heat Pump connected to it (that's on a different cylinder!). My 250L Mixergy cylinder has the dual immersion at the top, 1 connected to Mixergy controller, 1 connected to Eddi. I am using MacOS but Home Assistant is running on a dedicated raspberry pi; you can see my Mixergy tank here;

https://youtu.be/XJdqbU9obG4

tomasmcguinness commented 1 year ago

All I can suggest at this juncture is that I write a small script which you could run on your MacOS, which would do something similar to my HA Integration.

It might help us narrow down why the API call isn’t working.

It will take me a few days to put it together.

Up for that?

emsworth22 commented 1 year ago

Yeah thats sounds good - thanks for your help!

tomasmcguinness commented 1 year ago

I haven't forgotten, I'm just struggling to find the time!

kerbysj commented 1 year ago

Following this as im not getting anything back on mine either

tomasmcguinness commented 1 year ago

Right! Sorry for the delay. I've written this python script very quickly. Save the following code into a file called mixergy.py

import sys
import requests

username = sys.argv[1]
password = sys.argv[2]

# Get login URL

result = requests.get("https://www.mixergy.io/api/v2")

root_result = result.json()

account_url = root_result["_links"]["account"]["href"]

result = requests.get(account_url)

account_result = result.json()

login_url = account_result["_links"]["login"]["href"]

result = requests.post(login_url, json = {'username': username, 'password': password})

if result.status_code != 201:
    print("Authentication failure. Check your credentials and try again!")
    exit()

print("Authentication successful!")

login_result = result.json()

login_token = login_result["token"]

headers = {'Authorization': f'Bearer {login_token}'}

result = requests.get("https://www.mixergy.io/api/v2", headers=headers)

root_result = result.json()

tanks_url = root_result["_links"]["tanks"]["href"]

result = requests.get(tanks_url, headers=headers)

tanks_result = result.json()

tanks = tanks_result['_embedded']['tankList']

for i, subjobj in enumerate(tanks):
    print("** Found a tank with serial number", subjobj['serialNumber'])

To run it you'll need Python installed.

You'll also need to ensure the Requests module is installed.

pip install requests

To run it, just call it with your Mixergy username and password. These values are only used within the script, as you can see above.

python3 mixergy.py <username> <password>

so it might look like this:

python3 mixergy.py me@myemail.com abc123

When you run it, you should see an output like this:

Authentication successful!
** Found a tank with serial number MX00XXXX

Let's start with this script. Once you manage to get it working, I'll expand what it fetches until we can see what's happening.

emsworth22 commented 1 year ago

After about 24 hours mine started randomly appearing. I had rebooted multiple time and I wish I could say "thats what fixed it"

tomasmcguinness commented 1 year ago

That's strange. Maybe their API takes time to fill up with the correct data?

tomasmcguinness commented 1 year ago

@kerbysj If you're still experiencing the issues, would you be able to run that script above?

kerbysj commented 1 year ago

Im running HAOS and either im stupid/lack of coffee I cant seem to install python

tomasmcguinness commented 1 year ago

You can run the script on your computer or laptop. Are you a Windows or MacOS user?

kerbysj commented 1 year ago

Windows. Ive installed python with pip...

zarch1972 commented 1 year ago

To add my two-penneth.

When I reboot HA or just reload the integration, I get 'some' of the values back from the tank, but not all.

today at 13:05 File "/config/custom_components/mixergy/tank.py", line 269, in electic_heat_source
today at 13:05 return self._electric_heat_source
today at 13:05 AttributeError: 'Tank' object has no attribute '_electric_heat_source'
today at 13:05 2022-10-27 13:05:10.397 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up mixergy platform for sensor

image

But after that initial pull, nothing refreshes.

I'm wondering if the issue for me might be more to do with HA 2022.10.5 than the integration, as things were working before I updated this morning (from 2022.08 from memory).

zarch1972 commented 1 year ago

Just a quick update, I upgraded to Home Assistant 2022.11.2 this morning and the problem still persists.

It gets the 'current charge' and a few other readings on boot of HA, but then doesn't update again.

tomasmcguinness commented 1 year ago

I reckon the crash in the component around the missing _electric_heat_source property prevents the update code from kicking in. Would you be willing to run the python script? I just wonder if they haven't changed the API for different tank versions.

tomasmcguinness commented 1 year ago

I've added a testing folder with an updated mixergy.py script in there.

Run it first with your username and password

python3 mixergy.py <username> <password>

and you should get this result

Authentication successful! ** Found a tank with serial number MX00XXXX

Copy the serial number and run the script again, adding the serial number as an argument

python3 mixergy.py <username> <password> <serial_number>

You should then get a detailed breakdown of the tank's information

Using Serial Number MX00XXXX Authentication successful! Found tanks serial number MX00XXXX Tank Url: https://www.mixergy.io/api/v2/tanks/xxxx Firmware: 5.4.0 Fetching details... Measurement Url: https://www.mixergy.io/api/v2/tanks/xxxx/measurements/latest Control Url: https://www.mixergy.io/api/v2/tanks/xxxx/control Model: MX-210-IDE-EXT-475-2-1-B-0-0 Top Temp: 20.9 Bottom Temp: 16.0 Charge: 0.4 Heat Source: Indirect Heat Source On: False

Testing the script this morning, I noticed that holiday mode causes some problems. I'll need to amend the integration to report back on that. The heat_source property changes to source with a value of vacation.

If you get an errors, paste the output (taking care to remove GUIDs and Serial Numbers!). I can then add raw JSON dumps to the script.

As before, the script does everything locally and your username and password don't get saved anywhere and are used only to access the Mixergy API.

tomasmcguinness commented 1 year ago

Thanks to @zarch1972 I've found the problem -

Screenshot 2022-11-12 at 07 39 01

My code assume either Indirect or Electric heat sources. If it's HeatPump, it's not setting up the Tank object correctly, which is why it's missing the _electric_heat_source property!

I'll have to have a think about this as it will require some changes and a new entity for heat pump as a heat source.

Thanks everyone for your help. I'll get these changes made as soon as I can!

tomasmcguinness commented 1 year ago

I've pushed some change this morning which should bring heat pump support!

A new sensor should appear in HomeAssistant - mixergy_xxxxx_heatpump_heat, which will indicate when the heat source is a heat pump.

This will appear as an update to version 0.0.6 within HACS

Screenshot 2022-11-20 at 07 57 48
zarch1972 commented 1 year ago

Hey Tom, thanks for your hard work resolving the error. I upgraded usings HACS and the sensors appear to be working again now, thank you.

I can't seem to see the new sensor mixergy_xxxxx_heatpump_heat though?

tomasmcguinness commented 1 year ago

Forgot to register it! 0.0.7 includes a fix that should resolve this!

tomasmcguinness commented 1 year ago

I'm going to close this ticket as I'm happy the heat pump change fixes the underlying problem!