Skip to content

Instantly share code, notes, and snippets.

@drewB
Last active March 18, 2018 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewB/38c61541a0575a88c32753409d648d1a to your computer and use it in GitHub Desktop.
Save drewB/38c61541a0575a88c32753409d648d1a to your computer and use it in GitHub Desktop.
phantomjs script for arming Alarm.com panel
var page;
page = require('webpage').create();
page.viewportSize = { width: 320, height: 780 };
phantom.waitFor = function(callback) {
do {
// Clear the event queue while waiting.
// This can be accomplished using page.sendEvent()
this.page.sendEvent('mousemove');
} while (!callback());
}
phantom.waitForSomeTime = function() {
//super hacky way to "sleep" while waiting for page to load
count = 0
do {
// Clear the event queue while waiting.
// This can be accomplished using page.sendEvent()
this.page.sendEvent('mousemove');
count += 1
} while (count < 10000);
}
console.log('opening page...');
page.open('https://www.alarm.com/login.aspx', function(status) {
if (status === 'success') {
console.log('page open...');
page.evaluate(function() {
var config;
config = {
username: 'username',
password: 'password'
};
document.querySelector('input[name="ctl00$ContentPlaceHolder1$loginform$txtUserName"]').value = config.username;
document.querySelector('input[name="txtPassword"]').value = config.password;
document.querySelector('input[name="ctl00$ContentPlaceHolder1$loginform$signInButton"]').click();
});
console.log('filled form and clicked login');
phantom.waitFor(function() {
return page.evaluate(function() {
return document.querySelectorAll('.disarmed.icon-circle').length > 0;
})
})
console.log("Signed in and ready to change arm state");
phantom.waitForSomeTime(); // for some reason just waiting '.disarmed.icon-circle' doesn't seem to wait long enough
page.evaluate(function() {document.querySelector('.disarmed.icon-circle').click()});
console.log("Clicked Panel");
phantom.waitForSomeTime(); // for some reason waiting for the checkboxes doesn't wait long enough
page.evaluate(function() {document.querySelectorAll('.disarmed [role="checkbox"]')[1].click()}); //Silent Arming
page.evaluate(function() {document.querySelector('.disarmed .armed-stay').click()}); //Arm Stay
console.log("Arming....");
phantom.waitFor(function() {
return page.evaluate(function() {
return document.querySelector('.card-info.armed-stay h4 span').textContent == "Armed Stay";
})
})
console.log("Alarm is now armed for stay.")
phantom.exit();
} else {
console.log('Error loading page.');
phantom.exit();
}
});
@drewB
Copy link
Author

drewB commented Nov 5, 2017

Alarm.com's website was updated 10/30/2017 (give or take a day) to use ember and no jquery. I had difficulty updating the script to work with the new website so switched to their m.alarm.com site. Hopefully that will stay around for a while.

@drewB
Copy link
Author

drewB commented Mar 1, 2018

Alarm.com started redirecting the m.alarm.com site to the normal one. I was able to get the script working with the new desktop site thanks to super hacky method I wrote to "sleep" (phantom.waitForSomeTime).

@adamomg
Copy link

adamomg commented Mar 5, 2018

home-assistant/core#12694

I know its probably apples to oranges, but would you mind take a look at this? The Home Assistant component is based on pyalarmdotcom.

https://github.com/Xorso/pyalarmdotcom

@drewB
Copy link
Author

drewB commented Mar 18, 2018

Alarm.com just changed their site again and phantomjs doesn't work because of unsupported ES6 promises. I rewrote this in chrome-headless https://gist.github.com/drewB/7330b172d00364e067a91a95cf927695

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment