From 254e35efddd393a263288cbbf4b9cabbaee45b0a Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Wed, 5 Jun 2024 00:28:13 -0700 Subject: [PATCH] Some more stubbed stuff. --- .../emporia_vue_utility.cpp | 26 ++++++++ .../emporia_vue_utility/emporia_vue_utility.h | 59 +++++++++++++++++++ .../components/emporia_vue_utility/sensor.py | 31 ++++++++++ 3 files changed, 116 insertions(+) create mode 100644 esphome/components/emporia_vue_utility/emporia_vue_utility.cpp create mode 100644 esphome/components/emporia_vue_utility/emporia_vue_utility.h create mode 100644 esphome/components/emporia_vue_utility/sensor.py diff --git a/esphome/components/emporia_vue_utility/emporia_vue_utility.cpp b/esphome/components/emporia_vue_utility/emporia_vue_utility.cpp new file mode 100644 index 0000000..7c692ec --- /dev/null +++ b/esphome/components/emporia_vue_utility/emporia_vue_utility.cpp @@ -0,0 +1,26 @@ +#include "esphome/core/log.h" +#include "emporia_vue_utility.h" + +namespace esphome { +namespace emporia_vue_utility { + +static const char *TAG = "emporia_vue_utility.sensor"; + +void EmporiaVueUtility::setup() { + +} + +void EmporiaVueUtility::update() { + +} + +void EmporiaVueUtility::loop() { + +} + +void EmporiaVueUtility::dump_config(){ + ESP_LOGCONFIG(TAG, "Stubbed Emporia Vue Utility"); +} + +} // namespace emporia_vue_utility +} // namespace esphome \ No newline at end of file diff --git a/esphome/components/emporia_vue_utility/emporia_vue_utility.h b/esphome/components/emporia_vue_utility/emporia_vue_utility.h new file mode 100644 index 0000000..bd4f324 --- /dev/null +++ b/esphome/components/emporia_vue_utility/emporia_vue_utility.h @@ -0,0 +1,59 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/sensor/sensor.h" +#include "esphome/components/uart/uart.h" + +// Extra meter reading response debugging +#define DEBUG_VUE_RESPONSE true + +// If the instant watts being consumed meter reading is outside of these ranges, +// the sample will be ignored which helps prevent garbage data from polluting +// home assistant graphs. Note this is the instant watts value, not the +// watt-hours value, which has smarter filtering. The defaults of 131kW +// should be fine for most people. (131072 = 0x20000) +#define WATTS_MIN -131072 +#define WATTS_MAX 131072 + +// How much the watt-hours consumed value can change between samples. +// Values that change by more than this over the avg value across the +// previous 5 samples will be discarded. +#define MAX_WH_CHANGE 2000 + +// How many samples to average the watt-hours value over. +#define MAX_WH_CHANGE_ARY 5 + +// How often to request a reading from the meter in seconds. +// Meters typically update the reported value only once every +// 10 to 30 seconds, so "5" is usually fine. +// You might try setting this to "1" to see if your meter has +// new values more often +#define METER_READING_INTERVAL 30 + +// How often to attempt to re-join the meter when it hasn't +// been returning readings +#define METER_REJOIN_INTERVAL 30 + +// On first startup, how long before trying to start to talk to meter +#define INITIAL_STARTUP_DELAY 10 + +// Should this code manage the "wifi" and "link" LEDs? +// set to false if you want manually manage them elsewhere +#define USE_LED_PINS true + +#define LED_PIN_LINK 32 +#define LED_PIN_WIFI 33 + +namespace esphome { +namespace emporia_vue_utility { + +class EmporiaVueUtility : public sensor::Sensor, public PollingComponent, public uart::UARTDevice { + public: + void setup() override; + void update() override; + void loop() override; + void dump_config() override; +}; + +} // namespace emporia_vue_utility +} // namespace esphome \ No newline at end of file diff --git a/esphome/components/emporia_vue_utility/sensor.py b/esphome/components/emporia_vue_utility/sensor.py new file mode 100644 index 0000000..b6f4583 --- /dev/null +++ b/esphome/components/emporia_vue_utility/sensor.py @@ -0,0 +1,31 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import uart, sensor +from esphome.const import CONF_ID, CONF_POWER + +DEPENDENCIES = ['uart'] + +emporia_vue_utility_ns = cg.esphome_ns.namespace('emporia_vue_utility') +EmporiaVueUtility = emporia_vue_utility_ns.class_('EmporiaVueUtility', cg.PollingComponent, uart.UARTDevice) + +CONFIG_SCHEMA = cv.All( + cv.Schema( + cv.GenerateID(): cv.declare_id(EmporiaVueUtility), + cv.Optional(CONF_POWER): sensor.sensor_schema( + unit_of_measurement=UNIT_WATT, + device_class=DEVICE_CLASS_POWER, + state_class=STATE_CLASS_MEASUREMENT, + accuracy_decimals=2, + ), + ) +) + +# sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 1).extend({ +# cv.GenerateID(): cv.declare_id(EmporiaVueUtility), +# }).extend(cv.polling_component_schema('60s')).extend(uart.UART_DEVICE_SCHEMA) + +# def to_code(config): +# var = cg.new_Pvariable(config[CONF_ID]) +# yield cg.register_component(var, config) +# yield sensor.register_sensor(var, config) +# yield uart.register_uart_device(var, config)