Skip to content

Commit

Permalink
Wifi power saving mode turned off. (Brunas#2)
Browse files Browse the repository at this point in the history
Added custom setting for float decimal digits and appropriate code to handle float/int/non-numeric values.

mqtt.yaml for HASS configuration.

Amended readme a bit
  • Loading branch information
Brunas authored Jan 5, 2024
1 parent af54d70 commit bd7e4b4
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 130 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Setting up your Arduino IDE:
- Write to your device via USB the first time, you can do it OTA all times thereafter.

### Circuit diagram
I have used the RX02 pin on the ESP32 to still use the USB port on devkit for debugging your ESP32. You could use any other pin however if you use standard RX and try debugging using USB, conflicts will happen.
I have used the RX02 pin on the ESP32 to still use the USB port on devkit for debugging your ESP32. You could use any other pin however if you use standard RX and try debugging using USB, conflicts will happen.
Connect the ESP32 to an RJ12 cable/connector following the diagram.

| P1 pin | ESP32 Pin |
Expand Down Expand Up @@ -148,6 +148,10 @@ p1_meter/sensor/magnitude_of_last_voltage_swell_in_phase_l3
All the metrics you need are easily added in `DSMR_MAP` variable in `dsmr_map.h` file. With the DEBUG mode it's possible to see all the topics you add/create in the serial monitor. Also, it's possible to configure topic structure by changing `MQTT_ROOT_TOPIC` value in `settings.h` file.
There is additional TEST mode to try your setup with test telegram and actual MQTT message send while your adapter is not connected to P1 port.
EMAIL_DEBUGGING is used to send debug messages to any email, e.g. GMail address. This is might be usefull to trace what's going on when device is connected to P1 port and actual debugging using USB port is impossible.

### Home Assistant Configuration

Use this [example](https://raw.githubusercontent.com/daniel-jong/esp8266_p1meter/master/assets/p1_sensors.yaml) for home assistant's `sensor.yaml`
Use this [example](assets/mqtt.yaml) for home assistant's `mqtt.yaml` which must be included in main `configuration.yaml` as follows:
```yaml
mqtt: !include mqtt.yaml
```
229 changes: 229 additions & 0 deletions assets/mqtt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
# Sensors for esp32_p1meter to be used in Home Assistant
# In configuration.yaml file add following line to make sensors appear in HA:
# mqtt: !include mqtt.yaml
sensor:
- name: P1 Meter Clock Raw
unique_id: p1_meter_clock_raw
state_topic: "p1_meter/sensor/clock"
icon: "mdi:clock"
- name: P1 Meter Clock Timestamp
unique_id: p1_meter_clock_timestamp
state_topic: "p1_meter/sensor/clock"
value_template: >
{{strptime(value | regex_findall_index("\d*"), '%y%m%d%H%M%S') | as_timestamp}}
- name: P1 Meter Clock Date and Time
unique_id: p1_meter_clock_datetime
state_topic: "p1_meter/sensor/clock"
value_template: >
{{strptime(value | regex_findall_index("\d*"), '%y%m%d%H%M%S')}}
- name: P1 Meter Active energy import (+A) rate 1
unique_id: p1_meter_active_energy_import_rate_1
state_topic: "p1_meter/sensor/active_energy_import_rate_1"
device_class: "energy"
state_class: "total_increasing"
unit_of_measurement: "kWh"
suggested_display_precision: 3
- name: P1 Meter Active energy import (+A) rate 2
unique_id: p1_meter_active_energy_import_rate_2
state_topic: "p1_meter/sensor/active_energy_import_rate_2"
device_class: "energy"
state_class: "total_increasing"
unit_of_measurement: "kWh"
suggested_display_precision: 3

- name: P1 Meter Active energy export (+A) rate 1
unique_id: p1_meter_active_energy_export_rate_1
state_topic: "p1_meter/sensor/active_energy_export_rate_1"
device_class: "energy"
state_class: "total_increasing"
unit_of_measurement: "kWh"
suggested_display_precision: 3
- name: P1 Meter Active energy export (+A) rate 2
unique_id: p1_meter_active_energy_export_rate_2
state_topic: "p1_meter/sensor/active_energy_export_rate_2"
device_class: "energy"
state_class: "total_increasing"
unit_of_measurement: "kWh"
suggested_display_precision: 3

- name: P1 Meter Instantaneous voltage L1
unique_id: p1_meter_instantaneous_voltage_l1
state_topic: "p1_meter/sensor/instantaneous_voltage_l1"
device_class: "voltage"
state_class: "measurement"
unit_of_measurement: "kV"
- name: P1 Meter Instantaneous current L1
unique_id: p1_meter_instantaneous_current_l1
state_topic: "p1_meter/sensor/instantaneous_current_l1"
device_class: "current"
state_class: "measurement"
unit_of_measurement: "kA"
- name: P1 Meter Instantaneous voltage L2
unique_id: p1_meter_instantaneous_voltage_l2
state_topic: "p1_meter/sensor/instantaneous_voltage_l2"
device_class: "voltage"
state_class: "measurement"
unit_of_measurement: "kV"
- name: P1 Meter Instantaneous current L2
unique_id: p1_meter_instantaneous_current_l2
state_topic: "p1_meter/sensor/instantaneous_current_l2"
device_class: "current"
state_class: "measurement"
unit_of_measurement: "kA"
- name: P1 Meter Instantaneous voltage L3
unique_id: p1_meter_instantaneous_voltage_l3
state_topic: "p1_meter/sensor/instantaneous_voltage_l3"
device_class: "voltage"
state_class: "measurement"
unit_of_measurement: "kV"
- name: P1 Meter Instantaneous current L3
unique_id: p1_meter_instantaneous_current_l3
state_topic: "p1_meter/sensor/instantaneous_current_l3"
device_class: "current"
state_class: "measurement"
unit_of_measurement: "kA"

- name: P1 Meter Instantaneous active power (|+A|+|-A|)
unique_id: p1_meter_instantaneous_active_power
state_topic: "p1_meter/sensor/instantaneous_active_power"
device_class: "power"
state_class: "measurement"
unit_of_measurement: "kW"

- name: P1 Meter Instantaneous active import power (+A) in phase L1
unique_id: p1_meter_instantaneous_active_import_power_in_phase_l1
state_topic: "p1_meter/sensor/instantaneous_active_import_power_in_phase_l1"
device_class: "power"
state_class: "measurement"
unit_of_measurement: "kW"
- name: P1 Meter Instantaneous active import power (+A) in phase L2
unique_id: p1_meter_instantaneous_active_import_power_in_phase_l2
state_topic: "p1_meter/sensor/instantaneous_active_import_power_in_phase_l2"
device_class: "power"
state_class: "measurement"
unit_of_measurement: "kW"
- name: P1 Meter Instantaneous active import power (+A) in phase L3
unique_id: p1_meter_instantaneous_active_import_power_in_phase_l3
state_topic: "p1_meter/sensor/instantaneous_active_import_power_in_phase_l3"
device_class: "power"
state_class: "measurement"
unit_of_measurement: "kW"

- name: P1 Meter Instantaneous active export power (-A) in phase L1
unique_id: p1_meter_instantaneous_active_export_power_in_phase_l1
state_topic: "p1_meter/sensor/instantaneous_active_export_power_in_phase_l1"
device_class: "power"
state_class: "measurement"
unit_of_measurement: "kW"
- name: P1 Meter Instantaneous active export power (-A) in phase L2
unique_id: p1_meter_instantaneous_active_export_power_in_phase_l2
state_topic: "p1_meter/sensor/instantaneous_active_export_power_in_phase_l2"
device_class: "power"
state_class: "measurement"
unit_of_measurement: "kW"
- name: P1 Meter Instantaneous active export power (-A) in phase L3
unique_id: p1_meter_instantaneous_active_export_power_in_phase_l3
state_topic: "p1_meter/sensor/instantaneous_active_export_power_in_phase_l3"
device_class: "power"
state_class: "measurement"
unit_of_measurement: "kW"

- name: P1 Meter Instantaneous apparent import power (+VA)
unique_id: p1_meter_instantaneous_apparent_import_power
state_topic: "p1_meter/sensor/instantaneous_apparent_import_power"
device_class: "apparent_power"
state_class: "measurement"
unit_of_measurement: "kVA"
- name: P1 Meter Instantaneous apparent import power (+VA) in phase L1
unique_id: p1_meter_instantaneous_apparent_import_power_in_phase_l1
state_topic: "p1_meter/sensor/instantaneous_apparent_import_power_in_phase_l1"
device_class: "apparent_power"
state_class: "measurement"
unit_of_measurement: "kVA"
- name: P1 Meter Instantaneous apparent import power (+VA) in phase L2
unique_id: p1_meter_instantaneous_apparent_import_power_in_phase_l2
state_topic: "p1_meter/sensor/instantaneous_apparent_import_power_in_phase_l2"
device_class: "apparent_power"
state_class: "measurement"
unit_of_measurement: "kVA"
- name: P1 Meter Instantaneous apparent import power (+VA) in phase L3
unique_id: p1_meter_instantaneous_apparent_import_power_in_phase_l3
state_topic: "p1_meter/sensor/instantaneous_apparent_import_power_in_phase_l3"
device_class: "apparent_power"
state_class: "measurement"
unit_of_measurement: "kVA"

- name: P1 Meter Instantaneous apparent export power (-VA)
unique_id: p1_meter_instantaneous_apparent_export_power
state_topic: "p1_meter/sensor/instantaneous_apparent_export_power"
device_class: "apparent_power"
state_class: "measurement"
unit_of_measurement: "kVA"
- name: P1 Meter Instantaneous apparent export power (-VA) in phase L1
unique_id: p1_meter_instantaneous_apparent_export_power_in_phase_l1
state_topic: "p1_meter/sensor/instantaneous_apparent_export_power_in_phase_l1"
device_class: "apparent_power"
state_class: "measurement"
unit_of_measurement: "kVA"
- name: P1 Meter Instantaneous apparent export power (-VA) in phase L2
unique_id: p1_meter_instantaneous_apparent_export_power_in_phase_l2
state_topic: "p1_meter/sensor/instantaneous_apparent_export_power_in_phase_l2"
device_class: "apparent_power"
state_class: "measurement"
unit_of_measurement: "kVA"
- name: P1 Meter Instantaneous apparent export power (-VA) in phase L3
unique_id: p1_meter_instantaneous_apparent_export_power_in_phase_l3
state_topic: "p1_meter/sensor/instantaneous_apparent_export_power_in_phase_l3"
device_class: "apparent_power"
state_class: "measurement"
unit_of_measurement: "kVA"

- name: P1 Meter Instantaneous Power factor (+A/+VA)
unique_id: p1_meter_instantaneous_power_factor
state_topic: "p1_meter/sensor/instantaneous_power_factor"
device_class: "power_factor"
state_class: "measurement"
- name: P1 Meter Instantaneous power factor in phase L1
unique_id: p1_meter_instantaneous_power_factor_in_phase_l1
state_topic: "p1_meter/sensor/instantaneous_power_factor_in_phase_l1"
device_class: "power_factor"
state_class: "measurement"
- name: P1 Meter Instantaneous power factor in phase L2
unique_id: p1_meter_instantaneous_power_factor_in_phase_l2
state_topic: "p1_meter/sensor/instantaneous_power_factor_in_phase_l2"
device_class: "power_factor"
state_class: "measurement"
- name: P1 Meter Instantaneous power factor in phase L3
unique_id: p1_meter_instantaneous_power_factor_in_phase_l3
state_topic: "p1_meter/sensor/instantaneous_power_factor_in_phase_l3"
device_class: "power_factor"
state_class: "measurement"
- name: P1 Meter Minimum Power factor (+A/+VA)
unique_id: p1_meter_minimum_power_factor
state_topic: "p1_meter/sensor/minimum_power_factor"
device_class: "power_factor"
state_class: "measurement"

- name: P1 Meter Number of power failures in any phase
unique_id: p1_meter_number_of_power_failures_in_any_phase
state_topic: "p1_meter/sensor/number_of_power_failures_in_any_phase"
state_class: "total_increasing"
- name: P1 Meter Duration of last voltage sag in phase L1
unique_id: p1_meter_duration_of_last_voltage_sag_in_phase_l1
state_topic: "p1_meter/sensor/duration_of_last_voltage_sag_in_phase_l1"
device_class: "duration"
state_class: "measurement"
unit_of_measurement: "s"
- name: P1 Meter Duration of last voltage sag in phase L2
unique_id: p1_meter_duration_of_last_voltage_sag_in_phase_l2
state_topic: "p1_meter/sensor/duration_of_last_voltage_sag_in_phase_l2"
device_class: "duration"
state_class: "measurement"
unit_of_measurement: "s"
- name: P1 Meter Duration of last voltage sag in phase L3
unique_id: p1_meter_duration_of_last_voltage_sag_in_phase_l3
state_topic: "p1_meter/sensor/duration_of_last_voltage_sag_in_phase_l3"
device_class: "duration"
state_class: "measurement"
unit_of_measurement: "s"
120 changes: 0 additions & 120 deletions assets/p1_sensors.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion esp32_p1meter.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <esp_wifi.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <ArduinoJson.h>
Expand Down Expand Up @@ -125,4 +126,4 @@ void setupOTA() {
ArduinoOTA.setHostname(String(HOSTNAME).c_str());
ArduinoOTA.setPasswordHash(String(OTA_PASSWORD_HASH).c_str());
ArduinoOTA.begin();
}
}
Loading

0 comments on commit bd7e4b4

Please sign in to comment.