From 40d69c16505855ae3b83ccaa93e0cd219df7583d Mon Sep 17 00:00:00 2001 From: TheMrBooyah Date: Thu, 24 Nov 2022 18:01:21 +0100 Subject: [PATCH 1/3] Add MQTT authorization --- .../de/dvdgeisler/iot/dirigera/client/mqtt/MqttBridge.java | 7 +++++++ .../src/main/resources/application.properties | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dirigera-client-mqtt/src/main/java/de/dvdgeisler/iot/dirigera/client/mqtt/MqttBridge.java b/dirigera-client-mqtt/src/main/java/de/dvdgeisler/iot/dirigera/client/mqtt/MqttBridge.java index 68164fa..aedb848 100644 --- a/dirigera-client-mqtt/src/main/java/de/dvdgeisler/iot/dirigera/client/mqtt/MqttBridge.java +++ b/dirigera-client-mqtt/src/main/java/de/dvdgeisler/iot/dirigera/client/mqtt/MqttBridge.java @@ -22,6 +22,8 @@ public class MqttBridge extends org.eclipse.paho.client.mqttv3.MqttClient { public MqttBridge( @Value("${dirigera.mqtt.hostname:localhost}") final String host, @Value("${dirigera.mqtt.port:1883}") final Short port, + @Value("${dirigera.mqtt.username:}") final String username, + @Value("${dirigera.mqtt.password:}") final String password, @Value("${dirigera.mqtt.reconnect:true}") final Boolean reconnect, @Value("${dirigera.mqtt.timeout:10}") final Integer timeout, final DirigeraApi api) throws MqttException { @@ -38,6 +40,11 @@ public MqttBridge( options.setAutomaticReconnect(reconnect); options.setCleanSession(true); options.setConnectionTimeout(timeout); + + if (!username.isEmpty() && !password.isEmpty()) { + options.setUserName(username); + options.setPassword(password.toCharArray()); + } this.connect(options); log.info("Connection to MQTT broker successfully established"); diff --git a/dirigera-client-mqtt/src/main/resources/application.properties b/dirigera-client-mqtt/src/main/resources/application.properties index aed4086..a43a251 100644 --- a/dirigera-client-mqtt/src/main/resources/application.properties +++ b/dirigera-client-mqtt/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.application.name=Dirigera Dump +spring.application.name=Dirigera MQTT logging.level.root=error logging.level.de.dvdgeisler.iot.dirigera=debug spring.main.web-application-type=none From 6f59a1f0836c8133030ce56f292198778cc65d94 Mon Sep 17 00:00:00 2001 From: TheMrBooyah Date: Thu, 24 Nov 2022 18:48:54 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 25d36d5..ae37117 100644 --- a/README.md +++ b/README.md @@ -113,17 +113,16 @@ java -jar ./dirigera-client-dump/target/dirigera-client-dump-0.0.1-SNAPSHOT.jar ## Integration to Home Assistant Lights and sockets can be integrated into Home Assistant via MQTT (more devices will follow). -Therefore, the application [dirigera-client-mqtt](dirigera-client-mqtt/src/main/java/de/dvdgeisler/iot/dirigera/client/mqtt/DirigeraClientMqttApplication.java) -is started as a service giving the hostnames of the Dirigera, and the MQTT broker, e.g.: -```bash -./mvnw package -java -jar dirigera-client-mqtt/target/dirigera-client-mqtt-0.0.1-SNAPSHOT.jar \ - --dirigera.hostname= \ - --dirigera.mqtt.hostname= \ - --dirigera.mqtt.port= -``` Home Assistant will create entities for supported devices, based on its MQTT auto discovery approach. +Add https://github.com/TheMrBooyah/hassio-repository to your home assistant. +Update the configuration to your setup. + +In order to get your 'Token', run the [Dump Application](dirigera-client-dump/src/main/java/de/dvdgeisler/iot/dirigera/client/dump/DumpApplication.java). This will ask you to pair your gateway. After successfully pairing the gateway a file 'dirigera_access_token' will be created. Open the file with your favourite text editor and copy everything into the 'Token' field. + +Start the addon, watch the logs for any errors and if everything went as expected, home assistant should have some new devices/entities from your IKEA Smart Hub. + + ![](img/hass-integration.png) ## Other repos to dig in From ac8c2156709e53653a6055df2788f715bd93ff88 Mon Sep 17 00:00:00 2001 From: TheMrBooyah Date: Thu, 24 Nov 2022 21:14:55 +0100 Subject: [PATCH 3/3] Set final name for easier add-on creation process --- dirigera-client-mqtt/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/dirigera-client-mqtt/pom.xml b/dirigera-client-mqtt/pom.xml index 8d81de1..16090fc 100644 --- a/dirigera-client-mqtt/pom.xml +++ b/dirigera-client-mqtt/pom.xml @@ -40,6 +40,7 @@ + dirigera-client-mqtt org.springframework.boot