From 51a76baaf9cc21c3c624a488c16fa34e3a7de609 Mon Sep 17 00:00:00 2001 From: Erick Hitter <services@ethitter.com> Date: Sat, 10 Sep 2016 19:23:05 -0700 Subject: [PATCH] More customization --- config-sample.json | 7 ++++--- index.js | 10 +++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config-sample.json b/config-sample.json index f3f671c..7da2d29 100644 --- a/config-sample.json +++ b/config-sample.json @@ -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": "" } } } diff --git a/index.js b/index.js index 17ddf9a..2aac165 100644 --- a/index.js +++ b/index.js @@ -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 ); -- GitLab