04-07-2016, 09:47 PM
ResMed MyAir Email Notification with PhantomJS
As we all know, MyAir does not provide comprehensive sleep results by giving only the snapshot of previous day events.
Nonetheless, it’s a basic guide to take action if necessary.
To my amazement, MyAir does not have email notification functionality for the results. Also, 2 weeks of history is only made available. - Not sure if ResMed had the “end user” in mind with their portal design.
So, I created an automated PhantomJS script to login, open score details, take a screenshot and download the data. In addition, bash scripts to email last night’s results. – Some say (wife) I’m lazy. “True!”
PhantomJS is a headless WebKit (browser) scriptable with a JavaScript API. It has fast and native support for various web standards.
Download from here: h**p://phantomjs.org/download.html
Script is based on “login Amazon using PhantomJS” by Amir Duran.
Installation:
Option 1 – No email support – Windows and Linux environment
1. Install PhantomJS and check if its working by using the examples in the folder
2. Download the script resmedloginv2.js from here: h**ps://www.dropbox.com/s/s3bz0m0egd2t2a0/resmedloginv2.js?dl=0
3. Update email address and password for your ResMed MyAir login on line 60 and 61
4. If required, update download file location directory on line 89 and 102 – a must for Windows users
5. Run with: phantomjs --ignore-ssl-errors=true --ssl-protocol=any resmedloginv2.js
6. That’s it, open the downloaded files resmedmyair.html and resmedmyair.png
Option 2 – Email support – Linux environment only
1. Install PhantomJS and check if its working by using the examples in the folder
2. Ensure you have the necessary commands installed with which: i.e.: which sed \ which grep \ which mutt
3. Create directory /opt/resmed/
4. Change to newly created directory and download the archive: h**ps://www.dropbox.com/s/sjwchz74lrq42ao/resmed.zip?dl=0
5. Unzip the archive
6. Script resmedloginv2.js - update email address and password for your ResMed MyAir login on line 60 and 61
7. Script resmed.sh – update to your email address and someone else on line 16 and 17 – don’t use the same for both. mutt might not work.
8. Run with: /opt/resmed/./resmed.sh
9. Expect the email to arrive shortly
Backup of the html (data) and png file can be found in: /opt/resmed/resmedmyair-DATESTAMP
Script resmed.sh is designed to output the email result to the database file: /tmp/resmedmyairdb.txt and check each time if email has already been send. After all, we don’t won’t to lock the account by interrogating the ResMed server.
The lazy step – cron it!
I have cron run resmed.sh every 15mins between 7am and 2pm.
# cat /etc/crontab
# ResMed MyAir Login
*/15 7-14 * * * root /opt/resmed/./resmed.sh >/dev/null 2>&1
For Windows users that would like email notification, I guess it’s possible by tweaking scripts resmedscores.sh and resmed.sh into batch files. You need to install commands like; sed, grep for Windows to strip the results from the html (data) file. Having said that, I have found sed does behave differently across versions so be prepared for sleepless nights . As for sending the email, consider vbs that utilises SMTP.
Hope someone finds the post useful and of some benefit.
Cheers and happy sleeping.
Ps: If post does not meet the forum guidelines or posted incorrectly, do remove or move accordantly.
Nonetheless, it’s a basic guide to take action if necessary.
To my amazement, MyAir does not have email notification functionality for the results. Also, 2 weeks of history is only made available. - Not sure if ResMed had the “end user” in mind with their portal design.
So, I created an automated PhantomJS script to login, open score details, take a screenshot and download the data. In addition, bash scripts to email last night’s results. – Some say (wife) I’m lazy. “True!”
PhantomJS is a headless WebKit (browser) scriptable with a JavaScript API. It has fast and native support for various web standards.
Download from here: h**p://phantomjs.org/download.html
Script is based on “login Amazon using PhantomJS” by Amir Duran.
Installation:
Option 1 – No email support – Windows and Linux environment
1. Install PhantomJS and check if its working by using the examples in the folder
2. Download the script resmedloginv2.js from here: h**ps://www.dropbox.com/s/s3bz0m0egd2t2a0/resmedloginv2.js?dl=0
3. Update email address and password for your ResMed MyAir login on line 60 and 61
4. If required, update download file location directory on line 89 and 102 – a must for Windows users
5. Run with: phantomjs --ignore-ssl-errors=true --ssl-protocol=any resmedloginv2.js
6. That’s it, open the downloaded files resmedmyair.html and resmedmyair.png
Option 2 – Email support – Linux environment only
1. Install PhantomJS and check if its working by using the examples in the folder
2. Ensure you have the necessary commands installed with which: i.e.: which sed \ which grep \ which mutt
3. Create directory /opt/resmed/
4. Change to newly created directory and download the archive: h**ps://www.dropbox.com/s/sjwchz74lrq42ao/resmed.zip?dl=0
5. Unzip the archive
6. Script resmedloginv2.js - update email address and password for your ResMed MyAir login on line 60 and 61
7. Script resmed.sh – update to your email address and someone else on line 16 and 17 – don’t use the same for both. mutt might not work.
8. Run with: /opt/resmed/./resmed.sh
9. Expect the email to arrive shortly
Backup of the html (data) and png file can be found in: /opt/resmed/resmedmyair-DATESTAMP
Script resmed.sh is designed to output the email result to the database file: /tmp/resmedmyairdb.txt and check each time if email has already been send. After all, we don’t won’t to lock the account by interrogating the ResMed server.
The lazy step – cron it!
I have cron run resmed.sh every 15mins between 7am and 2pm.
# cat /etc/crontab
# ResMed MyAir Login
*/15 7-14 * * * root /opt/resmed/./resmed.sh >/dev/null 2>&1
For Windows users that would like email notification, I guess it’s possible by tweaking scripts resmedscores.sh and resmed.sh into batch files. You need to install commands like; sed, grep for Windows to strip the results from the html (data) file. Having said that, I have found sed does behave differently across versions so be prepared for sleepless nights . As for sending the email, consider vbs that utilises SMTP.
Hope someone finds the post useful and of some benefit.
Cheers and happy sleeping.
Ps: If post does not meet the forum guidelines or posted incorrectly, do remove or move accordantly.