Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
All notable changes to this project will be documented in this file.

## 2026-02
- Mark YS-IRTM scripts as production; add all 6 to manifest; remove Under Development banner from README
- Add JK200 BMS MODBUS-RTU reader (`the_pill/MODBUS/JK200-MBS`) with README
- Mark Deye SG02LP1 MODBUS-RTU scripts as production; fix @link URLs; add to manifest; add README
- Auto-set script name on device from original filename in `put_script.py`
- Add default manifest path to `sync-manifest-json.py` based on script location
- Remove non-production `ble/events-to-kvs.shelly.js` from manifest (missing @status)
- Add remote feature branch cleanup rule to AGENTS.md git workflow
- Add dev branch to CI/CD pull_request trigger
Expand Down
36 changes: 36 additions & 0 deletions SHELLY_MJS.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,42 @@ switch-input/shelly2p-domo-coverfix.shelly.js: Shelly Plus 2PM cover fix for Dom
Simple fix for outgoing Domoticz MQTTAD command 'GoToPosition'.
Shelly firmware 0.x supported. Developed for ShellyTeacher4Domo.

the_pill/MODBUS/Deye/the_pill_mbsa_deye.shelly.js: Deye SG02LP1 MODBUS-RTU
===
MODBUS-RTU example for reading Deye SG02LP1 solar inverter parameters over UART using the MODBUS-RTU master library.

the_pill/MODBUS/Deye/the_pill_mbsa_deye_vc.shelly.js: Deye SG02LP1 MODBUS-RTU + Virtual Components
===
MODBUS-RTU reader for Deye SG02LP1 solar inverter with Virtual Component updates. Reads parameters over UART (RS485) and pushes values to user-defined virtual number components.

the_pill/UART/uart_test.shelly.js: UART test
===
Simple UART loopback test that sends periodic messages and prints received data.

the_pill/ys_irtm/ysirtm.shelly.js: YS-IRTM infrared UART library
===
UART protocol implementation for YS-IRTM to send and receive NEC IR codes.

the_pill/ys_irtm/btn2ir.shelly.js: YS-IRTM button-to-IR example
===
Maps Shelly buttons and inputs to IR codes using YS-IRTM.

the_pill/ys_irtm/ir2sw.shelly.js: YS-IRTM IR-to-switch example
===
Maps received IR codes to Shelly switch actions.

the_pill/ys_irtm/ir_full.shelly.js: YS-IRTM advanced IR automation example
===
Bidirectional IR automation with scenes, HTTP calls, and switch integration.

the_pill/ys_irtm/ir_learn.shelly.js: YS-IRTM IR learn mode
===
Captures and prints NEC IR codes for reuse in other scripts.

the_pill/ys_irtm/tv_ir.shelly.js: YS-IRTM TV remote codes
===
Preconfigured NEC IR codes for common TV brands using YS-IRTM.

weather-env/cover-control-weather.shelly.js: Control a Shelly 2.5 (Gen1) depending on current cloud conditions
===
The script, when run, will fetch via REST api from a weather service the current conditions for a location check if
Expand Down
45 changes: 45 additions & 0 deletions examples-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,51 @@
"title": "Shelly Plus 2PM cover fix for Domoticz MQTTAD v1",
"description": "Simple fix for outgoing Domoticz MQTTAD command 'GoToPosition'.\n Shelly firmware 0.x supported. Developed for ShellyTeacher4Domo."
},
{
"fname": "the_pill/MODBUS/Deye/the_pill_mbsa_deye.shelly.js",
"title": "Deye SG02LP1 MODBUS-RTU",
"description": "MODBUS-RTU example for reading Deye SG02LP1 solar inverter parameters over UART using the MODBUS-RTU master library."
},
{
"fname": "the_pill/MODBUS/Deye/the_pill_mbsa_deye_vc.shelly.js",
"title": "Deye SG02LP1 MODBUS-RTU + Virtual Components",
"description": "MODBUS-RTU reader for Deye SG02LP1 solar inverter with Virtual Component updates. Reads parameters over UART (RS485) and pushes values to user-defined virtual number components."
},
{
"fname": "the_pill/UART/uart_test.shelly.js",
"title": "UART test",
"description": "Simple UART loopback test that sends periodic messages and prints received data."
},
{
"fname": "the_pill/ys_irtm/ysirtm.shelly.js",
"title": "YS-IRTM infrared UART library",
"description": "UART protocol implementation for YS-IRTM to send and receive NEC IR codes."
},
{
"fname": "the_pill/ys_irtm/btn2ir.shelly.js",
"title": "YS-IRTM button-to-IR example",
"description": "Maps Shelly buttons and inputs to IR codes using YS-IRTM."
},
{
"fname": "the_pill/ys_irtm/ir2sw.shelly.js",
"title": "YS-IRTM IR-to-switch example",
"description": "Maps received IR codes to Shelly switch actions."
},
{
"fname": "the_pill/ys_irtm/ir_full.shelly.js",
"title": "YS-IRTM advanced IR automation example",
"description": "Bidirectional IR automation with scenes, HTTP calls, and switch integration."
},
{
"fname": "the_pill/ys_irtm/ir_learn.shelly.js",
"title": "YS-IRTM IR learn mode",
"description": "Captures and prints NEC IR codes for reuse in other scripts."
},
{
"fname": "the_pill/ys_irtm/tv_ir.shelly.js",
"title": "YS-IRTM TV remote codes",
"description": "Preconfigured NEC IR codes for common TV brands using YS-IRTM."
},
{
"fname": "weather-env/cover-control-weather.shelly.js",
"title": "Control a Shelly 2.5 (Gen1) depending on current cloud conditions",
Expand Down
155 changes: 155 additions & 0 deletions the_pill/MODBUS/ComWinTop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# ComWinTop CWT-MB308V GPIO Expander

> **Under Development** - This script is currently under development and may not be fully functional.

Script for communicating with the **ComWinTop CWT-MB308V** IO module via MODBUS-RTU over RS485/UART using The Pill.

## Files

### [mb308v.shelly.js](mb308v.shelly.js)

**CWT-MB308V GPIO Expander Example** - Complete example for the ComWinTop MB308V IO module.

---

## Hardware Requirements

- Shelly device with UART (e.g., **The Pill**)
- RS485 transceiver module (e.g., MAX485, SP485)
- ComWinTop CWT-MB308V IO module (7-35VDC supply)

### Device Specifications

| Feature | Detail |
|---|---|
| Analog Inputs (AI) | 8 channels — 4-20mA / 0-5V / 0-10V (configurable per channel) |
| Analog Outputs (AO) | 4 channels — 0-10V / 4-20mA |
| Digital Inputs (DI) | 8 channels — dry contact / NPN |
| Digital Outputs (DO) | 12 relay outputs |

### Wiring

**RS485 module to Shelly (The Pill):**

| RS485 Module | Shelly / The Pill |
|---|---|
| RO (Receiver Output) | RX (GPIO) |
| DI (Driver Input) | TX (GPIO) |
| VCC | 3.3V or 5V |
| GND | GND |

**RS485 module to CWT-MB308V:**

| RS485 Module | CWT-MB308V |
|---|---|
| A (D+) | A (D+) |
| B (D-) | B (D-) |

**Power:** Connect 7-35VDC to the MB308V power terminals separately.

**UART Settings:** 9600 baud, 8N1, Slave ID: 1 (default)

---

## Register Map

| Type | Function Code | Address Range | Count |
|---|---|---|---|
| Digital Outputs (DO) | FC 0x01 (read) / FC 0x05 (write) | 0–11 | 12 coils |
| Digital Inputs (DI) | FC 0x02 (read) | 0–7 | 8 inputs |
| Analog Outputs (AO) | FC 0x03 (read) / FC 0x06 (write) | 0–3 | 4 registers |
| Analog Inputs (AI) | FC 0x04 (read) | 0–7 | 8 registers |

---

## API Methods

```javascript
readDigitalInputs(callback) // Read 8 DI
readDigitalOutputs(callback) // Read 12 DO (relays)
writeDigitalOutput(channel, value, cb) // Set relay (0-11, true/false)
readAnalogInputs(callback) // Read 8 AI
readAnalogOutputs(callback) // Read 4 AO
writeAnalogOutput(channel, value, cb) // Set AO (0-3, 0-24000)

// Conversion helpers
aiToMilliamps(raw) // Convert AI to mA (4-20mA mode)
aiToVoltage(raw) // Convert AI to V (0-10V mode)
milliampsToAo(mA) // Convert mA to AO value
voltageToAo(volts) // Convert V to AO value
```

---

## Usage Examples

**Read all digital inputs:**

```javascript
readDigitalInputs(function(err, inputs) {
if (err) {
print("Error: " + err);
return;
}
for (var i = 0; i < inputs.length; i++) {
print("DI" + i + ": " + (inputs[i] ? "ON" : "OFF"));
}
});
```

**Control relay output:**

```javascript
// Turn ON relay 0
writeDigitalOutput(0, true, function(err, success) {
if (success) print("Relay 0 ON");
});

// Turn OFF relay 5
writeDigitalOutput(5, false, function(err, success) {
if (success) print("Relay 5 OFF");
});
```

**Read analog inputs (4-20mA sensors):**

```javascript
readAnalogInputs(function(err, values) {
if (err) return;
for (var i = 0; i < values.length; i++) {
var mA = aiToMilliamps(values[i]);
print("AI" + i + ": " + mA.toFixed(2) + " mA");
}
});
```

**Set analog output (0-10V mode):**

```javascript
// Set AO0 to 5V
var rawValue = voltageToAo(5.0);
writeAnalogOutput(0, rawValue, function(err, success) {
if (success) print("AO0 set to 5V");
});
```

---

## Configuration

```javascript
var CONFIG = {
BAUD_RATE: 9600, // 9600, 19200, 38400, 115200
MODE: "8N1", // "8N1", "8E1", "8O1"
RESPONSE_TIMEOUT: 1000, // ms
DEBUG: true
};
```

---

## References

- [ComWinTop CWT-MB308V Product Page](https://store.comwintop.com/products/cwt-mb308v-8ai-4ao-8di-12do-rs485-rs232-ethernet-modbus-rtu-tcp-io-acquisition-module)
- [MB308V Python Driver (reference)](https://github.com/bgerp/ztm/blob/master/Zontromat/devices/vendors/cwt/mb308v/mb308v.py)
- [MODBUS Protocol Specification](https://modbus.org/specs.php)
Loading