diff --git a/config-sample.json b/config-sample.json index f3f671c2d229bb29cbaea363697569b35d867b31..7da2d29ec4b005ee51f94fbc5717d03fc8902517 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 17ddf9ae05efc30348329fe55af767ff78cb464c..2aac165e4ae55656427e6dc3176436267d78ac59 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 );