Skip to content

Instantly share code, notes, and snippets.

@boozeman
Last active March 29, 2024 15:45
Show Gist options
  • Save boozeman/afbfbca734ae1641552754415a5c97e5 to your computer and use it in GitHub Desktop.
Save boozeman/afbfbca734ae1641552754415a5c97e5 to your computer and use it in GitHub Desktop.
ESP32C3 version of the P1Reader
# ESP32C3 (Seeed Studio XIAO) version of the P1 reader
# Look at https://github.com/psvanstrom/esphome-p1reader and get that p1reader.h from there
esphome:
includes:
- p1reader.h
name: esp32-p1reader
friendly_name: esp32-p1reader
platformio_options:
board_build.f_flash: 40000000L
board_build.flash_mode: dio
board_build.flash_size: 4MB
board_build.extra_flags:
- "-DARDUINO_USB_CDC_ON_BOOT=0"
esp32:
board: seeed_xiao_esp32c3
variant: ESP32C3
framework:
type: arduino
substitutions:
device_name: esp32_p1reader
friendly_name: ESP32 p1reader
# Enable logging
logger:
level: DEBUG
baud_rate: 0 # disable logging over uart
# Enable Home Assistant API
api:
encryption:
# Generate API-key: https://esphome.io/components/api.html?highlight=randomly%20generated"
key: ""
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32-P1Reader Fallback Hotspot"
password: "lmQC8tD9B34e"
uart:
id: uart_bus
rx_pin:
number: 20
inverted: true
baud_rate: 115200
sensor:
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "${friendly_name} WiFi Signal dB"
id: ${device_name}_wifi_signal_db
update_interval: 60s
entity_category: "diagnostic"
# Uptime sensor.
- platform: uptime
name: ${friendly_name} Uptime
icon: mdi:clock-outline
id: ${device_name}_uptime
entity_category: "diagnostic"
# If your electricity meter is an Aidon, which use the older
# Branschstandard (1.2) where the data is HDLC-formatted
# Change the first line after lambda to
# auto_meter_sensor = new P1ReaderHDLC(id(uart_bus));
# else
# auto meter_sensor = new P1Reader(id(uart_bus));
- platform: custom
lambda: |-
auto meter_sensor = new P1Reader(id(uart_bus));
App.register_component(meter_sensor);
return {
meter_sensor->cumulativeActiveImport,
meter_sensor->cumulativeActiveExport,
meter_sensor->cumulativeReactiveImport,
meter_sensor->cumulativeReactiveExport,
meter_sensor->momentaryActiveImport,
meter_sensor->momentaryActiveExport,
meter_sensor->momentaryReactiveImport,
meter_sensor->momentaryReactiveExport,
meter_sensor->momentaryActiveImportL1,
meter_sensor->momentaryActiveExportL1,
meter_sensor->momentaryActiveImportL2,
meter_sensor->momentaryActiveExportL2,
meter_sensor->momentaryActiveImportL3,
meter_sensor->momentaryActiveExportL3,
meter_sensor->momentaryReactiveImportL1,
meter_sensor->momentaryReactiveExportL1,
meter_sensor->momentaryReactiveImportL2,
meter_sensor->momentaryReactiveExportL2,
meter_sensor->momentaryReactiveImportL3,
meter_sensor->momentaryReactiveExportL3,
meter_sensor->voltageL1,
meter_sensor->voltageL2,
meter_sensor->voltageL3,
meter_sensor->currentL1,
meter_sensor->currentL2,
meter_sensor->currentL3
};
sensors:
- name: "Cumulative Active Import"
unit_of_measurement: kWh
accuracy_decimals: 3
state_class: "total_increasing"
device_class: "energy"
- name: "Cumulative Active Export"
unit_of_measurement: kWh
accuracy_decimals: 3
state_class: "total_increasing"
device_class: "energy"
- name: "Cumulative Reactive Import"
unit_of_measurement: kvarh
accuracy_decimals: 3
- name: "Cumulative Reactive Export"
unit_of_measurement: kvarh
accuracy_decimals: 3
- name: "Momentary Active Import"
unit_of_measurement: kW
accuracy_decimals: 3
- name: "Momentary Active Export"
unit_of_measurement: kW
accuracy_decimals: 3
- name: "Momentary Reactive Import"
unit_of_measurement: kvar
accuracy_decimals: 3
- name: "Momentary Reactive Export"
unit_of_measurement: kvar
accuracy_decimals: 3
- name: "Momentary Active Import Phase 1"
unit_of_measurement: kW
accuracy_decimals: 3
- name: "Momentary Active Export Phase 1"
unit_of_measurement: kW
accuracy_decimals: 3
- name: "Momentary Active Import Phase 2"
unit_of_measurement: kW
accuracy_decimals: 3
- name: "Momentary Active Export Phase 2"
unit_of_measurement: kW
accuracy_decimals: 3
- name: "Momentary Active Import Phase 3"
unit_of_measurement: kW
accuracy_decimals: 3
- name: "Momentary Active Export Phase 3"
unit_of_measurement: kW
accuracy_decimals: 3
- name: "Momentary Reactive Import Phase 1"
unit_of_measurement: kvar
accuracy_decimals: 3
- name: "Momentary Reactive Export Phase 1"
unit_of_measurement: kvar
accuracy_decimals: 3
- name: "Momentary Reactive Import Phase 2"
unit_of_measurement: kvar
accuracy_decimals: 3
- name: "Momentary Reactive Export Phase 2"
unit_of_measurement: kvar
accuracy_decimals: 3
- name: "Momentary Reactive Import Phase 3"
unit_of_measurement: kvar
accuracy_decimals: 3
- name: "Momentary Reactive Export Phase 3"
unit_of_measurement: kvar
accuracy_decimals: 3
- name: "Voltage Phase 1"
unit_of_measurement: V
accuracy_decimals: 3
- name: "Voltage Phase 2"
unit_of_measurement: V
accuracy_decimals: 3
- name: "Voltage Phase 3"
unit_of_measurement: V
accuracy_decimals: 3
- name: "Current Phase 1"
unit_of_measurement: A
accuracy_decimals: 3
- name: "Current Phase 2"
unit_of_measurement: A
accuracy_decimals: 3
- name: "Current Phase 3"
unit_of_measurement: A
accuracy_decimals: 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment