Skip to content
Snippets Groups Projects
Verified Commit 51a76baa authored by Erick Hitter's avatar Erick Hitter
Browse files

More customization

parent 3a3c1e8e
Branches master
No related tags found
No related merge requests found
......@@ -9,16 +9,17 @@
"mac": "",
"label": "",
"status": {
"entity": "",
"entity_id": ""
},
"on": {
"entity": "",
"entity_id": ""
"entity_id": "",
"entity_action": ""
},
"off": {
"entity": "",
"entity_id": ""
"entity_id": "",
"entity_action": ""
}
}
}
......
......@@ -40,7 +40,7 @@ function buttonActivated( mac ) {
'x-ha-access': config.home_assistant_pass
}
};
console.log( req );
// First, check the current status so we can toggle
request( req, function( err, res, body ) {
// Handle error states
......@@ -57,14 +57,14 @@ console.log( req );
// HA only deals with JSON
body = JSON.parse( body );
var service = null,
postBody = {};
var service = 'services/',
postBody = {};
if ( 'off' === body.state ) {
service = buttonConfig.on.entity + '/turn_on';
service += buttonConfig.on.entity + '/' + buttonConfig.on.entity_action;
postBody.entity_id = buttonConfig.on.entity_id;
} else if ( 'on' === body.state ) {
service = buttonConfig.off.entity + '/turn_off';
service += buttonConfig.off.entity + '/' + buttonConfig.off.entity_action;
postBody.entity_id = buttonConfig.off.entity_id;
} else {
console.error( 'Unknown state: ' + body.state );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment