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

myair.resmed.eu #2

Closed
gkrallo opened this issue Jan 3, 2022 · 40 comments
Closed

myair.resmed.eu #2

gkrallo opened this issue Jan 3, 2022 · 40 comments

Comments

@gkrallo
Copy link

gkrallo commented Jan 3, 2022

Im new in HA but found this integration, and found out to late that it not was for eu.
I can try to test if that will be an featur in the future

@prestomation
Copy link
Owner

Hello, Thanks for opening the issue!

I'm unable to test this or gather the required information because I do not have an EU resmed device.
What I need are these pieces of information for the EU: https://github.com/prestomation/resmed_myair_sensors/blob/master/custom_components/resmed_myair/myair_client.py#L33-L59

These can be obtained by examining what the myAir web site does when logging in.
If you are handy at web development, you can examine this yourself, update those strings in your installation, restart HA and see if it works.

If you are not then here's how you can help:

  1. Login to myAir on the page that shows your stats
  2. Open the developer console.
  3. Refresh the page.
  4. Export a HAR file
  5. Send this HAR file to me or attach it here.

For step 4, here are some instructions for Chrome: https://support.google.com/admanager/answer/10358597?hl=en

I created an EU account just now and the UI looks a little different. There is some risk that EU works differently under the hood, we shall know when we get the HAR file.

Be careful to NOT enter your password when you have the network tab open. This may end up including your myAir password in the har file which we want to avoid.

@gkrallo
Copy link
Author

gkrallo commented Jan 4, 2022

myair.resmed.eu.har.zip

Hi
I tried to create the har-file, Im not so handy in coding so befor i Try you might need to have a look in the og to find out if you think it would be possible.
/KP

@prestomation
Copy link
Owner

This is great, thanks!

Unfortunately my suspicion was correct and the EU system is totally different. I think I can make this work though.

Can you take one more HAR file? Do the same thing, but load the equipment page. I think it's this one: https://myair.resmed.eu/myAccountEquipment.aspx
and then send me that har file as well.

@gkrallo
Copy link
Author

gkrallo commented Jan 4, 2022

myair_eq.zip

@gkrallo
Copy link
Author

gkrallo commented Jan 4, 2022

myAir web - Google Chrome 2022-01-04 09-06-20.zip
I took a snapshot for you to have a glance of the pages, the Har- files i taken of the pages where to change equpment.
Not visit in the short movie

@xfader2018
Copy link

Looking forward for the EU version as well. Let me know if you need info from my side as well.

@prestomation
Copy link
Owner

Thank @gkrallo , this helps!

@xfader2018 Great thank you. I'm hoping to have something up tonight(US time) for you two to test.
Just curious, are you looking to use this in HomeAssistant? Just curious as I saw your (now deleted) comment on the other repo.

@xfader2018
Copy link

@prestomation Great! Nice job. Yes I am looking to use this in HA. I deleted my comment because replied with login problem because of EU version before I saw it was already issued here.
Thanks for your work. 😀

@prestomation
Copy link
Owner

prestomation commented Jan 4, 2022

Ok great! I suspect that other repo will work in the EU if the URL and maybe some other values are changed. I am taking that scraper code for the EU support here. Looks like myAir has rebuilt their website but have only deployed it in the US. I suspect at some point EU will switch as well and we will have to change this package to treat them the same.
But at this point you might as well wait for me to add support here :)

prestomation added a commit that referenced this issue Jan 5, 2022
This change adds experimental EU support.
This is difficult for me to test as I do not have an EU-registered device, but this should work based upon information gathered from the community in the associated issue.
Please report success or failures(along with associated logs) to issue #2 in the repo
@prestomation
Copy link
Owner

prestomation commented Jan 5, 2022

@gkrallo and @xfader2018 Please try the latest version. When you add the integration you can now select NA or EU.

This is another reminder that I don't have access to an EU device, but I did as much testing as I could using the data from @gkrallo . Please let me know how it works. If there is an error, please report back all resmed-related log entries in the HA log. Collecting another HAR file of your dashboard will also help greatly as this should help me test any failures related to edge cases I did not account for.

If you're already downloaded the repo, you may need to click on it in HACS and select "Update Information" to get it to see the newest change.

@xfader2018
Copy link

xfader2018 commented Jan 5, 2022

Thank you very much!
I just tested it and it works now! They only thing is that it show my results of 31 december 2021 while on the website the results are up-to-date until today.
Also the "CPAP Last sleep date recorded" entity show wrong date/time.

So we are close! Well done.

Screen Shot 2022-01-05 at 08 24 18

@prestomation
Copy link
Owner

Nice! Ok I will look at this. Is the CPAP data you are seeing accurate for last night or is it dec31 data?

@xfader2018
Copy link

Nice! Ok I will look at this. Is the CPAP data you are seeing accurate for last night or is it dec31 data?

It's the data that also belongs to dec31 so that is correct and not mixed up. It's just not up-to-date. 😉

@prestomation
Copy link
Owner

Sorry about that. I've pushed another change. You'll need to 'Update Information' again and upgrade.

@gkrallo
Copy link
Author

gkrallo commented Jan 5, 2022 via email

@gkrallo
Copy link
Author

gkrallo commented Jan 5, 2022

4january.zip
new try with pictures attached

@prestomation
Copy link
Owner

prestomation commented Jan 5, 2022

Oh I see. It's returning hours where US is returning minutes. This was impossible to tell looking at the raw data.

I've pushed a fix for this

@xfader2018
Copy link

xfader2018 commented Jan 5, 2022

Unfortunately this didn't fix it but made it worse 😉

Screen Shot 2022-01-05 at 22 33 44

Can you also remove the time behind Last recorded date as well since it's always 00:00:00 ?

@prestomation
Copy link
Owner

Oh whoops 😳

I've pushed another change for the time.

for the last date recorded, the integration reports the day as a date, which I think is a better representation than just a string as then you can pass it to automations that expect a date. It is home assistant that decides to show the entire thing. For showing on a dashboard or something it might be best to use your own template to parse out the date in the format that works best for you but I will look more to see if there is a better way to handle dates in HA

@xfader2018
Copy link

Love your swift reply and fixes.

It's now working and showing the right minutes. I need to convert it to hours to have exact result.
Screen Shot 2022-01-05 at 22 48 06

@prestomation
Copy link
Owner

yay! I'm glad others are finding value out of my new year side project!

@Ferre0407
Copy link

This morning the integration worked very well and i wanted to update to the latest version. After the update all entities were gone...
image

@xfader2018
Copy link

xfader2018 commented Jan 5, 2022

Having same problem now after some reboots. Entities became unavailable. Friend of mine has same issue and error.

this is in log:

Logger: homeassistant.components.sensor
Source: helpers/update_coordinator.py:161 
Integration: Sensor (documentation, issues) 
First occurred: 24:02:09 (1 occurrences) 
Last logged: 24:02:09

Error while setting up resmed_myair platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 187, in _async_refresh
    self.data = await self._async_update_data()
  File "/config/custom_components/resmed_myair/coordinator.py", line 39, in _async_update_data
    self.sleep_records = await self.myair_client.get_sleep_records()
  File "/config/custom_components/resmed_myair/client/legacy_client.py", line 115, in get_sleep_records
    return generate_sleep_records(my_scores)
  File "/config/custom_components/resmed_myair/client/legacy_client.py", line 38, in generate_sleep_records
    record["totalUsage"] = float(score.get("Usage", 0)) * 60
ValueError: could not convert string to float: ''

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/resmed_myair/sensor.py", line 116, in async_setup_entry
    await coordinator.async_config_entry_first_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 161, in async_config_entry_first_refresh
    raise ex
homeassistant.exceptions.ConfigEntryNotReady: could not convert string to float: ''

@joverdijk
Copy link

I'm the friend xfade mentioned.
This is with the version of tonight, EU account, on first time install, i get log above and empty integration with no device/entities.
The version from earlier today did work, side from minutes/hours used, which displayed a very long line with numbers.

@prestomation
Copy link
Owner

Sorry folks, this is difficult because I don't have access to an EU device.

I'm assuming xfader2018 uses his CPAP every day, but you two do not :) Some days had no usage data which is reported as "" instead of 0. I've pushed a fix, so please update through HACS again

@joverdijk
Copy link

Hi, no worries at all, I'm glad there is some movement and stuff is happening ;)
About the 0, at this moment it is past 00h and then the website jumps to next day and will display all zero's for the whole night until it receives an update poll with the stats. I guess it's returning that.
However, the empty integration was also happening before 00h00 and the website did show numbers at that time.
I updated and i immediately got an device & entities and they all show 0 now, which is correct, because the device has not synced any usage today yet. Thanks for building support for this. When needed I can reset my password and you can fiddle around with my account (actually my GF's account ;)

@prestomation
Copy link
Owner

I see. Do folks here have feedback on how they would like the integration to work on days the CPAP has no data? It is kind of a deceptively hard problem because of how CPAP data works and how HA works. Do we want it to continue to report the last complete day? If we do this, then when you miss a CPAP day the sensors will still report the last complete day, but the Date sensor will tell you it is behind. Does that make sense? How would people like it to work?

@joverdijk
Copy link

When I check on EU website on calender view, on a day when device was not used, all values are displayed 0 and it says 'your device has not been used this night', in local language. I think it's best to put 0's in HA on days it has no data, this kind of reflects the behaviour of the myAir website. Also it puts in date/timestamps in influxdb behind HA, so I do get values (even if they are 0) in grafana graphs based on that data.

@prestomation
Copy link
Owner

got it. so this is what is already happening then right? although I suspect the date sensor is updating to today when it should still list yesterday

@gkrallo
Copy link
Author

gkrallo commented Jan 7, 2022

myair.resmed.eu_7 january.har.zip
Hi
one show 48 minutes the other 45 ?
I attached some files that might give som ideas?

@xfader2018
Copy link

xfader2018 commented Jan 7, 2022

myair.resmed.eu_7 january.har.zip
Hi
one show 48 minutes the other 45 ?
I attached some files that might give som ideas?

I guess on the website it's round off in hours, so 48 minutes is approx 0.45 hour ?

Anyway, I created a value template in HA to convert the exact minutes to HH:MM
Also created template for the last date recorded to date format of my region.

Screen Shot 2022-01-07 at 13 07 12

sensor:
  - platform: template
    sensors:
      cpap_usage:
        friendly_name: 'CPAP Usage in Time'
        value_template: >
          {% set ct = states('sensor.cpap_usage_minutes') | int %}
          {% if ct > 60 %}{{ ct // 60 }}:{{ '{:0>2d}'.format(ct%60) }}{% endif %}
          
  - platform: template
    sensors:
      cpap_last_usage:
        friendly_name: 'CPAP Last Sleep Date Recorded'
        value_template: >
          {{ as_timestamp(strptime(states('sensor.cpap_last_sleep_date_recorded'), '%Y-%m-%dT%H:%M:%S')) | timestamp_custom('%d-%m-%Y') }}

@gkrallo
Copy link
Author

gkrallo commented Jan 7, 2022

I think something is missing, if it is under 60?
I just tested this, but it gives 48 and I gues some other expression is mor properiat but I dint understand the syntax and commands. (tested it in the develpoer tool)
{% if ct > 60 %}
{{ ct // 60 }}:{{ '{:0>2d}'.format(ct%60) }}
{% else %}
{{ '{:0>2d}'.format(ct%60) }}
{% endif %}

( and yes I might need to glue the mask to the face so I use it mor than 60 minutes.... )

@prestomation
Copy link
Owner

What do you all think about this?:

image

CPAP Usage Time is a new sensor that is of the format HH:MM:SS so not everyone has to make their own template sensor. This is the same conversion you are all doing above from the usageMinutes sensor.

CPAP Sleep Data Last Collected is new, and is the point in time that your CPAP last reported new data. This will update once per day, I'm assuming only on days that you have used your CPAP. Not sure how useful this will be, but it gives you an idea of when your cpap usually communicates

CPAP Most Recent Sleep Date is new. This is the last day for which data exists. This will also update once a day if you use your CPAP every day. But if you stop using your CPAP this sensor will stop updating. This can be used to write automations to remind you to use your cpap if you didn't use it the day before or something like that

CPAP Current Data Date is what we used to call Last Sleep Date Recorded. This is the date to which the other current sensors applies. So this will always update every day, even when you have used your cpap. This changing can be used to know when the next days data is being read .This will be more accurate then watching the data sensors change, because it is technically possible for any of those to stay the same day after day

Does this make sense? Feel free to suggest better names too!

@gkrallo
Copy link
Author

gkrallo commented Jan 8, 2022 via email

@prestomation
Copy link
Owner

Regarding "one show 48 minutes the other 45 ?" Yes ResMed is returning 0.8 hours(which is 48 minutes) but it appears they do some rounding to show on the UI

Yes makes sense, we don't have the precision of seconds anyway so will adjust

@prestomation
Copy link
Owner

I've pushed this change. Please let me know if you have issues

@prestomation
Copy link
Owner

I'm taking no news as good news, but please don't hesitate to reopen or open a new issue if anyone on the thread has any issues. Thanks!

@dannya
Copy link

dannya commented Mar 20, 2022

@prestomation I believe the EU site code has been changed within the last week (I've noticed subtle visual differences on the mobile site login too), and my data is no longer pulling into HA:

image

I have attached a HAR file as explained above:
myair.resmed.eu.zip

Please let me know if there is any other information that I can provide to help resolve this issue.

Many thanks,
Danny

@xfader2018
Copy link

@prestomation I believe the EU site code has been changed within the last week (I've noticed subtle visual differences on the mobile site login too), and my data is no longer pulling into HA:

image

I have attached a HAR file as explained above: myair.resmed.eu.zip

Please let me know if there is any other information that I can provide to help resolve this issue.

Many thanks, Danny

This is due to the fact that Resmed enabled 2FA in more and more countries.
There is already a issue opened for this: #16
Hopefully Prestomation is able to make a solution for it in future.

See issue for possible workaround.

@dannya
Copy link

dannya commented Mar 20, 2022

@xfader2018 thanks for your comment.

If the workaround is to create a new account in a non-2fa country, I'll not do this and hope for a proper fix - I'd prefer not to lose my account history, and surely ResMed will be imminently rolling out 2fa to the rest of the countries anyway!

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

No branches or pull requests

6 participants