[ferroamp] Binding for ferroamp 20241111

Changes done in:
FerroampHandler.java
FerroampMqttCommunication.java
README.md

Signed-off-by: Örjan Backsell <orjan.backsell@gmail.com>
This commit is contained in:
Örjan Backsell 2024-11-11 19:49:10 +01:00
parent 2cd249119a
commit 70688ede67
3 changed files with 38 additions and 39 deletions

View File

@ -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. 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. 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: *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 ```java
Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=false, ssoS0=true ] Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=true, eso=true ]
```
```java
Thing ferroamp:energyhub:myenergyhub [ hostName="energyhub-ip", userName="myUserName", password="myPassword", hasBattery=true, ssoS0=true, eso=true ]
``` ```
@ -226,20 +224,21 @@ String Ferroamp "RequestCharge" <energy> { channel="ferroamp:energyhub:myenergyh
## Rules ## 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 ```yaml
configuration: {}
triggers: triggers:
id: "1" - id: "1"
configuration: configuration:
cronExpression: 0 0/2 * * * ? * itemName: EnergyHub_RequestCharge
type: timer.GenericCronTrigger type: core.ItemStateUpdateTrigger
conditions: [] conditions: []
actions: actions:
inputs: {} - id: "2"
id: "2"
configuration: configuration:
type: application/vnd.openhab.dsl.rule itemName: EnergyHub_RequestCharge
script: ChargingWith5000W.sendCommand("5000") command: "5000"
type: script.ScriptAction type: core.ItemCommandAction
``` ```

View File

@ -68,16 +68,16 @@ public class FerroampHandler extends BaseThingHandler implements MqttMessageSubs
if (FerroampBindingConstants.CHANNEL_REQUESTCHARGE.equals(channelUID.getId())) { if (FerroampBindingConstants.CHANNEL_REQUESTCHARGE.equals(channelUID.getId())) {
String requestCmdJsonCharge = "{\"" + "transId" + "\":\"" + transId String requestCmdJsonCharge = "{\"" + "transId" + "\":\"" + transId
+ "\",\"cmd\":{\"name\":\"charge\",\"arg\":\"" + valueConfiguration + "\"}}"; + "\",\"cmd\":{\"name\":\"charge\",\"arg\":\"" + valueConfiguration + "\"}}";
FerroampMqttCommunication.sendMQTT(requestCmdJsonCharge, ferroampConfig); FerroampMqttCommunication.sendPublishedTopic(requestCmdJsonCharge, ferroampConfig);
} }
if (FerroampBindingConstants.CHANNEL_REQUESTDISCHARGE.equals(channelUID.getId())) { if (FerroampBindingConstants.CHANNEL_REQUESTDISCHARGE.equals(channelUID.getId())) {
String requestCmdJsonDisCharge = "{\"" + "transId" + "\":\"" + transId String requestCmdJsonDisCharge = "{\"" + "transId" + "\":\"" + transId
+ "\",\"cmd\":{\"name\":\"discharge\",\"arg\":\"" + valueConfiguration + "\"}}"; + "\",\"cmd\":{\"name\":\"discharge\",\"arg\":\"" + valueConfiguration + "\"}}";
FerroampMqttCommunication.sendMQTT(requestCmdJsonDisCharge, ferroampConfig); FerroampMqttCommunication.sendPublishedTopic(requestCmdJsonDisCharge, ferroampConfig);
} }
if (FerroampBindingConstants.CHANNEL_AUTO.equals(channelUID.getId())) { if (FerroampBindingConstants.CHANNEL_AUTO.equals(channelUID.getId())) {
String requestCmdJsonAuto = "{\"" + "transId" + "\":\"" + transId + "\",\"cmd\":{\"name\":\"auto\"}}"; 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, final MqttBrokerConnection ferroampConnection = new MqttBrokerConnection(ferroampConfig.hostName,
FerroampBindingConstants.BROKER_PORT, false, false, ferroampConfig.userName); 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); scheduler.scheduleWithFixedDelay(this::pollTask, 60, refreshInterval, TimeUnit.SECONDS);
this.setFerroampConnection(ferroampConnection); this.setFerroampConnection(ferroampConnection);
} }
private void pollTask() { private void pollTask() {
try {
startMqttConnection();
} catch (InterruptedException e) {
logger.debug("Problems with startMqttConnection()");
}
if (getFerroampConnection().connectionState().toString().equals("DISCONNECTED")) { if (getFerroampConnection().connectionState().toString().equals("DISCONNECTED")) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
logger.debug("Problem connection to MqttBroker"); logger.debug("Problem connection to MqttBroker");
} else { // } else {
}
if (getFerroampConnection().connectionState().toString().equals("CONNECTED")) {
try { try {
channelUpdate(); channelUpdate();
updateStatus(ThingStatus.ONLINE); updateStatus(ThingStatus.ONLINE);
} catch (RuntimeException scheduleWithFixedDelayException) { } catch (RuntimeException scheduleWithFixedDelayException) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
scheduleWithFixedDelayException.getClass().getName() + ":" scheduleWithFixedDelayException.getClass().getName() + ":"
@ -124,15 +124,15 @@ public class FerroampHandler extends BaseThingHandler implements MqttMessageSubs
} }
private void startMqttConnection() throws InterruptedException { private void startMqttConnection() throws InterruptedException {
try { MqttBrokerConnection localSubscribeConnection = FerroampHandler.getFerroampConnection();
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException e) { localSubscribeConnection.start();
logger.debug("Connection to MqttBroker disturbed during startup of MqttConnection"); localSubscribeConnection.setCredentials(ferroampConfig.userName, ferroampConfig.password);
}
ferroampMqttCommunication.getMQTT("ehubTopic", ferroampConfig); ferroampMqttCommunication.getSubscribedTopic("ehubTopic", ferroampConfig);
ferroampMqttCommunication.getMQTT("ssoTopic", ferroampConfig); ferroampMqttCommunication.getSubscribedTopic("ssoTopic", ferroampConfig);
ferroampMqttCommunication.getMQTT("esoTopic", ferroampConfig); ferroampMqttCommunication.getSubscribedTopic("esoTopic", ferroampConfig);
ferroampMqttCommunication.getMQTT("esmTopic", ferroampConfig); ferroampMqttCommunication.getSubscribedTopic("esmTopic", ferroampConfig);
} }
private void channelUpdate() { private void channelUpdate() {

View File

@ -60,7 +60,7 @@ public class FerroampMqttCommunication implements MqttMessageSubscriber {
} }
// Handles request topic // Handles request topic
static void sendMQTT(String payload, FerroampConfiguration ferroampConfig) { static void sendPublishedTopic(String payload, FerroampConfiguration ferroampConfig) {
MqttBrokerConnection localConfigurationConnection = FerroampHandler.getFerroampConnection(); MqttBrokerConnection localConfigurationConnection = FerroampHandler.getFerroampConnection();
@ -70,12 +70,12 @@ public class FerroampMqttCommunication implements MqttMessageSubscriber {
} }
// Handles respective topic type // Handles respective topic type
void getMQTT(String topic, FerroampConfiguration ferroampConfig) { void getSubscribedTopic(String topic, FerroampConfiguration ferroampConfig) {
MqttBrokerConnection localSubscribeConnection = FerroampHandler.getFerroampConnection(); MqttBrokerConnection localSubscribeConnection = FerroampHandler.getFerroampConnection();
localSubscribeConnection.start(); // localSubscribeConnection.start();
localSubscribeConnection.setCredentials(ferroampConfig.userName, ferroampConfig.password); // localSubscribeConnection.setCredentials(ferroampConfig.userName, ferroampConfig.password);
if ("ehubTopic".equals(topic)) { if ("ehubTopic".equals(topic)) {
localSubscribeConnection.subscribe(FerroampBindingConstants.EHUB_TOPIC, this); localSubscribeConnection.subscribe(FerroampBindingConstants.EHUB_TOPIC, this);