Skip to content

Commit

Permalink
Merge pull request #130 from Dirnei/fix/shelly25
Browse files Browse the repository at this point in the history
Fix shelly25 node MQTT config
  • Loading branch information
Dirnei committed Nov 14, 2022
2 parents 39ad1a8 + 9cdfc50 commit 03536db
Show file tree
Hide file tree
Showing 22 changed files with 1,286 additions and 197 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = {
"browser": true,
"es2021": true,
"node": true,
"amd": true
"amd": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/node.js-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build
- run: npm test
- run: npm run test
- run: npm run testintegration
- run: npm run lint
- run: npm install -g node-red-dev
- run: node-red-dev validate
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.idea
debug
node_modules
dist
Expand Down
8 changes: 6 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Contributing

Everyone is welcomed to create a pull request. If you are unsure what or how to do something, we can discuss it on [GitHub](https://github.com/Dirnei/node-red-contrib-zigbee2mqtt-devices) or [Discord](https://discord.gg/4qCMEhJ).
Everyone is welcome to create a pull request. If you are unsure what or how to do something, we can discuss it on [GitHub](https://github.com/Dirnei/node-red-contrib-zigbee2mqtt-devices) or [Discord](https://discord.gg/4qCMEhJ).


# Development Environment

The project is written in JavaScript, HTML, and Typescript. We are currently in the process of migrating towards Typescript for new nodes.
The project is written in JavaScript, HTML, and Typescript.

For easier development, we have a couple of npm tasks:

Expand All @@ -18,6 +18,10 @@ In VS-Code you can also press <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>B</kbd>

`npm run createnode` to create a new JavaScript node. There is no template for a Typescript node yet.

`npm test` runs the unit tests in the `test` folder.

`npm testintegration` runs the integration tests in the `test-integration` folder. It starts the services in `test-integration/docker` and runs the integration tests against those services.

# System requirements
Developing is possible on Windows, Linux, and macOS. The IDE is up to you; we use VS-Code.

Expand Down
13 changes: 13 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ If you feel very generous and want to contribute with coffee, you sure can:

## Changelog

### Release: `0.19.6` _13 Nov 2022_

#### Features:

#### Bug fixes:
- Bridge did not connect in newer z2m versions because z2m changed the format of 'bridge/state' from string to JSON.
- Shelly 2.5 did not connect to the broker, because it used an old configuration node.
- Shelly 2.5 node did not unsubscribe from the old channel with no full redeploy.

#### Behind the scenes
- Add mocha and first-unit test examples
- Add integration tests to test with a real MQTT broker

### Release: `0.19.5` - _14 Mar 2022_

#### Bug fixes:
Expand Down
Binary file added docs/nodes/img/shelly25-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/nodes/img/shelly25-listen-input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/nodes/img/shelly25-toggle-relay-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/nodes/img/shelly25-toggle-relay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions docs/nodes/shelly-25-node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Shelly 2.5

The shelly 2.5 node controls the relays on a shelly and receives input, relay, and status changes.

Tested with the following Shellies:
- Shelly 1
- Shelly 2.5

## Configuration

![img](img/shelly25-config.png)

### Broker

For more information see [mqtt-config](../config/mqtt-config.md)

### Device

The device section configures a shelly's MQTT topic and, optionally, its friendly name.
For example, `shellies/my-device`, the shelly node will subscribe and publish on this topic.

### Channel

The channel configures which relay will be triggered when the node receives an input. Furthermore, the node only publishes relay and input changes for the selected input.
Possible options are:
- `Channel 1`: Switches and subscribes to channel 1 (MQTT topic `relay/0` and `input/0`).
- `Channel 2`: Switches and subscribes to channel 2 (MQTT topic `relay/1` and `input/1`).
- `Both`: Switches and subscribes to channels 1 and 2.

For the shelly 1, one should stick to channel one, as it has only one input and relay.

### State
The state is used to control the relay when the node receives an input.
- `On`: Switches the relay for the selected channel to on.
- `Off`: Switches the relay for the selected channel to off.
- `Toggle`: Switches the relay for the selected channel on if it is off and vice versa.

### Enable Input
This option enables the input connector on the node. Only when it is enabled is it possible to switch the relays.

### Custom payload
The custom payload allows you to define a specific payload to be published when the shelly's input state changes since the default are `0` and `1`, which might not be too helpful, primarily if two channels are used. For example:
- Payload 1: Input one was triggered
- Payload 2: Input zero was triggered


## Usage

### Control a shelly's relay

On input, the shelly 2.5 node prepares a payload sent to the shelly by [send-messages](send-messages.md) via MQTT.

The inject node triggers the shelly node to create a payload. The shelly node is configured to toggle its state between on and off. Moreover, only channel one is selected. The send-messages node is configured to use an MQTT broker as well as a zigbee2mqtt topic. The zigbee2mqtt topic is ignored for shellies, and they publish at the configured topic, usually `shellies/my-device`.


![img](img/shelly25-toggle-relay-settings.png)

![img](img/shelly25-toggle-relay.png)

To try it, have a look at the example: [shelly25-toggle-relay.json](../../examples/shelly-25/shelly25-toggle-relay.json)


### Receive input or relay changes from a shelly

When the relay actuates, or a payload is sent to the first output to the 'Log shelly relay' debug node.
When the input changes, a payload is sent to the second output to the 'Log shelly input' debug node.

![img](img/shelly25-listen-input.png)

To try it, have a look at the example: [shelly25-listen-to-input.json](../../examples/shelly-25/shelly25-listen-to-input.json)


[*← back to the index*](../documentation.md)
97 changes: 97 additions & 0 deletions examples/shelly-25/shelly25-listen-to-input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
[
{
"id": "ddc73c09685b6ca2",
"type": "debug",
"z": "d6c6189e516c5861",
"name": "Log shelly input",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 440,
"y": 200,
"wires": []
},
{
"id": "876f6827a210a969",
"type": "shelly-25",
"z": "d6c6189e516c5861",
"name": "Shelly 1 Terrace Light",
"mqtt": "b1503ab27dfa3ccd",
"shelly": "daf62c0c2a5c1ebd",
"enableInput": false,
"state": "on",
"channel": "2",
"inputs": 0,
"outputs": 2,
"customPayload": true,
"payloadInput0": "",
"typeInput0": "str",
"payloadInput1": "",
"typeInput1": "str",
"x": 200,
"y": 180,
"wires": [
[
"2212d8cf185ffa8e"
],
[
"ddc73c09685b6ca2"
]
]
},
{
"id": "2212d8cf185ffa8e",
"type": "debug",
"z": "d6c6189e516c5861",
"name": "Log shelly relay",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 440,
"y": 160,
"wires": []
},
{
"id": "b1503ab27dfa3ccd",
"type": "mqtt-broker",
"name": "Mosquitto",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": "",
"credentials": {}
},
{
"id": "daf62c0c2a5c1ebd",
"type": "shelly-config",
"name": "terrace-light",
"prefix": "shellies/terrace-light"
}
]
109 changes: 109 additions & 0 deletions examples/shelly-25/shelly25-toggle-relay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
[
{
"id": "8bcc1c584da5c6f6",
"type": "shelly-25",
"z": "d6c6189e516c5861",
"name": "Shelly 1 Terrace Light",
"mqtt": "b1503ab27dfa3ccd",
"shelly": "daf62c0c2a5c1ebd",
"enableInput": true,
"state": "toggle",
"channel": "0",
"inputs": 1,
"outputs": 3,
"customPayload": false,
"payloadInput0": "",
"typeInput0": "str",
"payloadInput1": "",
"typeInput1": "str",
"x": 440,
"y": 400,
"wires": [
[],
[],
[
"0e5a9766c04a1a6a"
]
]
},
{
"id": "2b95eb1c49dc7662",
"type": "inject",
"z": "d6c6189e516c5861",
"name": "Virtual light switch",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 170,
"y": 400,
"wires": [
[
"8bcc1c584da5c6f6"
]
]
},
{
"id": "0e5a9766c04a1a6a",
"type": "send-messages",
"z": "d6c6189e516c5861",
"name": "",
"bridge": "11358734e0ff49d5",
"x": 660,
"y": 400,
"wires": []
},
{
"id": "b1503ab27dfa3ccd",
"type": "mqtt-broker",
"name": "Mosquitto",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "daf62c0c2a5c1ebd",
"type": "shelly-config",
"name": "terrace-light",
"prefix": "shellies/terrace-light"
},
{
"id": "11358734e0ff49d5",
"type": "zigbee2mqtt-bridge-config",
"name": "Mosquitto",
"broker": "b1503ab27dfa3ccd",
"baseTopic": "zigbee2mqtt",
"enabledLogging": false,
"allowDeviceStatusRefresh": true
}
]
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-zigbee2mqtt-devices",
"version": "0.19.5",
"version": "0.19.6",
"description": "Nodes to interact with zigbee2mqtt for Node-RED",
"author": "Christian Dirnhofer",
"license": "MIT",
Expand Down Expand Up @@ -48,8 +48,9 @@
"createnode": "run-script-os",
"createnode:nix": "pwsh ./createNode.ps1",
"createnode:win32": "@powershell -NoProfile -Command ./createNode.ps1",
"lint": "eslint ./src/**/*.js",
"test": "mocha \"test/**/*_spec.js\""
"lint": "eslint ./src/**/*.js ./test/**/*.js ./test-integration/**/*.js",
"test": "mocha \"test/**/*_spec.js\"",
"testintegration": "docker-compose -f test-integration/docker/docker-compose.yml up -d && mocha \"test-integration/**/*_spec.js\""
},
"devDependencies": {
"@types/jquery": "^3.5.13",
Expand Down
Loading

0 comments on commit 03536db

Please sign in to comment.