diff --git a/bundles/org.openhab.binding.ferroamp/README.md b/bundles/org.openhab.binding.ferroamp/README.md index 6359f332512..ba51464bb0d 100644 --- a/bundles/org.openhab.binding.ferroamp/README.md +++ b/bundles/org.openhab.binding.ferroamp/README.md @@ -4,6 +4,8 @@ The Ferroamp binding is used to get live data from Ferroamp EnergyHub The Ferroamp binding is compatible with EnergyHub Wall and EnergyHub XL, and connects to your local EnergyHub via LAN. Data and commands are received/sent using MQTT where the user connects to the MQTT broker residing on the EnergyHub. +The communication with the broker might take some minute to establish, so Please just be patient. The Thing will be +in state INITIALIZATION during this time and ONLINE once connection is established. *note* Contact Ferroamp support to enable MQTT in the EnergyHub and to get the Username and Password: @@ -209,11 +211,7 @@ Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUser ``` ```java -Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=false, ssoS0=true ] -``` - -```java -Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=true, ssoS0=true, eso=true ] +Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=true, eso=true ] ``` @@ -226,20 +224,21 @@ String Ferroamp "RequestCharge" { channel="ferroamp:energyhub:myenergyh ## Rules -Ex. Set Charging with 5000W with cron trigger: +Ex. Rule name: Set Charge Level. +Set charging level to 5000W when item RequestCharge is updated. ```yaml +configuration: {} triggers: - id: "1" + - id: "1" configuration: - cronExpression: 0 0/2 * * * ? * - type: timer.GenericCronTrigger + itemName: EnergyHub_RequestCharge + type: core.ItemStateUpdateTrigger conditions: [] actions: - inputs: {} - id: "2" + - id: "2" configuration: - type: application/vnd.openhab.dsl.rule - script: ChargingWith5000W.sendCommand("5000") - type: script.ScriptAction + itemName: EnergyHub_RequestCharge + command: "5000" + type: core.ItemCommandAction ``` diff --git a/bundles/org.openhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampHandler.java b/bundles/org.openhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampHandler.java index 8be70518dcb..9528f38eca0 100644 --- a/bundles/org.openhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampHandler.java +++ b/bundles/org.openhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampHandler.java @@ -68,16 +68,16 @@ public class FerroampHandler extends BaseThingHandler implements MqttMessageSubs if (FerroampBindingConstants.CHANNEL_REQUESTCHARGE.equals(channelUID.getId())) { String requestCmdJsonCharge = "{\"" + "transId" + "\":\"" + transId + "\",\"cmd\":{\"name\":\"charge\",\"arg\":\"" + valueConfiguration + "\"}}"; - FerroampMqttCommunication.sendMQTT(requestCmdJsonCharge, ferroampConfig); + FerroampMqttCommunication.sendPublishedTopic(requestCmdJsonCharge, ferroampConfig); } if (FerroampBindingConstants.CHANNEL_REQUESTDISCHARGE.equals(channelUID.getId())) { String requestCmdJsonDisCharge = "{\"" + "transId" + "\":\"" + transId + "\",\"cmd\":{\"name\":\"discharge\",\"arg\":\"" + valueConfiguration + "\"}}"; - FerroampMqttCommunication.sendMQTT(requestCmdJsonDisCharge, ferroampConfig); + FerroampMqttCommunication.sendPublishedTopic(requestCmdJsonDisCharge, ferroampConfig); } if (FerroampBindingConstants.CHANNEL_AUTO.equals(channelUID.getId())) { String requestCmdJsonAuto = "{\"" + "transId" + "\":\"" + transId + "\",\"cmd\":{\"name\":\"auto\"}}"; - FerroampMqttCommunication.sendMQTT(requestCmdJsonAuto, ferroampConfig); + FerroampMqttCommunication.sendPublishedTopic(requestCmdJsonAuto, ferroampConfig); } } @@ -95,26 +95,26 @@ public class FerroampHandler extends BaseThingHandler implements MqttMessageSubs final MqttBrokerConnection ferroampConnection = new MqttBrokerConnection(ferroampConfig.hostName, FerroampBindingConstants.BROKER_PORT, false, false, ferroampConfig.userName); - scheduler.execute(() -> { - try { - startMqttConnection(); - } catch (InterruptedException e) { - logger.debug("Faulty startMqttConnection()"); - } - }); - scheduler.scheduleWithFixedDelay(this::pollTask, 60, refreshInterval, TimeUnit.SECONDS); this.setFerroampConnection(ferroampConnection); } private void pollTask() { + try { + startMqttConnection(); + } catch (InterruptedException e) { + logger.debug("Problems with startMqttConnection()"); + } if (getFerroampConnection().connectionState().toString().equals("DISCONNECTED")) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); logger.debug("Problem connection to MqttBroker"); - } else { + // } else { + } + if (getFerroampConnection().connectionState().toString().equals("CONNECTED")) { try { channelUpdate(); updateStatus(ThingStatus.ONLINE); + } catch (RuntimeException scheduleWithFixedDelayException) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, scheduleWithFixedDelayException.getClass().getName() + ":" @@ -124,15 +124,15 @@ public class FerroampHandler extends BaseThingHandler implements MqttMessageSubs } private void startMqttConnection() throws InterruptedException { - try { - TimeUnit.SECONDS.sleep(10); - } catch (InterruptedException e) { - logger.debug("Connection to MqttBroker disturbed during startup of MqttConnection"); - } - ferroampMqttCommunication.getMQTT("ehubTopic", ferroampConfig); - ferroampMqttCommunication.getMQTT("ssoTopic", ferroampConfig); - ferroampMqttCommunication.getMQTT("esoTopic", ferroampConfig); - ferroampMqttCommunication.getMQTT("esmTopic", ferroampConfig); + MqttBrokerConnection localSubscribeConnection = FerroampHandler.getFerroampConnection(); + + localSubscribeConnection.start(); + localSubscribeConnection.setCredentials(ferroampConfig.userName, ferroampConfig.password); + + ferroampMqttCommunication.getSubscribedTopic("ehubTopic", ferroampConfig); + ferroampMqttCommunication.getSubscribedTopic("ssoTopic", ferroampConfig); + ferroampMqttCommunication.getSubscribedTopic("esoTopic", ferroampConfig); + ferroampMqttCommunication.getSubscribedTopic("esmTopic", ferroampConfig); } private void channelUpdate() { diff --git a/bundles/org.openhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampMqttCommunication.java b/bundles/org.openhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampMqttCommunication.java index 5c6acc0fb93..c99880494f3 100644 --- a/bundles/org.openhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampMqttCommunication.java +++ b/bundles/org.openhab.binding.ferroamp/src/main/java/org/openhab/binding/ferroamp/internal/FerroampMqttCommunication.java @@ -60,7 +60,7 @@ public class FerroampMqttCommunication implements MqttMessageSubscriber { } // Handles request topic - static void sendMQTT(String payload, FerroampConfiguration ferroampConfig) { + static void sendPublishedTopic(String payload, FerroampConfiguration ferroampConfig) { MqttBrokerConnection localConfigurationConnection = FerroampHandler.getFerroampConnection(); @@ -70,12 +70,12 @@ public class FerroampMqttCommunication implements MqttMessageSubscriber { } // Handles respective topic type - void getMQTT(String topic, FerroampConfiguration ferroampConfig) { + void getSubscribedTopic(String topic, FerroampConfiguration ferroampConfig) { MqttBrokerConnection localSubscribeConnection = FerroampHandler.getFerroampConnection(); - localSubscribeConnection.start(); - localSubscribeConnection.setCredentials(ferroampConfig.userName, ferroampConfig.password); + // localSubscribeConnection.start(); + // localSubscribeConnection.setCredentials(ferroampConfig.userName, ferroampConfig.password); if ("ehubTopic".equals(topic)) { localSubscribeConnection.subscribe(FerroampBindingConstants.EHUB_TOPIC, this);