diff options
| -rw-r--r-- | README.md | 28 | ||||
| -rw-r--r-- | cache.go | 1 | ||||
| -rw-r--r-- | main.go | 4 | ||||
| -rw-r--r-- | mqtt.go | 4 | ||||
| -rw-r--r-- | shelly.go | 6 | ||||
| -rw-r--r-- | tplink.go | 6 |
6 files changed, 42 insertions, 7 deletions
@@ -118,9 +118,21 @@ For all terms not explained here see the [MQTT version 3.1.1 documentation][9]. - `open`: contact is open - `closed`: contact is closed +### `/cover/<id>` + +- description: Discovery of Shelly 2PM Gen3 covers +- direction: Sia server to client +- Quality of Service: QoS 1 (at least once) +- retained: yes +- receives will message: no +- topic parameters: + - `id`: ID of the Shelly 2PM Gen3 cover +- payloads: + - `exists`: a device with the given ID exists + ### `/cover/<id>/movement` -- description: Allows control of Shelly 2PM Gen3 covers +- description: Control of Shelly 2PM Gen3 covers - direction: client to Sia server - Quality of Service: QoS 2 (exactly once) - retained: no @@ -132,9 +144,21 @@ For all terms not explained here see the [MQTT version 3.1.1 documentation][9]. - `retract`: cover decreases the covering surface - `stop`: cover stops current motion if given +### `/plug/<id>` + +- description: Discovery of TP-Link HS100 Wi-Fi plugs +- direction: Sia server to client +- Quality of Service: QoS 1 (at least once) +- retained: yes +- receives will message: no +- topic parameters: + - `id`: ID of the TP-Link HS100 Wi-Fi plug +- payloads: + - `exists`: a device with the given ID exists + ### `/plug/<id>/action` -- description: Implements control of tp-link HS100 Wi-Fi plugs +- description: Control of TP-Link HS100 Wi-Fi plugs - direction: client to Sia server - Quality of Service: QoS 2 (exactly once) - retained: no @@ -43,6 +43,7 @@ func (c *Cache) Update(states States) { c.Tx <- MQTTMessage{ Topic: topic, Payload: payload, + Retain: true, } } c.States[id] = state @@ -24,8 +24,8 @@ func main() { go MQTTRun(config.MQTT, tx, coverMovement, plugAction) go HomematicRun(config.Homematic, tx) - go ShellyRun(config.Shelly, coverMovement) - go TPLinkRun(config.TPLink, plugAction) + go ShellyRun(config.Shelly, tx, coverMovement) + go TPLinkRun(config.TPLink, tx, plugAction) Await(syscall.SIGTERM, syscall.SIGINT) } @@ -27,6 +27,7 @@ var ( type MQTTMessage struct { Topic string Payload []byte + Retain bool } type Route struct { @@ -60,6 +61,7 @@ func MQTTRun(config MQTTConfig, tx chan MQTTMessage, routes ...Route) { message := MQTTMessage{ Topic: strings.TrimPrefix(msg.Topic(), config.TopicPrefix + "/"), Payload: msg.Payload(), + Retain: msg.Retained(), } route.Destination <- message }) @@ -88,7 +90,7 @@ func MQTTRun(config MQTTConfig, tx chan MQTTMessage, routes ...Route) { for message := range tx { topic := fmt.Sprintf("%s/%s", config.TopicPrefix, message.Topic) - client.Publish(topic, QoS1, RETAINED, message.Payload) + client.Publish(topic, QoS1, message.Retain, message.Payload) } } @@ -9,7 +9,11 @@ import ( "github.com/gorilla/websocket" ) -func ShellyRun(config ShellyConfigs, route Route) { +func ShellyRun(config ShellyConfigs, tx chan MQTTMessage, route Route) { + for _, shelly := range config { + tx <- MQTTMessage{fmt.Sprintf("cover/%s", shelly.ID), []byte("exists"), true} + } + for message := range route.Destination { ip, command, err := parseMessage(config, message) if err != nil { @@ -16,7 +16,11 @@ const ( TPLink_HS100_OFF = false ) -func TPLinkRun(config TPLinkConfigs, route Route) { +func TPLinkRun(config TPLinkConfigs, tx chan MQTTMessage, route Route) { + for _, tplink := range config { + tx <- MQTTMessage{fmt.Sprintf("plug/%s", tplink.ID), []byte("exists"), true} + } + for message := range route.Destination { ip, action, err := tplinkParseMessage(config, message) if err != nil { |
