Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
e9ebf19
multiple upgrades
Sep 24, 2020
5463d98
fix README
Sep 24, 2020
76543e8
add set_default_shutdown function + duration event
Sep 24, 2020
ed970fe
fix log of connection error
Sep 24, 2020
cc5b610
catching errors and optimizing
Sep 25, 2020
22aa05a
fixed is_valid + show status event only for the chosen device
Sep 26, 2020
5b12a8b
add listen function and remove this.status_socket from default + adju…
Sep 28, 2020
2ccd3fb
fixed returning status in listen function
Sep 28, 2020
a9cef2b
added support for switcher runner
nitaybz Apr 1, 2021
a787f04
added support for switcher runner
nitaybz Apr 1, 2021
1ceba2c
fix syntax
nitaybz Apr 1, 2021
b652551
version
nitaybz Apr 1, 2021
e296636
remove console.log
nitaybz Apr 1, 2021
13cbf09
more logs
nitaybz Apr 1, 2021
2eba3eb
version
nitaybz Apr 1, 2021
3f3b2cb
fix log on listen
nitaybz Apr 2, 2021
a157587
version
nitaybz Apr 2, 2021
119eb65
reset p_session
nitaybz Apr 3, 2021
d2bdc85
version
nitaybz Apr 3, 2021
ba53d0d
add breeze support
nitaybz Dec 17, 2021
9f89f85
set device_id in file path to support multiple devices
nitaybz Dec 17, 2021
fd0533b
version
nitaybz Dec 17, 2021
ddba511
fix return set
nitaybz Dec 19, 2021
268bca8
fix return set
nitaybz Dec 19, 2021
c99a261
version
nitaybz Dec 19, 2021
ce311f1
added stop runner command + fixed deformed names & remote
nitaybz Jun 13, 2022
2a6baa1
sanitize state
nitaybz Jun 13, 2022
90094d0
update packages + prevent no waves in IRset
nitaybz Jun 14, 2022
3d8ce9e
several fixes
nitaybz Jun 18, 2022
d01810a
handle separated swing remotes
nitaybz Jun 18, 2022
9d9ef10
several fixes and addes eslint
nitaybz Jun 18, 2022
cc0cd19
version
nitaybz Jun 18, 2022
e0fa430
eslint update
nitaybz Jun 18, 2022
bf436ce
possible fix for remote detection
nitaybz Jul 10, 2022
5c19f9d
implement child lock for runner
nitaybz Aug 14, 2022
70cabeb
add new device s11/s12 support + create one general command function
nitaybz Aug 14, 2022
46b52d3
child lock support
nitaybz Aug 16, 2022
9cb7717
version
nitaybz Aug 16, 2022
1aa773f
fixed remote capture
nitaybz Aug 16, 2022
1cbbb40
version
nitaybz Aug 16, 2022
de9773a
add child lock status to runner
nitaybz Aug 16, 2022
d218f16
Extend length of the remote search + several bug fixes
nitaybz Sep 11, 2022
8dfd9d1
version
nitaybz Sep 11, 2022
850069a
fix remote extraction crash + update remotes file
nitaybz Oct 7, 2022
f35031a
fix for S11 S12 new versions
nitaybz Feb 12, 2023
e05e04f
allow hebrew names
nitaybz Feb 12, 2023
9866616
new logic including token for shutters
nitaybz Mar 16, 2023
07f5c15
use token only for s11 and s12
nitaybz Mar 23, 2023
9bb763a
version
nitaybz Mar 23, 2023
e4fea8a
added support for switcher lights
nitaybz Jun 4, 2023
973c314
fix crash
nitaybz Jun 4, 2023
025992b
fixed TCP groups + added mini lights devices
nitaybz Jun 4, 2023
0675b12
use lights with token
nitaybz Jun 4, 2023
1bad747
update old devices protocol
nitaybz Dec 12, 2023
31d2065
fix old protocol devices
nitaybz Dec 13, 2023
4126085
add method to update device key
nitaybz Dec 17, 2023
1f2cd03
added fuji remote
nitaybz Jan 2, 2025
9b5c828
1.6.8: log fixes in static methods + dep bumps
nitaybz May 6, 2026
d3c3b1e
1.6.9: add Switcher OnWall (model 0321) as boiler-family device
nitaybz May 6, 2026
a71463a
1.6.10: try OnWall on new TCP port + harden command error paths
nitaybz May 6, 2026
d91a873
1.7.0: self-heal stale TCP connections, retry once on connection fail…
nitaybz May 6, 2026
0d60d1b
1.7.1: better debug logging for connection and login flow
nitaybz May 6, 2026
7051a7c
1.8.0: Switcher Heater (031f) support, token-based protocol
nitaybz May 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 10 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"env": {
"node": true,
"es2022": true
},
"extends": "eslint:recommended",
"rules": {
"indent": ["error", "tab", { "SwitchCase": 1 }]
}
}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
log/

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down Expand Up @@ -102,3 +103,10 @@ dist

# TernJS port file
.tern-port

test2.js
test.js

cache/

.DS_Store
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cSpell.words": [
"ELEC",
"getsocket",
"inet",
"ipaddr",
"ntoa",
"precommand"
]
}
154 changes: 130 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,88 @@
# switcher-js
switcher-js is a native nodejs library for controling [switcher smart water heater](https://switcher.co.il/).<br/>
It is a native javascript port of a wonderful python script (can be found [here](https://github.com/NightRang3r/Switcher-V2-Python)) created as a result of the extensive work which has been done by Aviad Golan ([@AviadGolan](https://twitter.com/AviadGolan)) and Shai rod ([@NightRang3r](https://twitter.com/NightRang3r)).<br/>
# switcher-js2

*Fork of [@johnathanvidu JS implementation](https://github.com/johnathanvidu/switcher-js)*

switcher-js is a native nodejs library for controling [Switcher](https://switcher.co.il/) smart home accessories - water heater, sockets, and blinds.<br/><br/>
It is a native javascript port of a wonderful python script (can be found [here](https://github.com/NightRang3r/Switcher-V2-Python)) created as a result of the extensive work which has been done by Aviad Golan ([@AviadGolan](https://twitter.com/AviadGolan)) and Shai rod ([@NightRang3r](https://twitter.com/NightRang3r)).

It is a work in progress and there is still a lot of work left to do.

I built it according to my specific needs and my specific device. If any issue arises, please feel free to open an issue and I'll do my best to help.<br/>
Current supported devices known to work with switcher-js:<br/>
- **Switcher V3** (Switcher touch) - FW **V1.51**
I built it according to my specific needs and my specific device. If any issue arises, please feel free to open an issue and I'll do my best to help.

Current supported devices known to work with switcher-js:

- **Switcher Lights SL03**
- **Switcher Lights SL02**
- **Switcher Lights SL01**
- **Switcher Runner S12**
- **Switcher Runner S11**
- **Switcher Runner Mini**
- **Switcher Runner**
- **Switcher V4**
- **Switcher Mini**
- **Switcher V3**: (Switcher touch) - Firmware **V1.51**
- **Switcher V2**: Firmware **3.21** (Based on ESP chipset)
- **Switcher V2**: Firmware**72.32** (Qualcomm chipset)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested all three devices?


## Installation
Use [npm](https://www.npmjs.com/) to install switcher-js.
```bash
npm install switcher-js
npm install switcher-js2
```

## Usage
## Usage Examples:
```javascript
const Switcher = require('switcher-js').Switcher;
const Switcher = require('switcher-js2');

var switcher = new Switcher('device-id', 'device-ip', 'phone-id', 'device-pass', 'log function');
var switcher = new Switcher('device-id', 'device-ip', 'log function', 'listen(boolean)', 'device-type');
```

### Discover

To use the auto discover functionallity use:
```javascript
const Switcher = require('switcher-js').Switcher;
const Switcher = require('switcher-js2');

var proxy = Switcher.discover('phone-id', 'device-pass', 'log function');
var proxy = Switcher.discover('log function', 'identifier(optional)', 'discovery-timeout(optional)');

proxy.on('ready', (switcher) => {
switcher.turn_on(); // switcher is a new initialized instance of Switcher class
});


setTimeout(() => {
proxy.close(); // optional way to close the discovery (if discovery-timeout is not set)
}, 10000);

```

discover will emit a ready event when auto discovery completed.

phone-id (optional) - will be defaulted to 0000 if no value provided<br/>
device-pass (optional) - will be defaulted to 00000000 if no value provided
identifier (optional) - you can provide the Switcher name, IP or device-id to detect specific device.<br/>
discovery-timeout (optional) - set maximum time in seconds to scan for devices.

Examples:
```javascript
const Switcher = require('switcher-js').Switcher;

var switcher = new Switcher('device-id', 'device-ip', 'phone-id', 'device-pass', 'log function');
### Control

switcher.on('state', (state) => { // state is the new switcher state

```javascript
const Switcher = require('switcher-js2');

var switcher = new Switcher('device-id', 'device-ip', 'log function', 'listen', 'device-type');
// set listen to true if you want to listen for status messages

switcher.on('status', (status) => { // status broadcast message - only works when listen=true
console.log(status)
/* response:
{
power: 1,
remaining_seconds: 591,
default_shutdown_seconds: 5400,
power_consumption: 2447 // in watts
}
*/
});
switcher.on('state', (state) => { // state is the new switcher state
console.log(state) // 1
});
switcher.on('error', (error) => {

Expand All @@ -52,18 +91,85 @@ switcher.on('error', (error) => {
switcher.turn_on(); // turns switcher on
switcher.turn_on(15); // turns switcher on for 15 minutes
switcher.turn_off(); // turns switcher off
switcher.set_default_shutdown(3600) // set the default auto shutdown to 1 hour (must be between 3600 and 86340)
switcher.status(status => { // get status
console.log(status);
});
switcher.close(); // closes any dangling connections safely
```

switcher-js exposes two states for convenience
### Control Runner Devices (blinds)

```javascript
const switcher = require('switcher-js');
const Switcher = require('switcher-js2');

var runner = new Switcher('device-id', 'device-ip', 'log function', 'listen', 'runner');
// set 'device-type' to 'runner' if you want to control the runner devices

runner.on('status', (status) => { // status broadcast message - only works when listen=true
console.log(status)
/* response:
{
position: 80,
direction: 'STOP'
}
*/
});
runner.on('position', (pos) => { // position is the new switcher position
console.log(pos) // 100
});
switcher.on('error', (error) => {

});

switcher.set_position(80); // Set blinds position to 80%

switcher.stop_runner() // stop the blinds

switcher.close(); // closes any dangling connections safely
```

### Listen

Global listen functionality that listens to a single or multiple switcher devices for status messages.

To use the listen functionallity use:
```javascript
const Switcher = require('switcher-js2');

var proxy = Switcher.listen('log function', 'identifier(optional)');

proxy.on('message', (message) => {
console.log(message)
/* response:
{
device_id: 'e3a845',
device_ip: '10.0.0.1',
name: 'Boiler',
type: 'v4'
state: {
power: 1,
remaining_seconds: 591,
default_shutdown_seconds: 5400,
power_consumption: 2447 // in watts
}
}
*/
});

proxy.close(); // close the listener socket

switcher.ON = 0
switcher.OFF = 1
```

proxy will emit a message event every time it receives a message from a switcher device.

identifier (optional) - you can provide the Switcher name, IP or device-id to filter specific device messages.

## Multiple Connections

Don't use Discover, Listen and Switcher with (listen=true) at the same time as it will return error since this socket is being used.
If you want to listen to multiple devices, use the global listen function to get all statuses, and use the switcher instance without the listen capability.

## Contributing
Pull requests are more than welcome. For major changes, please open an issue first to discuss what you would like to change.
Even coding tips and standards are welcome, I have very limited experience with javascript, so there's a lot of things I don't know are cleaner or more standarized in the industry.
Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const switcher = require('./src/switcher');


module.exports = {
Switcher: switcher.Switcher
}
module.exports = switcher.Switcher
Loading