diff --git a/README.md b/README.md index d766302..ce8b818 100755 --- a/README.md +++ b/README.md @@ -196,6 +196,10 @@ Activates or deactivates a circuit. See [`SLSetCircuitStateMessage`](#slsetcircu Sets the heating setpoint for any body. See [`SLSetHeatSetPointMessage`](#slsetheatsetpointmessage) documentation for argument values. Emits the `setPointChanged` event when response is acknowledged. +### setHeatMode(controllerId, bodyType, heatMode) + +Sets the preferred heat mode. See [`SLSetHeatModeMessage`](#slsetheatmodemessage) documentation for argument values. Emits the `heatModeChanged` event when response is acknowledged. + ### sendLightCommand(controllerId, command) Sends a lighting command. See [`SLLightControlMessage`](#sllightcontrolmessage) documentation for argument values. Emits the `sentLightCommand` event when response is acknowledged. @@ -380,6 +384,17 @@ Passed as an argument to the emitted `setPointChanged` event. The passed version * `bodyType` - integer indicating the type of body to set the setpoint of. The pool is body `0` and the spa is body `1`. * `temperature` - integer indicating the desired setpoint. This is presumably in whatever units your system is set to (celsius or fahrenheit). +## SLSetHeatModeMessage + +Passed as an argument to the emitted `setHeatMode` event. The passed version is empty, however, since the response is just an acknowledgement of receipt of the set command. + +### Properties + +* `controllerId` - integer indicating the ID of the controller to send this command to. + * Note that while `SLControllerConfigMessage` includes a controllerId, this ID, in my experience, should always be 0. +* `bodyType` - integer indicating the type of body to set the setpoint of. The pool is body `0` and the spa is body `1`. +* `heatMode` - integer indicating the desired heater mode. Valid values are: 0: "Off", 1: "Solar", 2 : "Solar Preferred", 3 : "Heat Pump", 4: "Don't Change" + ## SLLightControlMessage Passed as an argument to the emitted `sentLightCommand` event. The passed version is empty, however, since the response is just an acknowledgement of receipt of the light command. diff --git a/heatmodetest.js b/heatmodetest.js new file mode 100755 index 0000000..0a1a485 --- /dev/null +++ b/heatmodetest.js @@ -0,0 +1,49 @@ +'use strict'; + +const ScreenLogic = require('./index'); + +// use this to find and connect to units local to the network this is running on +var finder = new ScreenLogic.FindUnits(); +finder.on('serverFound', function(server) { + finder.close(); + connect(new ScreenLogic.UnitConnection(server)); +}); + +finder.search(); + +// use this if you want to use a direct connection to a known unit +// connect(new ScreenLogic.UnitConnection(80, '10.0.0.85')); + +// use this to remote connect to a system by name (going through the Pentair servers) +// const systemName = 'Pentair: xx-xx-xx'; +// const password = '1234'; + +// var remote = new ScreenLogic.RemoteLogin(systemName); +// remote.on('gatewayFound', function(unit) { +// remote.close(); +// if (unit && unit.gatewayFound) { +// console.log('unit ' + remote.systemName + ' found at ' + unit.ipAddr + ':' + unit.port); +// connect(new ScreenLogic.UnitConnection(unit.port, unit.ipAddr, password)); +// } else { +// console.log('no unit found by that name'); +// } +// }); + +// remote.connect(); + +// generic connection method used by all above examples +function connect(client) { + client.on('loggedIn', function() { + this.getVersion(); + }).on('version', function(version) { + this.setHeatMode(0, 0, 3); + console.log(' version=' + version.version); + }).on('heatModeChanged', function() { + client.close(); + }).on('loginFailed', function() { + console.log(' unable to login (wrong password?)'); + client.close(); + }); + + client.connect(); +} diff --git a/index.js b/index.js index 5218760..4c4fbc5 100644 --- a/index.js +++ b/index.js @@ -210,6 +210,10 @@ class UnitConnection extends EventEmitter { this.client.write(new messages.SLSetHeatSetPointMessage(controllerId, bodyType, temperature).toBuffer()); } + setHeatMode(controllerId, bodyType, heatMode) { + this.client.write(new messages.SLSetHeatModeMessage(controllerId, bodyType, heatMode).toBuffer()); + } + sendLightCommand(controllerId, command) { this.client.write(new messages.SLLightControlMessage(controllerId, command).toBuffer()); } @@ -259,6 +263,10 @@ class UnitConnection extends EventEmitter { // console.log(" it's a setpoint ack"); this.emit('setPointChanged', new messages.SLSetHeatSetPointMessage()); break; + case messages.SLSetHeatModeMessage.getResponseId(): + // console.log(" it's a heater mode ack"); + this.emit('heatModeChanged', new messages.SLSetHeatModeMessage()); + break; case messages.SLLightControlMessage.getResponseId(): // console.log(" it's a light control ack"); this.emit('sentLightCommand', new messages.SLLightControlMessage()); diff --git a/messages/SLSetHeatMode.js b/messages/SLSetHeatMode.js new file mode 100644 index 0000000..9460915 --- /dev/null +++ b/messages/SLSetHeatMode.js @@ -0,0 +1,29 @@ +'use strict'; + +const SLMessage = require('./SLMessage.js').SLMessage; + +const MSG_ID = 12538; + +exports.SLSetHeatMode = class SLSetHeatMode extends SLMessage { + constructor(controllerIndex, bodyType, heatMode) { + super(0, MSG_ID); + + this.controllerIndex = controllerIndex; + this.bodyType = bodyType; + this.heatMode = heatMode; + // heatmodes: + // 0: "Off", 1: "Solar", 2 : "Solar Preferred", 3 : "Heat Pump", 4: "Don't Change" + } + + encode() { + this.writeInt32LE(this.controllerIndex || 0); + this.writeInt32LE(this.bodyType || 0); + this.writeInt32LE(this.heatMode || 0); + + super.encode(); + } + + static getResponseId() { + return MSG_ID + 1; + } +}; diff --git a/messages/index.js b/messages/index.js index fdd1c59..d099248 100644 --- a/messages/index.js +++ b/messages/index.js @@ -10,4 +10,5 @@ exports.SLVersionMessage = require('./SLVersionMessage.js').SLVersionMessage; exports.SLSetCircuitStateMessage = require('./SLSetCircuitStateMessage.js').SLSetCircuitStateMessage; exports.SLGetGatewayDataMessage = require('./SLGetGatewayDataMessage.js').SLGetGatewayDataMessage; exports.SLSetHeatSetPointMessage = require('./SLSetHeatSetPoint.js').SLSetHeatSetPoint; +exports.SLSetHeatModeMessage = require('./SLSetHeatMode.js').SLSetHeatMode; exports.SLLightControlMessage = require('./SLLightControl.js').SLLightControl;