From 3cffad99ddf69990739c1efaadae4202a6f8100c Mon Sep 17 00:00:00 2001 From: Chris Nussbaum Date: Sat, 14 Aug 2021 17:13:17 -0500 Subject: [PATCH] Energy monitoring updates (#14) * Update most everything to report power and energy to Home Assistant and Sense * ESPSense is pulled from GitHub Co-authored-by: Chris Nussbaum --- README.md | 3 + components/tuya_dimmer_as_fan/README.md | 9 ++- components/tuya_dimmer_as_fan/fan.py | 29 +++++++++- .../tuya_dimmer_as_fan/tuya_dimmer_as_fan.cpp | 6 ++ .../tuya_dimmer_as_fan/tuya_dimmer_as_fan.h | 7 ++- components/tuya_light_plus/README.md | 12 +++- components/tuya_light_plus/light.py | 24 +++++++- .../tuya_light_plus/tuya_light_plus.cpp | 6 ++ components/tuya_light_plus/tuya_light_plus.h | 4 ++ devices/basement_bathroom_light_fan.yaml | 34 +++++++++++ ...basement_bathroom_shower_light_heater.yaml | 56 +++++++++++++++++++ devices/basement_stair_lights_1.yaml | 4 ++ devices/basement_stair_lights_2.yaml | 2 +- devices/computer_light.yaml | 4 ++ devices/dining_room_light.yaml | 4 ++ devices/family_room_light.yaml | 4 ++ devices/front_entry_lights_1.yaml | 4 ++ devices/front_entry_lights_2.yaml | 2 +- devices/front_lights.yaml | 4 ++ devices/kitchen_bar_lights.yaml | 4 ++ devices/kitchen_table_light.yaml | 4 ++ devices/living_room_lights.yaml | 4 ++ devices/master_bath_fan.yaml | 1 + devices/master_bath_lights_1.yaml | 4 ++ devices/master_bath_lights_2.yaml | 2 +- devices/office_light.yaml | 4 ++ devices/patio_lights.yaml | 34 +++++++++++ ...lights.yaml => pool_and_patio_lights.yaml} | 34 +++++++++++ devices/pool_pumps.yaml | 28 ++++++++++ packages/feit_dimmer.yaml | 17 ++++++ packages/feit_dimmer_as_fan.yaml | 23 +++++++- packages/feit_dimmer_without_power.yaml | 16 ++++++ 32 files changed, 382 insertions(+), 11 deletions(-) rename devices/{patio_and_pool_lights.yaml => pool_and_patio_lights.yaml} (67%) create mode 100644 packages/feit_dimmer_without_power.yaml diff --git a/README.md b/README.md index 460f80f..f34e3eb 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ This an enhanced version of the standard [Tuya](https://esphome.io/components/li ### Tuya Dimmer as Fan This a modified version of the Tuya fan component I use with [Feit Dimmers](https://www.amazon.com/gp/product/B07SXDFH38/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1) (but it will likely work with other Tuya dimmers) to control bathroom fans. The major change from the standard Tuya fan component (other than removing options for speed, oscillation, and direction) is adding a function to always change the dimmer back to the maximum "brightness" effectively making this only an on/off device. Details on how to use this component are available [here](./components/tuya_dimmer_as_fan/README.md). +### ESPSense +This excellent component is not mine and doesn't live in this repository but most of my devices are using it so I felt it was worthy of a mention here. More details are available [here](https://github.com/cbpowell/ESPSense). + ## Misc Devices ### [Basement Bathroom Sensor](./devices/basement_bathroom_sensor.yaml) diff --git a/components/tuya_dimmer_as_fan/README.md b/components/tuya_dimmer_as_fan/README.md index f109241..b0caf2c 100644 --- a/components/tuya_dimmer_as_fan/README.md +++ b/components/tuya_dimmer_as_fan/README.md @@ -1,6 +1,6 @@ # Tuya Light Plus Component ## Overview -This a modified version of the Tuya fan component I use with [Feit Dimmers](https://www.amazon.com/gp/product/B07SXDFH38/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1) (but it will likely work with other Tuya dimmers) to control bathroom fans. The major change from the standard Tuya fan component (other than removing options for speed, oscillation, and direction) is adding a function to always change the dimmer back to the maximum "brightness" effectively making this only an on/off device. +This a modified version of the Tuya fan component I use with [Feit Dimmers](https://www.amazon.com/gp/product/B07SXDFH38/ref=ppx_yo_dt_b_asin_title_o02_s00?ie=UTF8&psc=1) (but it will likely work with other Tuya dimmers) to control bathroom fans. The major change from the standard Tuya fan component (other than removing options for speed, oscillation, and direction) is adding a function to always change the dimmer back to the maximum "brightness" effectively making this only an on/off device. Similar to the Tuya Light Plus component this component can also add a power sensor based on configured wattage of the fan, this could be done with a templat sensor and automations but it was easy to add here so I figured why not. ## Setup @@ -29,6 +29,10 @@ fan: switch_datapoint: 1 dimmer_datapoint: 2 dimmer_max_value: 1000 + power: + id: my_fan_power + name: My Fan Power + light_wattage: 21.6 ``` ## Configuration Variables @@ -37,3 +41,6 @@ fan: * switch_datapoint (Required, int): The datapoint id number of the power switch. * dimmer_datapoint (Required, int): The datapoint id number of the dimmer value. * dimmer_max_value (Optional, int, default 255): The highest dimmer value allowed. +* power.id (Optional, string) Manually specify the power sensor ID used for code generation. +* power.name (Optional, string) The name for the power sensor. +* power.fan_wattage (Optional, float) The total wattage of the fan(s) controled by this dimmer. diff --git a/components/tuya_dimmer_as_fan/fan.py b/components/tuya_dimmer_as_fan/fan.py index 9615737..a07b657 100644 --- a/components/tuya_dimmer_as_fan/fan.py +++ b/components/tuya_dimmer_as_fan/fan.py @@ -1,13 +1,22 @@ -from esphome.components import fan +from esphome.components import fan, sensor import esphome.config_validation as cv import esphome.codegen as cg -from esphome.const import CONF_OUTPUT_ID, CONF_SWITCH_DATAPOINT from esphome.components.tuya import CONF_TUYA_ID, Tuya +from esphome.const import ( + CONF_OUTPUT_ID, + CONF_SWITCH_DATAPOINT, + CONF_POWER, + UNIT_WATT, + DEVICE_CLASS_POWER, + STATE_CLASS_MEASUREMENT, + ICON_POWER, +) DEPENDENCIES = ["tuya"] CONF_DIMMER_DATAPOINT = "dimmer_datapoint" CONF_MAX_VALUE = "dimmer_max_value" +CONF_FAN_WATTAGE = "fan_wattage" tuya_ns = cg.esphome_ns.namespace("tuya") TuyaFan = tuya_ns.class_("TuyaDimmerAsFan", cg.Component) @@ -20,6 +29,17 @@ CONFIG_SCHEMA = cv.All( cv.Required(CONF_SWITCH_DATAPOINT): cv.uint8_t, cv.Required(CONF_DIMMER_DATAPOINT): cv.uint8_t, cv.Optional(CONF_MAX_VALUE): cv.int_, + cv.Optional(CONF_POWER): sensor.sensor_schema( + unit_of_measurement_=UNIT_WATT, + accuracy_decimals_=1, + device_class_=DEVICE_CLASS_POWER, + state_class_=STATE_CLASS_MEASUREMENT, + icon_=ICON_POWER, + ).extend( + { + cv.Optional(CONF_FAN_WATTAGE): cv.positive_float, + } + ), } ).extend(cv.COMPONENT_SCHEMA), ) @@ -38,3 +58,8 @@ async def to_code(config): cg.add(var.set_dimmer_id(config[CONF_DIMMER_DATAPOINT])) if CONF_MAX_VALUE in config: cg.add(var.set_dimmer_max_value(config[CONF_MAX_VALUE])) + if CONF_POWER in config: + power_config = config[CONF_POWER] + power_sensor = await sensor.new_sensor(power_config) + cg.add(var.set_fan_wattage(power_config[CONF_FAN_WATTAGE])) + cg.add(var.set_power_sensor(power_sensor)) diff --git a/components/tuya_dimmer_as_fan/tuya_dimmer_as_fan.cpp b/components/tuya_dimmer_as_fan/tuya_dimmer_as_fan.cpp index 4891735..ac247ca 100644 --- a/components/tuya_dimmer_as_fan/tuya_dimmer_as_fan.cpp +++ b/components/tuya_dimmer_as_fan/tuya_dimmer_as_fan.cpp @@ -15,6 +15,12 @@ void TuyaDimmerAsFan::setup() { auto call = this->fan_->make_call(); call.set_state(datapoint.value_bool); call.perform(); + + if (this->fan_wattage_.has_value() && this->power_sensor_ != nullptr) + { + float power = datapoint.value_bool ? this->fan_wattage_.value() : 0.0f; + this->power_sensor_->publish_state(power); + } }); this->parent_->register_listener(*this->dimmer_id_, [this](const TuyaDatapoint &datapoint) { diff --git a/components/tuya_dimmer_as_fan/tuya_dimmer_as_fan.h b/components/tuya_dimmer_as_fan/tuya_dimmer_as_fan.h index fd32148..055816f 100644 --- a/components/tuya_dimmer_as_fan/tuya_dimmer_as_fan.h +++ b/components/tuya_dimmer_as_fan/tuya_dimmer_as_fan.h @@ -1,8 +1,9 @@ #pragma once #include "esphome/core/component.h" -#include "esphome/components/tuya/tuya.h" #include "esphome/components/fan/fan_state.h" +#include "esphome/components/sensor/sensor.h" +#include "esphome/components/tuya/tuya.h" namespace esphome { namespace tuya { @@ -15,6 +16,8 @@ class TuyaDimmerAsFan : public Component { void set_switch_id(uint8_t switch_id) { this->switch_id_ = switch_id; } void set_dimmer_id(uint8_t dimmer_id) { this->dimmer_id_ = dimmer_id; } void set_dimmer_max_value(uint32_t max_value) { this->dimmer_max_value_ = max_value; } + void set_fan_wattage(float fan_wattage) { this->fan_wattage_ = fan_wattage; } + void set_power_sensor(sensor::Sensor *power_sensor) { this->power_sensor_ = power_sensor; } protected: Tuya *parent_; @@ -22,6 +25,8 @@ class TuyaDimmerAsFan : public Component { optional dimmer_id_{}; uint32_t dimmer_max_value_ = 255; fan::FanState *fan_; + optional fan_wattage_{}; + sensor::Sensor *power_sensor_; }; } // namespace tuya diff --git a/components/tuya_light_plus/README.md b/components/tuya_light_plus/README.md index 7e1b1b4..eff5745 100644 --- a/components/tuya_light_plus/README.md +++ b/components/tuya_light_plus/README.md @@ -11,6 +11,7 @@ This an enhanced version of the standard Tuya light component that adds a bunch * Double clicking the dimmer while off can be configured to leave the light in an off or on state. * Adds an option to configure action(s) to run when the dimmer is double clicked while on (this double click always turns the light off otherwise you get strange flash when double clicking). * Allows you to "link" other light(s) in Home Assistant that will be controlled by this dimmer (on/off and level). +* Can add a sensor to report current power usage based on a configured wattage of the lights it controls. Currently this reports the specified wattage regardless of the dimmer level (my lights run at the max level 95% of the time so for me this is pretty accurate). Eventually I want to determine approximately what the dimmer level to power reduction ratio is so that it can more accurately report the power. ## Setup @@ -35,7 +36,7 @@ Add and configure the Tuya Light Plus component ```yaml light: - platform: tuya_light_plus - name: my_dimmer + name: My Light switch_datapoint: 1 dimmer_datapoint: 2 max_value: 1000 @@ -55,6 +56,11 @@ light: double_click_while_off_stays_off: false on_double_click_while_on: - script.execute: double_click + power: + id: my_light_power + name: My Light Power + light_wattage: 21.6 + ``` ## Configuration Variables @@ -79,7 +85,9 @@ light: * on_double_click_while_off (Optional): List of actions to run when the dimmer is double clicked while off * double_click_while_off_stays_off (Optional, bool, default: true): Determines if the light remains off or turns on after a double click while off * on_double_click_while_on (Optional): List of actions to run when the dimmer is double clicked while on - +* power.id (Optional, string) Manually specify the power sensor ID used for code generation. +* power.name (Optional, string) The name for the power sensor +* power.light_wattage (Optional, float) The total wattage of the light(s) controled by this dimmer ## Operation This component adds 2 services to Home Assistant that can be used to update the settings of the dimmer: diff --git a/components/tuya_light_plus/light.py b/components/tuya_light_plus/light.py index d7f4399..8ae87a2 100644 --- a/components/tuya_light_plus/light.py +++ b/components/tuya_light_plus/light.py @@ -1,6 +1,6 @@ from typing import Optional from esphome import core -from esphome.components import light +from esphome.components import light, sensor import esphome.config_validation as cv import esphome.automation as auto import esphome.codegen as cg @@ -12,6 +12,11 @@ from esphome.const import ( CONF_DEFAULT_TRANSITION_LENGTH, CONF_SWITCH_DATAPOINT, CONF_SENSOR_ID, + CONF_POWER, + UNIT_WATT, + DEVICE_CLASS_POWER, + STATE_CLASS_MEASUREMENT, + ICON_POWER, ) from esphome.components.tuya import CONF_TUYA_ID, Tuya @@ -33,6 +38,7 @@ CONF_NIGHT_AUTO_OFF_TIME = "night_auto_off_time" CONF_ON_DOUBLE_CLICK_WHILE_OFF = "on_double_click_while_off" CONF_DOUBLE_CLICK_WHILE_OFF_STAYS_OFF = "double_click_while_off_stays_off" CONF_ON_DOUBLE_CLICK_WHILE_ON = "on_double_click_while_on" +CONF_LIGHT_WATTAGE = "light_wattage" tuya_ns = cg.esphome_ns.namespace("tuya") api_ns = cg.esphome_ns.namespace("api") @@ -89,6 +95,17 @@ CONFIG_SCHEMA = cv.All( cv.Optional( CONF_DEFAULT_TRANSITION_LENGTH, default="0s" ): cv.positive_time_period_milliseconds, + cv.Optional(CONF_POWER): sensor.sensor_schema( + unit_of_measurement_=UNIT_WATT, + accuracy_decimals_=1, + device_class_=DEVICE_CLASS_POWER, + state_class_=STATE_CLASS_MEASUREMENT, + icon_=ICON_POWER, + ).extend( + { + cv.Optional(CONF_LIGHT_WATTAGE): cv.positive_float, + } + ), } ).extend(cv.COMPONENT_SCHEMA), ) @@ -144,5 +161,10 @@ async def to_code(config): for conf in config.get(CONF_ON_DOUBLE_CLICK_WHILE_ON, []): trigger = cg.new_Pvariable(conf[CONF_ON_DOUBLE_CLICK_WHILE_ON], var) await auto.build_automation(trigger, [], conf) + if CONF_POWER in config: + power_config = config[CONF_POWER] + power_sensor = await sensor.new_sensor(power_config) + cg.add(var.set_light_wattage(power_config[CONF_LIGHT_WATTAGE])) + cg.add(var.set_power_sensor(power_sensor)) paren = await cg.get_variable(config[CONF_TUYA_ID]) cg.add(var.set_tuya_parent(paren)) diff --git a/components/tuya_light_plus/tuya_light_plus.cpp b/components/tuya_light_plus/tuya_light_plus.cpp index 64d4742..57febfc 100644 --- a/components/tuya_light_plus/tuya_light_plus.cpp +++ b/components/tuya_light_plus/tuya_light_plus.cpp @@ -239,6 +239,12 @@ void TuyaLightPlus::handle_tuya_datapoint_(tuya::TuyaDatapoint datapoint) }); } } + + if (this->light_wattage_.has_value() && this->power_sensor_ != nullptr) + { + float power = this->state_->current_values.is_on() ? this->light_wattage_.value() : 0.0f; + this->power_sensor_->publish_state(power); + } } void TuyaLightPlus::on_day_night_changed_(std::string state) diff --git a/components/tuya_light_plus/tuya_light_plus.h b/components/tuya_light_plus/tuya_light_plus.h index 1655db9..a843ce0 100644 --- a/components/tuya_light_plus/tuya_light_plus.h +++ b/components/tuya_light_plus/tuya_light_plus.h @@ -23,6 +23,8 @@ class TuyaLightPlus : public Component, public light::LightOutput, public api::C void set_tuya_parent(Tuya *parent) { this->parent_ = parent; } void set_min_value(uint32_t min_value) { this->min_value_ = min_value; } void set_max_value(uint32_t max_value) { this->max_value_ = max_value; } + void set_light_wattage(float light_wattage) { this->light_wattage_ = light_wattage; } + void set_power_sensor(sensor::Sensor *power_sensor) { this->power_sensor_ = power_sensor; } light::LightTraits get_traits() override; void setup_state(light::LightState *state) override; void write_state(light::LightState *state) override; @@ -71,6 +73,8 @@ class TuyaLightPlus : public Component, public light::LightOutput, public api::C optional night_default_brightness_{}; optional day_auto_off_time_{}; optional night_auto_off_time_{}; + optional light_wattage_{}; + sensor::Sensor *power_sensor_; CallbackManager double_click_while_off_callback_{}; CallbackManager double_click_while_on_callback_{}; bool has_double_click_while_off_{false}; diff --git a/devices/basement_bathroom_light_fan.yaml b/devices/basement_bathroom_light_fan.yaml index fc7b6ba..9f7f769 100644 --- a/devices/basement_bathroom_light_fan.yaml +++ b/devices/basement_bathroom_light_fan.yaml @@ -11,6 +11,10 @@ substitutions: packages: device_base: !include ../packages/device_base.yaml +external_components: + - source: github://cbpowell/ESPSense + components: [ espsense ] + binary_sensor: - platform: gpio id: light_button @@ -29,6 +33,12 @@ binary_sensor: then: - fan.toggle: the_fan +espsense: + plugs: + - name: Basement Bathroom Light + power_sensor: light_power + voltage: 120 + fan: - platform: binary id: the_fan @@ -40,6 +50,14 @@ light: id: the_light name: "Basement Bathroom Light" output: light_output + on_turn_on: + - sensor.template.publish: + id: light_power + state: 48.0 + on_turn_off: + - sensor.template.publish: + id: light_power + state: 0.0 output: - platform: gpio @@ -53,3 +71,19 @@ status_led: pin: number: 0 inverted: true + +sensor: + - platform: template + name: Basement Bathroom Light Power + id: light_power + unit_of_measurement: W + device_class: power + state_class: measurement + accuracy_decimals: 1 + - platform: total_daily_energy + name: Basement Bathroom Light + power_id: light_power + state_class: measurement + +time: + - platform: homeassistant diff --git a/devices/basement_bathroom_shower_light_heater.yaml b/devices/basement_bathroom_shower_light_heater.yaml index 80056c0..5c08378 100644 --- a/devices/basement_bathroom_shower_light_heater.yaml +++ b/devices/basement_bathroom_shower_light_heater.yaml @@ -11,6 +11,10 @@ substitutions: packages: device_base: !include ../packages/device_base.yaml +external_components: + - source: github://cbpowell/ESPSense + components: [ espsense ] + binary_sensor: - platform: gpio id: light_button @@ -29,11 +33,28 @@ binary_sensor: then: - switch.toggle: heater +espsense: + plugs: + - name: Basement Bathroom Shower Light + power_sensor: light_power + voltage: 120 + - name: Basement Bathroom Heater + power_sensor: heat_power + voltage: 120 + light: - platform: binary id: the_light name: "Basement Shower Light" output: light_output + on_turn_on: + - sensor.template.publish: + id: light_power + state: 11.5 + on_turn_off: + - sensor.template.publish: + id: light_power + state: 0.0 output: - platform: gpio @@ -51,3 +72,38 @@ switch: name: "Basement Bathroom Heater" icon: mdi:radiator pin: 4 + on_turn_on: + - sensor.template.publish: + id: heat_power + state: 500 + on_turn_off: + - sensor.template.publish: + id: heat_power + state: 0.0 + +sensor: + - platform: template + name: Basement Bathroom Shower Light + id: light_power + unit_of_measurement: W + device_class: power + state_class: measurement + accuracy_decimals: 1 + - platform: template + name: Basement Bathroom Heater + id: heat_power + unit_of_measurement: W + device_class: power + state_class: measurement + accuracy_decimals: 1 + - platform: total_daily_energy + name: Basement Bathroom Shower Light + power_id: light_power + state_class: measurement + - platform: total_daily_energy + name: Basement Bathroom Heater + power_id: heat_power + state_class: measurement + +time: + - platform: homeassistant diff --git a/devices/basement_stair_lights_1.yaml b/devices/basement_stair_lights_1.yaml index 940262a..54291e9 100644 --- a/devices/basement_stair_lights_1.yaml +++ b/devices/basement_stair_lights_1.yaml @@ -40,3 +40,7 @@ light: double_click_while_off_stays_off: true on_double_click_while_on: - script.execute: double_click + power: + id: power + name: ${device_name} Power + light_wattage: 21.6 diff --git a/devices/basement_stair_lights_2.yaml b/devices/basement_stair_lights_2.yaml index 1f6fb91..96ebf47 100644 --- a/devices/basement_stair_lights_2.yaml +++ b/devices/basement_stair_lights_2.yaml @@ -15,7 +15,7 @@ script: entity_id: switch.basement_tv, switch.xbox, light.basement_tv, light.basement, light.bar, switch.pool_table_light, light.basement_bathroom_light, light.basement_shower_light packages: - feit_dimmer: !include ../packages/feit_dimmer.yaml + feit_dimmer: !include ../packages/feit_dimmer_without_power.yaml light: - platform: tuya_light_plus diff --git a/devices/computer_light.yaml b/devices/computer_light.yaml index eb3e781..d700a0c 100644 --- a/devices/computer_light.yaml +++ b/devices/computer_light.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 11.8 diff --git a/devices/dining_room_light.yaml b/devices/dining_room_light.yaml index a3430e9..18c9d6e 100644 --- a/devices/dining_room_light.yaml +++ b/devices/dining_room_light.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 22.6 diff --git a/devices/family_room_light.yaml b/devices/family_room_light.yaml index db98bed..dfea840 100644 --- a/devices/family_room_light.yaml +++ b/devices/family_room_light.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 21.6 diff --git a/devices/front_entry_lights_1.yaml b/devices/front_entry_lights_1.yaml index 59e2d83..84aed74 100644 --- a/devices/front_entry_lights_1.yaml +++ b/devices/front_entry_lights_1.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 33.8 diff --git a/devices/front_entry_lights_2.yaml b/devices/front_entry_lights_2.yaml index 867f79a..16ec722 100644 --- a/devices/front_entry_lights_2.yaml +++ b/devices/front_entry_lights_2.yaml @@ -7,7 +7,7 @@ substitutions: ap_wifi_pwd: !secret front_entry_lights_2_ap_wifi_pwd packages: - feit_dimmer: !include ../packages/feit_dimmer.yaml + feit_dimmer: !include ../packages/feit_dimmer_without_power.yaml light: - platform: tuya_light_plus diff --git a/devices/front_lights.yaml b/devices/front_lights.yaml index 1260cea..588f298 100644 --- a/devices/front_lights.yaml +++ b/devices/front_lights.yaml @@ -23,3 +23,7 @@ light: double_click_while_off_stays_off: false on_turn_off: - lambda: tuya_tuyalightplus->set_auto_off_time(30 * 60 * 1000); + power: + id: power + name: ${device_name} Power + light_wattage: 73.4 diff --git a/devices/kitchen_bar_lights.yaml b/devices/kitchen_bar_lights.yaml index 7767a80..f9fba2c 100644 --- a/devices/kitchen_bar_lights.yaml +++ b/devices/kitchen_bar_lights.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 32.4 diff --git a/devices/kitchen_table_light.yaml b/devices/kitchen_table_light.yaml index fa84cca..c1431b5 100644 --- a/devices/kitchen_table_light.yaml +++ b/devices/kitchen_table_light.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 55.1 diff --git a/devices/living_room_lights.yaml b/devices/living_room_lights.yaml index 377d5f6..efa8a6c 100644 --- a/devices/living_room_lights.yaml +++ b/devices/living_room_lights.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 117.6 diff --git a/devices/master_bath_fan.yaml b/devices/master_bath_fan.yaml index f930b36..a304b93 100644 --- a/devices/master_bath_fan.yaml +++ b/devices/master_bath_fan.yaml @@ -5,6 +5,7 @@ substitutions: ota_pwd: !secret master_bath_fan_ota_pwd api_pwd: !secret master_bath_fan_api_pwd ap_wifi_pwd: !secret master_bath_fan_ap_wifi_pwd + fan_wattage: "26.6" packages: device_base: !include ../packages/feit_dimmer_as_fan.yaml diff --git a/devices/master_bath_lights_1.yaml b/devices/master_bath_lights_1.yaml index 614d8d2..bfa8d09 100644 --- a/devices/master_bath_lights_1.yaml +++ b/devices/master_bath_lights_1.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 35.5 diff --git a/devices/master_bath_lights_2.yaml b/devices/master_bath_lights_2.yaml index 8b7d1f8..e10c48c 100644 --- a/devices/master_bath_lights_2.yaml +++ b/devices/master_bath_lights_2.yaml @@ -7,7 +7,7 @@ substitutions: ap_wifi_pwd: !secret master_bath_lights_2_ap_wifi_pwd packages: - feit_dimmer: !include ../packages/feit_dimmer.yaml + feit_dimmer: !include ../packages/feit_dimmer_without_power.yaml light: - platform: tuya_light_plus diff --git a/devices/office_light.yaml b/devices/office_light.yaml index 479f60b..3efaf09 100644 --- a/devices/office_light.yaml +++ b/devices/office_light.yaml @@ -26,3 +26,7 @@ light: night_default_brightness: 1 day_auto_off_time: 0 min night_auto_off_time: 15 min + power: + id: power + name: ${device_name} Power + light_wattage: 36.7 diff --git a/devices/patio_lights.yaml b/devices/patio_lights.yaml index 104f858..f3a5238 100644 --- a/devices/patio_lights.yaml +++ b/devices/patio_lights.yaml @@ -11,12 +11,46 @@ substitutions: packages: device_base: !include ../packages/device_base.yaml +external_components: + - source: github://cbpowell/ESPSense + components: [ espsense ] + +espsense: + plugs: + - name: Patio Lights + power_sensor: power + voltage: 120 + light: - platform: binary name: "Patio Lights" output: patio_lights_output + on_turn_on: + - sensor.template.publish: + id: power + state: 15.3 + on_turn_off: + - sensor.template.publish: + id: power + state: 0.0 output: - platform: gpio id: patio_lights_output pin: D1 + +sensor: + - platform: template + name: Patio Lights Power + id: power + unit_of_measurement: W + device_class: power + state_class: measurement + accuracy_decimals: 1 + - platform: total_daily_energy + name: Patio Lights + power_id: power + state_class: measurement + +time: + - platform: homeassistant diff --git a/devices/patio_and_pool_lights.yaml b/devices/pool_and_patio_lights.yaml similarity index 67% rename from devices/patio_and_pool_lights.yaml rename to devices/pool_and_patio_lights.yaml index 866ffcd..96b6d8f 100644 --- a/devices/patio_and_pool_lights.yaml +++ b/devices/pool_and_patio_lights.yaml @@ -15,6 +15,10 @@ esphome: includes: - ../custom/TreoLedPoolLight.h +external_components: + - source: github://cbpowell/ESPSense + components: [ espsense ] + binary_sensor: - platform: gpio id: patio_lights_button @@ -54,6 +58,12 @@ binary_sensor: then: - switch.turn_off: patio_lights_indicator +espsense: + plugs: + - name: Pool Lights + power_sensor: pool_light_power + voltage: 120 + light: - platform: custom lambda: |- @@ -63,6 +73,27 @@ light: lights: - id: pool_lights name: "Pool Lights" + on_turn_on: + - sensor.template.publish: + id: pool_light_power + state: 10.0 + on_turn_off: + - sensor.template.publish: + id: pool_light_power + state: 0.0 + +sensor: + - platform: template + name: Pool Lights Power + id: pool_light_power + unit_of_measurement: W + device_class: power + state_class: measurement + accuracy_decimals: 1 + - platform: total_daily_energy + name: Pool Lights + power_id: pool_light_power + state_class: measurement status_led: pin: @@ -73,3 +104,6 @@ switch: - platform: gpio id: patio_lights_indicator pin: 13 + +time: + - platform: homeassistant diff --git a/devices/pool_pumps.yaml b/devices/pool_pumps.yaml index 53081dd..6de69dc 100644 --- a/devices/pool_pumps.yaml +++ b/devices/pool_pumps.yaml @@ -11,6 +11,21 @@ substitutions: packages: device_base: !include ../packages/device_base.yaml +external_components: + - source: github://cbpowell/ESPSense + components: [ espsense ] + +espsense: + plugs: + - name: Pool Pump + power_sensor: pool_pump_power + current_sensor: pool_pump_current + voltage_sensor: voltage + - name: Pool Cleaner + power_sensor: pool_cleaner_power + current_sensor: pool_cleaner_current + voltage_sensor: voltage + i2c: sda: GPIO12 scl: GPIO14 @@ -19,10 +34,12 @@ sensor: - platform: ade7953 voltage: name: ${device_name} Voltage + id: voltage filters: - multiply: 2 current_a: name: Pool Cleaner Current + id: pool_cleaner_current filters: - lambda: |- // Filter the initial high current spike when the motor starts to prevent tripping the on_value_range logic @@ -43,6 +60,7 @@ sensor: - switch.turn_off: pool_cleaner current_b: name: Pool Pump Current + id: pool_pump_current filters: - lambda: |- // Filter the initial high current spike when the motor starts to prevent tripping the on_value_range logic @@ -63,10 +81,12 @@ sensor: - switch.turn_off: pool_pump active_power_a: name: Pool Cleaner Power + id: pool_cleaner_power filters: - lambda: "return x < .1 ? 0 : x * 2;" active_power_b: name: Pool Pump Power + id: pool_pump_power filters: - lambda: "return abs(x) < .1 ? 0 : abs(x) * 2;" update_interval: 2s @@ -92,6 +112,14 @@ sensor: name: "Pool Mode Id" id: pool_mode_id internal: true + - platform: total_daily_energy + name: "Pool Pump Total Daily Energy" + power_id: pool_pump_power + state_class: "measurement" + - platform: total_daily_energy + name: "Pool Cleaner Total Daily Energy" + power_id: pool_cleaner_power + state_class: "measurement" status_led: pin: diff --git a/packages/feit_dimmer.yaml b/packages/feit_dimmer.yaml index 7228c85..49c2760 100644 --- a/packages/feit_dimmer.yaml +++ b/packages/feit_dimmer.yaml @@ -7,10 +7,27 @@ external_components: type: local path: ../components components: [ tuya, tuya_light_plus ] + - source: github://cbpowell/ESPSense + components: [ espsense ] + +espsense: + plugs: + - name: ${device_name} + power_sensor: power + voltage: 120 packages: base: !include device_base.yaml logger: !include logger/logger_no_serial.yaml uart: !include uart/tuya.yaml +sensor: + - platform: total_daily_energy + name: ${device_name} + power_id: power + state_class: measurement + +time: + - platform: homeassistant + tuya: diff --git a/packages/feit_dimmer_as_fan.yaml b/packages/feit_dimmer_as_fan.yaml index 9e458af..7f2fcfa 100644 --- a/packages/feit_dimmer_as_fan.yaml +++ b/packages/feit_dimmer_as_fan.yaml @@ -7,13 +7,19 @@ external_components: type: local path: ../components components: [ tuya, tuya_dimmer_as_fan ] + - source: github://cbpowell/ESPSense + components: [ espsense ] packages: base: !include device_base.yaml logger: !include logger/logger_no_serial.yaml uart: !include uart/tuya.yaml -tuya: +espsense: + plugs: + - name: ${device_name} + power_sensor: power + voltage: 120 fan: - platform: tuya_dimmer_as_fan @@ -22,3 +28,18 @@ fan: switch_datapoint: 1 dimmer_datapoint: 2 dimmer_max_value: 1000 + power: + id: power + name: ${device_name} Power + fan_wattage: ${fan_wattage} + +sensor: + - platform: total_daily_energy + name: ${device_name} + power_id: power + state_class: measurement + +time: + - platform: homeassistant + +tuya: diff --git a/packages/feit_dimmer_without_power.yaml b/packages/feit_dimmer_without_power.yaml new file mode 100644 index 0000000..7228c85 --- /dev/null +++ b/packages/feit_dimmer_without_power.yaml @@ -0,0 +1,16 @@ +substitutions: + platform: ESP8266 + board: esp01_1m + +external_components: + - source: + type: local + path: ../components + components: [ tuya, tuya_light_plus ] + +packages: + base: !include device_base.yaml + logger: !include logger/logger_no_serial.yaml + uart: !include uart/tuya.yaml + +tuya: