owlbrain-mqtt
v0.1.0
Published
**MQTT integration for OwlBrain — connect to a MQTT server and listen and publish messages.**
Readme
OwlBrain MQTT
MQTT integration for OwlBrain — connect to a MQTT server and listen and publish messages.
This integration lets your OwlBrain scripts react to MQTT messages using simple decorators.
List of provided decorators
Events
- @OnMessage — Listen to messages
Quickstart
Install
npm install owlbrain-core owlbrain-mqttEnable the MQTT integration
import { OwlBrain } from "owlbrain-core"
import { MqttIntegration } from "owlbrain-mqtt"
async function main() {
await OwlBrain.withIntegration(new MqttIntegration({ port: 3000 })).run()
}Options
| Option | Type | Default | Description |
| --- | --- | --- | --- |
| url | string | required | Url to the MQTT server |
| url | username | | Username if required to connect to the MQTT server |
| url | password | | Username if required to connect to the MQTT server |
| name | string | "mqtt" | Unique integration name. Change this if you want multiple MQTT connections. |
Create a script with MQTT routes
import { Script } from "owlbrain-core"
import { MqttIntegration, OnMessage, type OwlMessage, type MqttClient } from "owlbrain-mqtt"
@Script()
export class UserScript extends Script {
@Inject(["mqtt", "client"])
private mqtt: MqttClient!
@OnMessage("sensor/back kitchen/temperature")
async onHighTemp(event: OnMessage) {
if(event.message > 120)
this.mqtt.publish("fan/back kitchen/set", { state: "ON" })
}
}Examples
Also find more examples on owlbrain-core package
