-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yadomi
committed
Nov 26, 2024
0 parents
commit f14f999
Showing
7 changed files
with
541 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
config/ | ||
compose.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM denoland/deno:alpine-1.45.5 | ||
|
||
WORKDIR /app | ||
|
||
COPY main.ts . | ||
COPY deno.lock . | ||
|
||
RUN deno cache main.ts | ||
|
||
CMD ["run", "--allow-net", "--allow-env", "--allow-read", "main.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# `hrules` | ||
|
||
hrules processes MQTT messages based on a text configuration file. The configuration file defines rules for subscribing to MQTT topics, evaluating a user defined expression, and publishing responses to specified topics. | ||
|
||
## `hrules.rules` File Structure | ||
|
||
The configuration file consists of multiple lines, each defining a specific rule. Each rule is separated into three parts using the "->" delimiter. The parts are as follows: | ||
|
||
1. **MQTT Topic to Subscribe**: The MQTT topic that the system should subscribe to. | ||
2. **Evaluation Expression**: An expression that is evaluated to determine if the response topic should be published. | ||
3. **Response Topic**: The MQTT topic to which the system should publish the response. | ||
|
||
## Syntax | ||
|
||
``` | ||
<mqtt_topic> -> <expression> -> <response_topic> | ||
<mqtt_topic> | <hours> -> <expression> -> <response_topic> <response_payload> | ||
``` | ||
|
||
### Example | ||
|
||
``` | ||
zigbee/wc/sensor01 -> payload.occupancy == true -> hue/set { match: { room: "WC", device: "*" }, state: { on: { on: true } } } | ||
``` | ||
|
||
### Detailed Breakdown | ||
|
||
1. **MQTT Topic to Subscribe**: `zigbee/wc/sensor01` | ||
- This is the MQTT topic that the system will subscribe to. | ||
|
||
2. **Evaluation Expression**: `payload.occupancy == true` | ||
- This expression evaluates the payload of the MQTT message. In this case, it checks if the `occupancy` field in the payload is `true`. | ||
|
||
3. **Response Topic**: `hue/set { match: { room: "WC", device: "*" }, state: { on: { on: true } } }` | ||
- This is the MQTT topic to which the system will publish the response. The response includes a JSON object used as a payload | ||
|
||
## Examples | ||
|
||
### Occupancy Sensors | ||
|
||
``` | ||
zigbee/bathroom/sensor01 -> payload.occupancy == true -> hue/set { match: { room: "Salle de bain", device: "*" }, state: { on: { on: true } } } | ||
zigbee/bathroom/sensor01 -> payload.occupancy == false -> hue/set { match: { room: "Salle de bain", device: "*" }, state: { on: { on: false } } } | ||
``` | ||
|
||
### Switches | ||
|
||
``` | ||
zigbee/kitchen/switch -> payload.action == "on_press_release" -> hue/set { match: { room: "Cusine", device: "*" }, state: { on: { on: true } } } | ||
zigbee/kitchen/switch -> payload.action == "off_press_release" -> hue/set { match: { room: "Cusine", device: "*" }, state: { on: { on: false } } } | ||
zigbee/living/switch -> payload.action == "down_hold_release" -> zigbee/living/powersocket02/set "OFF" | ||
zigbee/living/switch -> payload.action == "up_hold_release" -> zigbee/living/powersocket02/set "ON" | ||
``` | ||
|
||
### Time-Based Rules | ||
|
||
The configuration file also supports time-based rules using the | delimiter followed by a time range. This allows rules to be active only during specific times of the day. | ||
|
||
``` | ||
zigbee/room/switch | 09:00-22:30 -> payload.action == "on_press_release" -> hue/set { match: { room: "Chambre", device: "*" }, state: { on: { on: true }, brightness: 100 } } | ||
zigbee/room/switch | 22:30-09:00 -> payload.action == "on_press_release" -> hue/set { match: { room: "Chambre", device: "*" }, state: { on: { on: true }, brightness: 20 } } | ||
``` | ||
|
||
## Notes | ||
|
||
- The evaluation expression must return `true` for the response topic to be published | ||
- The response topic can include JSON objects or simple strings. If the payload is wrapped with quotes it will be treated as string and JSON otherwise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
tube: | ||
image: yadomi/hrules | ||
user: 1000:1000 | ||
restart: unless-stopped | ||
volumes: | ||
- ./config:/app/config/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"tasks": { | ||
"lock": "deno cache --lock=deno.lock --lock-write main.ts", | ||
"build": "docker build -t yadomi/hrules ." | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.