Skip to content

Commit

Permalink
Added new channel waterconsumption_since_midnight that sums todays wa…
Browse files Browse the repository at this point in the history
…ter consumption (same as in the Grohe app)
  • Loading branch information
seime committed Jan 2, 2022
1 parent fb506cb commit 15782ae
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
15 changes: 8 additions & 7 deletions bundles/org.openhab.binding.groheondus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ and the `locationId`. Once the account bridge is configured, the appliances in y

##### senseguard

| Channel | Type | Description |
|--------------------------|--------------------------|-------------------------------------------------------|
| name | String | The name of the appliance |
| pressure | Number:Pressure | The pressure of your water supply |
| temperature_guard | Number:Temperature | The ambient temperature of the appliance |
| valve_open | Switch | Valve switch |
| waterconsumption | Number | The amount of water used in a specific timeframe |
| Channel | Type | Description |
|---------------------------------|--------------------------|--------------------------------------------------|
| name | String | The name of the appliance |
| pressure | Number:Pressure | The pressure of your water supply |
| temperature_guard | Number:Temperature | The ambient temperature of the appliance |
| valve_open | Switch | Valve switch |
| waterconsumption | Number | The amount of water used in a specific timeframe |
| waterconsumption_since_midnight | Number | The amount of water used since midnight |

##### sense

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class GroheOndusBindingConstants {
public static final String CHANNEL_TEMPERATURE_GUARD = "temperature_guard";
public static final String CHANNEL_VALVE_OPEN = "valve_open";
public static final String CHANNEL_WATERCONSUMPTION = "waterconsumption";
public static final String CHANNEL_WATERCONSUMPTION_SINCE_MIDNIGHT = "waterconsumption_since_midnight";
public static final String CHANNEL_TEMPERATURE = "temperature";
public static final String CHANNEL_HUMIDITY = "humidity";
public static final String CHANNEL_BATTERY = "battery";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -95,6 +96,9 @@ protected void updateChannel(ChannelUID channelUID, Appliance appliance, Data da
case CHANNEL_WATERCONSUMPTION:
newState = sumWaterCosumption(dataPoint);
break;
case CHANNEL_WATERCONSUMPTION_SINCE_MIDNIGHT:
newState = sumWaterCosumptionSinceMidnight(dataPoint);
break;
default:
throw new IllegalArgumentException("Channel " + channelUID + " not supported.");
}
Expand All @@ -103,6 +107,19 @@ protected void updateChannel(ChannelUID channelUID, Appliance appliance, Data da
}
}

private State sumWaterCosumptionSinceMidnight(Data dataPoint) {
Instant start = Instant.now().truncatedTo(ChronoUnit.DAYS);
Instant end = start.plus(1, ChronoUnit.DAYS);

Date earliestWithdrawal = new Date(start.toEpochMilli());
Date latestWithdrawal = new Date(end.toEpochMilli());

Double waterConsumption = dataPoint.getWithdrawals().stream()
.filter(e -> e.starttime.after(earliestWithdrawal) && e.starttime.before(latestWithdrawal))
.mapToDouble(withdrawal -> withdrawal.getWaterconsumption()).sum();
return new DecimalType(waterConsumption);
}

private DecimalType sumWaterCosumption(Data dataPoint) {
Double waterConsumption = dataPoint.getWithdrawals().stream()
.mapToDouble(withdrawal -> withdrawal.getWaterconsumption()).sum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<channel id="pressure" typeId="pressure"/>
<channel id="temperature_guard" typeId="temperature_guard"/>
<channel id="waterconsumption" typeId="waterconsumption"/>
<channel id="waterconsumption_since_midnight" typeId="waterconsumption_since_midnight"/>
<channel id="valve_open" typeId="valve_open"/>
</channels>

Expand Down Expand Up @@ -144,4 +145,10 @@
</parameter>
</config-description>
</channel-type>
<channel-type id="waterconsumption_since_midnight">
<item-type>Number</item-type>
<label>Water Consumption Since Midnight</label>
<description>The amount of water consumed since midnight</description>
<state readOnly="true"/>
</channel-type>
</thing:thing-descriptions>

0 comments on commit 15782ae

Please sign in to comment.