Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
.vscode/

# PlatformIo
.pio/
.pio/
.DS_Store
9 changes: 9 additions & 0 deletions assets/p1_sensors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@
state_topic: "sensors/power/p1meter/gas_meter_m3"
value_template: "{{ value|float / 1000 }}"

- platform: mqtt
name: P1 Actual Gas Consumption
unique_id: 'sensor.p1_actual_gas_consumption'
device_class: gas
state_class: measurement
unit_of_measurement: 'm³'
state_topic: "sensors/power/p1meter/actual_consumption_gas_m3"
value_template: "{{ value|float / 1000 }}"

- platform: mqtt
name: P1 Actual Tariff Group
unique_id: 'sensor.p1_actual_tariff_group'
Expand Down
39 changes: 35 additions & 4 deletions esp8266_p1meter/esp8266_p1meter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,24 @@ void send_metric(String name, long metric)

void send_data_to_broker()
{
send_metric("consumption_low_tarif", CONSUMPTION_LOW_TARIF);
send_metric("consumption_high_tarif", CONSUMPTION_HIGH_TARIF);
send_metric("returndelivery_low_tarif", RETURNDELIVERY_LOW_TARIF);
send_metric("returndelivery_high_tarif", RETURNDELIVERY_HIGH_TARIF);
if (FLIPHIGHLOWTARIF) {
send_metric("consumption_low_tarif", CONSUMPTION_HIGH_TARIF);
send_metric("consumption_high_tarif", CONSUMPTION_LOW_TARIF);
send_metric("returndelivery_low_tarif", RETURNDELIVERY_HIGH_TARIF);
send_metric("returndelivery_high_tarif", RETURNDELIVERY_LOW_TARIF);
if (ACTUAL_TARIF == 1)
{
ACTUAL_TARIF = 2;
} else {
ACTUAL_TARIF = 1;
}
} else {
send_metric("consumption_low_tarif", CONSUMPTION_LOW_TARIF);
send_metric("consumption_high_tarif", CONSUMPTION_HIGH_TARIF);
send_metric("returndelivery_low_tarif", RETURNDELIVERY_LOW_TARIF);
send_metric("returndelivery_high_tarif", RETURNDELIVERY_HIGH_TARIF);
}

send_metric("actual_consumption", ACTUAL_CONSUMPTION);
send_metric("actual_returndelivery", ACTUAL_RETURNDELIVERY);

Expand All @@ -147,6 +161,7 @@ void send_data_to_broker()
send_metric("l3_voltage", L3_VOLTAGE);

send_metric("gas_meter_m3", GAS_METER_M3);
send_metric("actual_consumption_gas_m3", ACTUAL_CONSUMPTION_GAS_M3);

send_metric("actual_tarif_group", ACTUAL_TARIF);
send_metric("short_power_outages", SHORT_POWER_OUTAGES);
Expand Down Expand Up @@ -373,6 +388,14 @@ bool decode_telegram(int len)
{
GAS_METER_M3 = getValue(telegram, len, '(', '*');
}


// 0-1:24.2.3(150531200000S)(00811.923*m3)
// 0-1:24.2.3 = Gas on Belgian meters
if (strncmp(telegram, "0-1:24.2.3", strlen("0-1:24.2.3")) == 0)
{
GAS_METER_M3 = getValue(telegram, len, '(', '*');
}

// 0-0:96.14.0(0001)
// 0-0:96.14.0 = Actual Tarif
Expand Down Expand Up @@ -436,6 +459,14 @@ void processLine(int len) {

bool result = decode_telegram(len + 1);
if (result) {
if (LAST_GAS_METER_M3 > 0) {
if (GAS_METER_M3 > LAST_GAS_METER_M3) {
ACTUAL_CONSUMPTION_GAS_M3 = GAS_METER_M3 - LAST_GAS_METER_M3;
}
} else {
ACTUAL_CONSUMPTION_GAS_M3 = 0;
}
LAST_GAS_METER_M3 = GAS_METER_M3;
send_data_to_broker();
LAST_UPDATE_SENT = millis();
}
Expand Down
5 changes: 5 additions & 0 deletions esp8266_p1meter/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
// * MQTT root topic
#define MQTT_ROOT_TOPIC "sensors/power/p1meter"

// * Belgian meters have flipped high and low tarif codes, this variable allows you to flip
#define FLIPHIGHLOWTARIF true

// * MQTT Last reconnection counter
long LAST_RECONNECT_ATTEMPT = 0;

Expand All @@ -56,6 +59,8 @@ long RETURNDELIVERY_HIGH_TARIF;
long ACTUAL_CONSUMPTION;
long ACTUAL_RETURNDELIVERY;
long GAS_METER_M3;
long ACTUAL_CONSUMPTION_GAS_M3;
long LAST_GAS_METER_M3;

long L1_INSTANT_POWER_USAGE;
long L2_INSTANT_POWER_USAGE;
Expand Down