Skip to content

Commit 9b7d19b

Browse files
authored
[French Govt Energy Data] New binding (openhab#16713)
Signed-off-by: Gaël L'hopital <gael@lhopital.org> Signed-off-by: clinique <gael@lhopital.org>
1 parent 77bd3bf commit 9b7d19b

File tree

18 files changed

+788
-0
lines changed

18 files changed

+788
-0
lines changed

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
/bundles/org.openhab.binding.freebox/ @lolodomo
120120
/bundles/org.openhab.binding.freeboxos/ @clinique
121121
/bundles/org.openhab.binding.freecurrency/ @J-N-K
122+
/bundles/org.openhab.binding.frenchgovtenergydata/ @clinique
122123
/bundles/org.openhab.binding.fronius/ @trokohl
123124
/bundles/org.openhab.binding.fsinternetradio/ @paphko
124125
/bundles/org.openhab.binding.ftpupload/ @paulianttila

bom/openhab-addons/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@
586586
<artifactId>org.openhab.binding.freecurrency</artifactId>
587587
<version>${project.version}</version>
588588
</dependency>
589+
<dependency>
590+
<groupId>org.openhab.addons.bundles</groupId>
591+
<artifactId>org.openhab.binding.frenchgovtenergydata</artifactId>
592+
<version>${project.version}</version>
593+
</dependency>
589594
<dependency>
590595
<groupId>org.openhab.addons.bundles</groupId>
591596
<artifactId>org.openhab.binding.fronius</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This content is produced and maintained by the openHAB project.
2+
3+
* Project home: https://www.openhab.org
4+
5+
== Declared Project Licenses
6+
7+
This program and the accompanying materials are made available under the terms
8+
of the Eclipse Public License 2.0 which is available at
9+
https://www.eclipse.org/legal/epl-2.0/.
10+
11+
== Source Code
12+
13+
https://github.com/openhab/openhab-addons
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# French Government Energy Data Binding
2+
3+
This binding provides regulated electricity prices in France.
4+
5+
This can be used to plan energy consumption, for example to calculate the cheapest period for running a dishwasher or charging an EV.
6+
7+
## Supported Things
8+
9+
The binding offers things for the two usual tariff classes (proposed by example by EDF).
10+
11+
- `base`: This is the basic subscription with a fixed kWh price.
12+
- `hphc`: Alternative subscription offering variable price in a given hour set (low hours/high hours).
13+
14+
15+
## Thing Configuration
16+
17+
Things (both `base` and `hphc`) only offers the configuration of the power output of the electrical delivery point (Linky terminal).
18+
19+
| Name | Type | Description | Default | Required |
20+
|-----------------------|---------|---------------------------------------------|---------------|----------|
21+
| puissance | integer | PDL power output (in kVA) | 6 | no |
22+
23+
24+
## Channels
25+
26+
### `base` Tariff Thing
27+
28+
All channels are read-only.
29+
30+
| Channel | Type | Description | Advanced |
31+
|--------------|--------------------|-----------------------------------------|----------|
32+
| fixed-ttc | Number:Currency | Yearly fixed price including taxes | No |
33+
| variable-ttc | Number:EnergyPrice | Energy price in €/kWh including taxes | No |
34+
| tariff-start | DateTime | Beginning date for this tariff | Yes |
35+
| fixed-ht | Number:Currency | Yearly fixed price excluding taxes | Yes |
36+
| variable-ht | Number:EnergyPrice | Energy price in €/kWh excluding taxes | Yes |
37+
38+
39+
### `hphc` Tariff Thing
40+
41+
All channels are read-only.
42+
43+
| Channel | Type | Description | Advanced |
44+
|--------------|--------------------|----------------------------------------------------|----------|
45+
| fixed-ttc | Number:Currency | Yearly fixed price including taxes | No |
46+
| hc-ttc | Number:EnergyPrice | Low hours energy price in €/kWh including taxes | No |
47+
| hp-ttc | Number:EnergyPrice | High hours energy price in €/kWh including taxes | No |
48+
| tariff-start | DateTime | Beginning date for this tariff | Yes |
49+
| fixed-ht | Number:Currency | Yearly fixed price excluding taxes | Yes |
50+
| hc-ht | Number:EnergyPrice | Low hours energy price in €/kWh excluding taxes | Yes |
51+
| hp-ht | Number:EnergyPrice | High hours energy price in €/kWh excluding taxes | Yes |
52+
53+
54+
## Full Example
55+
56+
57+
### Thing Configuration
58+
59+
```java
60+
Thing frenchgovtenergydata:hphc:local "Tarification Actuelle HP/HC" [puissance=9]
61+
```
62+
63+
### Item Configuration
64+
65+
```java
66+
DateTime Tarif_Start { channel="frenchgovtenergydata:hphc:local:tariff-start" }
67+
Number:Currency Abonnement_Annuel {channel="frenchgovtenergydata:hphc:local:fixed-ttc"}
68+
Number:EnergyPrice Prix_Heure_Pleine {channel="frenchgovtenergydata:hphc:local:hp-ttc"}
69+
Number:EnergyPrice Prix_Heure_Creuse {channel="frenchgovtenergydata:hphc:local:hc-ttc"}
70+
```
71+
72+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.openhab.addons.bundles</groupId>
9+
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
10+
<version>4.2.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>org.openhab.binding.frenchgovtenergydata</artifactId>
14+
15+
<name>openHAB Add-ons :: Bundles :: French Government Energy Data Binding</name>
16+
17+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<features name="org.openhab.binding.frenchgovtenergydata-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
3+
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>
4+
5+
<feature name="openhab-binding-frenchgovtenergydata" description="French Government Energy Data Binding" version="${project.version}">
6+
<feature>openhab-runtime-base</feature>
7+
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.frenchgovtenergydata/${project.version}</bundle>
8+
</feature>
9+
</features>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2010-2024 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.frenchgovtenergydata.internal;
14+
15+
import java.util.Currency;
16+
17+
import org.eclipse.jdt.annotation.NonNullByDefault;
18+
import org.openhab.core.thing.ThingTypeUID;
19+
20+
/**
21+
* The {@link FrenchGovtEnergyDataBindingConstants} class defines common constants, which are
22+
* used across the whole binding.
23+
*
24+
* @author Gaël L'hopital - Initial contribution
25+
*/
26+
@NonNullByDefault
27+
public class FrenchGovtEnergyDataBindingConstants {
28+
29+
private static final String BINDING_ID = "frenchgovtenergydata";
30+
31+
// List of all Thing Type UIDs
32+
public static final ThingTypeUID THING_TYPE_BASE = new ThingTypeUID(BINDING_ID, "base");
33+
public static final ThingTypeUID THING_TYPE_HPHC = new ThingTypeUID(BINDING_ID, "hphc");
34+
35+
// List of all Channel ids
36+
public static final String CHANNEL_TARIFF_START = "tariff-start";
37+
public static final String CHANNEL_FIXED_HT = "fixed-ht";
38+
public static final String CHANNEL_FIXED_TTC = "fixed-ttc";
39+
public static final String CHANNEL_VARIABLE_HT = "variable-ht";
40+
public static final String CHANNEL_VARIABLE_TTC = "variable-ttc";
41+
public static final String CHANNEL_HC_HT = "hc-ht";
42+
public static final String CHANNEL_HC_TTC = "hc-ttc";
43+
public static final String CHANNEL_HP_HT = "hp-ht";
44+
public static final String CHANNEL_HP_TTC = "hp-ttc";
45+
46+
public static final Currency CURRENCY_EUR = Currency.getInstance("EUR");
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Copyright (c) 2010-2024 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.frenchgovtenergydata.internal;
14+
15+
import static org.openhab.binding.frenchgovtenergydata.internal.FrenchGovtEnergyDataBindingConstants.*;
16+
17+
import java.util.Set;
18+
19+
import org.eclipse.jdt.annotation.NonNullByDefault;
20+
import org.eclipse.jdt.annotation.Nullable;
21+
import org.openhab.binding.frenchgovtenergydata.internal.handler.BaseTariffHandler;
22+
import org.openhab.binding.frenchgovtenergydata.internal.handler.HpHcTariffHandler;
23+
import org.openhab.core.thing.Thing;
24+
import org.openhab.core.thing.ThingTypeUID;
25+
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
26+
import org.openhab.core.thing.binding.ThingHandler;
27+
import org.openhab.core.thing.binding.ThingHandlerFactory;
28+
import org.osgi.service.component.annotations.Component;
29+
30+
/**
31+
* The {@link FrenchGovtEnergyDataHandlerFactory} is responsible for creating things and thing handlers.
32+
*
33+
* @author Gaël L'hopital - Initial contribution
34+
*/
35+
@NonNullByDefault
36+
@Component(configurationPid = "binding.frenchgovtenergydata", service = ThingHandlerFactory.class)
37+
public class FrenchGovtEnergyDataHandlerFactory extends BaseThingHandlerFactory {
38+
39+
private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_BASE, THING_TYPE_HPHC);
40+
41+
@Override
42+
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
43+
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
44+
}
45+
46+
@Override
47+
protected @Nullable ThingHandler createHandler(Thing thing) {
48+
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
49+
50+
return THING_TYPE_BASE.equals(thingTypeUID) ? new BaseTariffHandler(thing)
51+
: THING_TYPE_HPHC.equals(thingTypeUID) ? new HpHcTariffHandler(thing) : null;
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) 2010-2024 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.frenchgovtenergydata.internal.dto;
14+
15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
17+
/**
18+
* The {@link BaseTariff} holds base price informations
19+
*
20+
* @author Gaël L'hopital - Initial contribution
21+
*/
22+
@NonNullByDefault
23+
public class BaseTariff extends Tariff {
24+
public final double variableHT;
25+
public final double variableTTC;
26+
27+
public BaseTariff(String line) {
28+
super(line, 7);
29+
try {
30+
this.variableHT = Double.parseDouble(values[5]);
31+
this.variableTTC = Double.parseDouble(values[6]);
32+
} catch (NumberFormatException e) {
33+
throw new IllegalArgumentException("Incorrect data in '%s'".formatted(line), e);
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright (c) 2010-2024 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.frenchgovtenergydata.internal.dto;
14+
15+
import org.eclipse.jdt.annotation.NonNullByDefault;
16+
17+
/**
18+
* The {@link HpHcTariff} holds HP-HC price informations
19+
*
20+
* @author Gaël L'hopital - Initial contribution
21+
*/
22+
@NonNullByDefault
23+
public class HpHcTariff extends Tariff {
24+
public final double hcHT;
25+
public final double hcTTC;
26+
public final double hpHT;
27+
public final double hpTTC;
28+
29+
public HpHcTariff(String line) {
30+
super(line, 9);
31+
try {
32+
this.hcHT = Double.parseDouble(values[5]);
33+
this.hcTTC = Double.parseDouble(values[6]);
34+
this.hpHT = Double.parseDouble(values[7]);
35+
this.hpTTC = Double.parseDouble(values[8]);
36+
} catch (NumberFormatException e) {
37+
throw new IllegalArgumentException("Incorrect data in '%s'".formatted(line), e);
38+
}
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (c) 2010-2024 Contributors to the openHAB project
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*/
13+
package org.openhab.binding.frenchgovtenergydata.internal.dto;
14+
15+
import java.time.LocalDate;
16+
import java.time.ZoneOffset;
17+
import java.time.ZonedDateTime;
18+
import java.time.format.DateTimeFormatter;
19+
import java.time.format.DateTimeParseException;
20+
21+
import org.eclipse.jdt.annotation.NonNullByDefault;
22+
import org.eclipse.jdt.annotation.Nullable;
23+
24+
/**
25+
* The {@link Tariff} is the base class holding common information for Tariffs
26+
*
27+
* @author Gaël L'hopital - Initial contribution
28+
*/
29+
@NonNullByDefault
30+
public class Tariff {
31+
protected static final DateTimeFormatter TARIFF_DATE_FORMAT = DateTimeFormatter.ofPattern("dd/MM/yyyy");
32+
33+
protected final String[] values;
34+
public final ZonedDateTime dateDebut;
35+
public final @Nullable ZonedDateTime dateFin;
36+
public final int puissance;
37+
public final double fixeHT;
38+
public final double fixeTTC;
39+
40+
public Tariff(String line, int lenControl) {
41+
this.values = line.replace(',', '.').split(";");
42+
if (values.length == lenControl) {
43+
try {
44+
this.dateDebut = LocalDate.parse(values[0], TARIFF_DATE_FORMAT).atStartOfDay(ZoneOffset.UTC);
45+
this.dateFin = !values[1].isEmpty()
46+
? LocalDate.parse(values[1], TARIFF_DATE_FORMAT).atStartOfDay(ZoneOffset.UTC)
47+
: null;
48+
this.puissance = Integer.parseInt(values[2]);
49+
this.fixeHT = Double.parseDouble(values[3]);
50+
this.fixeTTC = Double.parseDouble(values[4]);
51+
} catch (NumberFormatException | DateTimeParseException e) {
52+
throw new IllegalArgumentException("Incorrect data in '%s'".formatted(line), e);
53+
}
54+
} else {
55+
throw new IllegalArgumentException("Unexpected number of data, %d expected".formatted(lenControl));
56+
}
57+
}
58+
59+
public boolean isActive() {
60+
return dateFin == null;
61+
}
62+
}

0 commit comments

Comments
 (0)