mirror of
https://github.com/nuttytree/ESPHome-Devices.git
synced 2024-08-30 18:12:19 +00:00
All Feit dimmer devices use custom Tuya light comp
Move all Feit dimmer devices to device folder README updates
This commit is contained in:
parent
56abafbb31
commit
dbd6e6c824
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
# Gitignore settings for ESPHome
|
||||
/.esphome/
|
||||
**/.esphome/
|
||||
/.vscode/
|
||||
**/.pioenvs/
|
||||
**/.piolibdeps/
|
||||
|
35
README.md
35
README.md
@ -1,6 +1,6 @@
|
||||
# ESPHome-Devices
|
||||
## Overview
|
||||
> This is a collection of [ESPHome](https://ESPHome.io) configuration files and code for my various ESP8266 devices that integrate with [Home Assistant](https://www.home-assistant.io/).
|
||||
> This is a collection of [ESPHome](https://ESPHome.io) configuration files and code for my various ESP8266 devices that integrate with [Home Assistant](https://www.home-assistant.io/). I am using includes and packages pretty extensively in order to prevent duplication and allow for easy changing of common settings.
|
||||
|
||||
> **What is ESPHome**<br>
|
||||
> ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems. For more information checkout [ESPHome.io](https://ESPHome.io).
|
||||
@ -28,6 +28,9 @@
|
||||
> ### Patio Lights
|
||||
> This is a [WEMOS D1 Mini Pro](https://www.amazon.com/gp/product/B07G9HZ5LM/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1) that is connected to a [relay](https://www.amazon.com/gp/product/B00VRUAHLE/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1) to control the power to the landscape lights around my patio. I used the WEMOS D1 Mini Pro because it has an external antenna. I initially used a [WEMOS D1 Mini clone](https://www.amazon.com/gp/product/B076F52NQD/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1) but the power supply for my lights was to far from the house and I kept having connectivity issues.
|
||||
|
||||
> ### Scripture of the Day
|
||||
> This is a project I just started working on (and I am still waiting on the hardware to arrive from China). I am planning on building 2 of them as Christmas presents for my wife and son. It will consist of a [ESP8266 e-Paper Panel Driver Board](https://www.waveshare.com/e-paper-esp8266-driver-board.htm) powered by a [lithium battery](https://www.amazon.com/dp/B0867KDMY7/?coliid=IE0LBNACFHG4U&colid=1LOK862UA8LA0&psc=1&ref_=lv_ov_lig_dp_it) and [TP4056 lithium battery charger module](https://www.amazon.com/dp/B06XQRQR3Q/?coliid=I1B2ELKKLLKAK0&colid=1LOK862UA8LA0&psc=1&ref_=lv_ov_lig_dp_it) and driving a [Waveshare 7.5inch 800×480 E-Ink display](https://www.waveshare.com/7.5inch-e-paper.htm) all mounted inside a picture frame. The plan is to have it sit in deep-sleep most of the time but wake up every night, grab a random scripture from the [Our Manna Daily Verses API](http://www.ourmanna.com/verses/api/), update the display with the verse, and go back to sleep.
|
||||
|
||||
## Switches
|
||||
> I plan to use dimmer switches for anything that is dimmable just for consistency and you never know when you might want to have the ability to dim a light. However there are times when a dimmer isn't an option.
|
||||
|
||||
@ -53,20 +56,24 @@
|
||||
|
||||
> Things I don't like about these switches:
|
||||
> > * Have to click repeatedly to change the brightness (can't hold to change)
|
||||
> > * All buttons are managed by the Tuya MCU so no ability to do things like double-taps (although I may have a solution for this but haven't had a chance to do a POC)
|
||||
> > * All buttons are managed by the Tuya MCU so adding things like double-taps is kind of a hack
|
||||
|
||||
> I have created a custom component for these that should work with most (if not all) Tuya dimmers which provides the following extra features:
|
||||
> I have created a custom [component](https://github.com/nuttytree/ESPHome-Devices/blob/master/custom/tuya_light_plus.h) for these that extends the standard Tuya Light component that should work with most (if not all) Tuya dimmers and provides the following extra features:
|
||||
> > * Resets the brightness level back to a default level when turned off so that it always comes on at the same level instead of the level it was at when turned off
|
||||
> > * The default level is configurable as different levels when my house is in "Day" mode vs "Night" mode (based on a binary sensor in Home Assistant)
|
||||
> > * Provides a service that I can dynamically change the current default brightness level
|
||||
> > * Allows you to "link" another light in Home Assistant that will be controlled by this dimmer
|
||||
> > * The default level is configurable as different levels when my house is in "Day" mode vs "Night" mode (based on a binary sensor in Home Assistant) and via a service in Home Assistant
|
||||
> > * Provides an option to auto turn off the light after a period of time
|
||||
> > * The auto turn off time is configurable to be different when my house is in "Day" mode vs "Night" mode (based on a binary sensor in Home Assistant) and via a service in Home Assistant
|
||||
> > * Adds ability to specify a function to call when the switch is double tapped
|
||||
> > * Allows you to "link" other light(s) in Home Assistant that will be controlled by this dimmer
|
||||
|
||||
> The following devices are Feit Dimmers:
|
||||
> > * Basement Stair Lights/Basement Stair Lights 2
|
||||
> > * Computer Light
|
||||
> > * Dining Room Light
|
||||
> > * Family Room Light
|
||||
> > * Kitchen Bar Lights
|
||||
> > * Kitchen Table Light
|
||||
> > * Master Bathroom Lights/Master Bathroom Lights 2
|
||||
> > * Office Light
|
||||
> > * [Basement Stair Lights](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/basement_stair_lights_1.yaml)/[Basement Stair Lights 2](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/basement_stair_lights_2.yaml)
|
||||
> > * [Computer Light](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/computer_light.yaml)
|
||||
> > * [Dining Room Light](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/dining_room_light.yaml)
|
||||
> > * [Family Room Light](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/family_room_light.yaml)
|
||||
> > * [Front Lights](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/front_lights.yaml)
|
||||
> > * [Kitchen Bar Lights](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/kitchen_bar_lights.yaml)
|
||||
> > * [Kitchen Table Light](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/kitchen_table_light.yaml)
|
||||
> > * [Living Room Lights](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/living_room_lights.yaml)
|
||||
> > * [Master Bathroom Lights](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/master_bath_lights_1.yaml)/[Master Bathroom Lights 2](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/master_bath_lights_2.yaml)
|
||||
> > * [Office Light](https://github.com/nuttytree/ESPHome-Devices/blob/master/devices/office_light.yaml)
|
||||
|
@ -1,11 +0,0 @@
|
||||
<<: !include wifi.yaml
|
||||
<<: !include api.yaml
|
||||
<<: !include ota.yaml
|
||||
|
||||
tuya:
|
||||
|
||||
uart:
|
||||
- !include uart/tuya.yaml
|
||||
|
||||
light:
|
||||
- !include light/tuya_dimmer.yaml
|
@ -1,50 +0,0 @@
|
||||
esphome:
|
||||
<<: !include esphome.yaml
|
||||
includes:
|
||||
- tuya_light_control.h
|
||||
|
||||
<<: !include common_tuya_dimmer.yaml
|
||||
<<: !include logger/logger_none.yaml
|
||||
|
||||
interval:
|
||||
- interval: 1min
|
||||
then:
|
||||
if:
|
||||
condition:
|
||||
and:
|
||||
- binary_sensor.is_off: day_night
|
||||
- for:
|
||||
time: ${night_auto_off_time}
|
||||
condition:
|
||||
light.is_on: tuya_light
|
||||
then:
|
||||
- light.turn_off: tuya_light
|
||||
|
||||
custom_component:
|
||||
- lambda: |-
|
||||
auto control = new TuyaLightControl();
|
||||
control->set_switch_id(1);
|
||||
control->set_dimmer_id(2);
|
||||
control->set_min_value(0);
|
||||
control->set_max_value(1000);
|
||||
control->set_tuya_parent(tuya_tuya);
|
||||
control->set_day_brightness(${day_brightness});
|
||||
control->set_night_brightness(${night_brightness});
|
||||
control->set_api_server(api_apiserver);
|
||||
control->set_linked_lights("${linked_lights}");
|
||||
return {control};
|
||||
|
||||
binary_sensor:
|
||||
- !include binary_sensor/status.yaml
|
||||
- !include binary_sensor/day_night.yaml
|
||||
|
||||
sensor:
|
||||
- !include sensor/uptime.yaml
|
||||
- !include sensor/wifi.yaml
|
||||
|
||||
switch:
|
||||
- !include switch/restart.yaml
|
||||
|
||||
text_sensor:
|
||||
- !include text_sensor/version.yaml
|
||||
- !include text_sensor/wifi.yaml
|
10
devices/.gitignore
vendored
10
devices/.gitignore
vendored
@ -1,10 +0,0 @@
|
||||
# Gitignore settings for ESPHome
|
||||
# This is an example and may include too much for your use-case.
|
||||
# You can modify this file to suit your needs.
|
||||
/.esphome/
|
||||
**/.pioenvs/
|
||||
**/.piolibdeps/
|
||||
**/lib/
|
||||
**/src/
|
||||
**/platformio.ini
|
||||
/secrets.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: basement_stair_lights
|
||||
device_name: Basement Stair Lights
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret basement_stair_lights_ip
|
||||
ota_pwd: !secret basement_stair_lights_ota_pwd
|
||||
api_pwd: !secret basement_stair_lights_api_pwd
|
||||
ap_wifi_pwd: !secret basement_stair_lights_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".03"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: "light.basement_stair_lights_2"
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: basement_stair_lights_2
|
||||
device_name: Basement Stair Lights 2
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret basement_stair_lights_2_ip
|
||||
ota_pwd: !secret basement_stair_lights_2_ota_pwd
|
||||
api_pwd: !secret basement_stair_lights_2_api_pwd
|
||||
ap_wifi_pwd: !secret basement_stair_lights_2_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".03"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: "light.basement_stair_lights"
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: family_room_light
|
||||
device_name: Family Room Light
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret family_room_light_ip
|
||||
ota_pwd: !secret family_room_light_ota_pwd
|
||||
api_pwd: !secret family_room_light_api_pwd
|
||||
ap_wifi_pwd: !secret family_room_light_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".03"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: ""
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: kitchen_bar_lights
|
||||
device_name: Kitchen Bar Lights
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret kitchen_bar_lights_ip
|
||||
ota_pwd: !secret kitchen_bar_lights_ota_pwd
|
||||
api_pwd: !secret kitchen_bar_lights_api_pwd
|
||||
ap_wifi_pwd: !secret kitchen_bar_lights_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".03"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: ""
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: kitchen_table_light
|
||||
device_name: Kitchen Table Light
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret kitchen_table_light_ip
|
||||
ota_pwd: !secret kitchen_table_light_ota_pwd
|
||||
api_pwd: !secret kitchen_table_light_api_pwd
|
||||
ap_wifi_pwd: !secret kitchen_table_light_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".03"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: ""
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: living_room_lights
|
||||
device_name: Living Room Lights
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret living_room_lights_ip
|
||||
ota_pwd: !secret living_room_lights_ota_pwd
|
||||
api_pwd: !secret living_room_lights_api_pwd
|
||||
ap_wifi_pwd: !secret living_room_lights_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".03"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: ""
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: master_bath_lights
|
||||
device_name: Master Bathroom Lights
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret master_bath_lights_ip
|
||||
ota_pwd: !secret master_bath_lights_ota_pwd
|
||||
api_pwd: !secret master_bath_lights_api_pwd
|
||||
ap_wifi_pwd: !secret master_bath_lights_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".05"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: ""
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: master_bath_lights_2
|
||||
device_name: Master Bathroom Lights 2
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret master_bath_lights_2_ip
|
||||
ota_pwd: !secret master_bath_lights_2_ota_pwd
|
||||
api_pwd: !secret master_bath_lights_2_api_pwd
|
||||
ap_wifi_pwd: !secret master_bath_lights_2_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".05"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: ""
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
@ -1,15 +1,21 @@
|
||||
substitutions:
|
||||
device_id: office_light
|
||||
device_name: Office Light
|
||||
platform: ESP8266
|
||||
board: esp01_1m
|
||||
ip_address: !secret office_light_ip
|
||||
ota_pwd: !secret office_light_ota_pwd
|
||||
api_pwd: !secret office_light_api_pwd
|
||||
ap_wifi_pwd: !secret office_light_ap_wifi_pwd
|
||||
day_brightness: "1"
|
||||
night_brightness: ".03"
|
||||
night_auto_off_time: 15min
|
||||
day_auto_off_minutes: "0"
|
||||
night_auto_off_minutes: "15"
|
||||
linked_lights: ""
|
||||
double_tap_on_stays_on: "true"
|
||||
|
||||
<<: !include common/device_tuya_dimmer.yaml
|
||||
script:
|
||||
- id: startup
|
||||
then:
|
||||
- lambda: |-
|
||||
|
||||
packages:
|
||||
feit_dimmer: !include ../packages/feit_dimmer.yaml
|
1
devices/secrets.yaml
Normal file
1
devices/secrets.yaml
Normal file
@ -0,0 +1 @@
|
||||
<<: !include ../secrets.yaml
|
@ -1,117 +0,0 @@
|
||||
#include "esphome.h"
|
||||
|
||||
class TuyaLightControl : public Component, public CustomAPIDevice {
|
||||
public:
|
||||
void setup() override;
|
||||
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_tuya_parent(esphome::tuya::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_day_brightness(float brightness) { this->day_brightness_ = brightness; }
|
||||
void set_night_brightness(float brightness) { this->night_brightness_ = brightness; }
|
||||
void set_api_server(api::APIServer *api_server) { this->api_server_ = api_server; };
|
||||
void set_linked_lights(const std::string linked_lights);
|
||||
void set_default_brightness(float brightness);
|
||||
void on_day_night_changed(std::string state);
|
||||
|
||||
protected:
|
||||
void handle_datapoint(esphome::tuya::TuyaDatapoint datapoint);
|
||||
void set_brightness();
|
||||
|
||||
esphome::tuya::Tuya *parent_;
|
||||
optional<uint8_t> switch_id_{};
|
||||
optional<uint8_t> dimmer_id_{};
|
||||
uint32_t min_value_ = 0;
|
||||
uint32_t max_value_ = 1000;
|
||||
float day_brightness_ = 1;
|
||||
float night_brightness_ = .03;
|
||||
float default_brightness_ = 1;
|
||||
api::APIServer *api_server_;
|
||||
api::HomeAssistantServiceCallAction<> *turn_on_service_;
|
||||
api::HomeAssistantServiceCallAction<> *turn_off_service_;
|
||||
bool has_linked_lights_ = false;
|
||||
bool is_on_;
|
||||
uint32_t brightness_pct_;
|
||||
};
|
||||
|
||||
void TuyaLightControl::setup() {
|
||||
this->parent_->register_listener(*this->switch_id_, [this](esphome::tuya::TuyaDatapoint datapoint) {
|
||||
this->handle_datapoint(datapoint);
|
||||
});
|
||||
|
||||
this->parent_->register_listener(*this->dimmer_id_, [this](esphome::tuya::TuyaDatapoint datapoint) {
|
||||
this->handle_datapoint(datapoint);
|
||||
});
|
||||
|
||||
register_service(&TuyaLightControl::set_default_brightness, "set_default_brightness", {"brightness"});
|
||||
|
||||
subscribe_homeassistant_state(&TuyaLightControl::on_day_night_changed, "sensor.day_night");
|
||||
}
|
||||
|
||||
void TuyaLightControl::set_linked_lights(const std::string linked_lights) {
|
||||
if (linked_lights != "") {
|
||||
this->has_linked_lights_ = true;
|
||||
|
||||
this->turn_on_service_ = new api::HomeAssistantServiceCallAction<>(this->api_server_, false);
|
||||
this->turn_on_service_->set_service("light.turn_on");
|
||||
this->turn_on_service_->add_data("entity_id", linked_lights);
|
||||
this->turn_on_service_->add_variable("brightness_pct", [=]() { return this->brightness_pct_; });
|
||||
this->turn_on_service_->add_data_template("brightness_pct", "{{ brightness_pct }}");
|
||||
|
||||
this->turn_off_service_ = new api::HomeAssistantServiceCallAction<>(this->api_server_, false);
|
||||
this->turn_off_service_->set_service("light.turn_off");
|
||||
this->turn_off_service_->add_data("entity_id", linked_lights);
|
||||
}
|
||||
}
|
||||
|
||||
void TuyaLightControl::set_default_brightness(float brightness) {
|
||||
this->default_brightness_ = brightness > 1 ? 1 : brightness;
|
||||
this->set_brightness();
|
||||
}
|
||||
|
||||
void TuyaLightControl::on_day_night_changed(std::string state) {
|
||||
if (state == "Day") {
|
||||
this->default_brightness_ = this->day_brightness_;
|
||||
}
|
||||
else if (state == "Night")
|
||||
{
|
||||
this->default_brightness_ = this->night_brightness_;
|
||||
}
|
||||
this->set_brightness();
|
||||
}
|
||||
|
||||
void TuyaLightControl::handle_datapoint(esphome::tuya::TuyaDatapoint datapoint) {
|
||||
if (datapoint.id == *this->switch_id_) {
|
||||
this->is_on_ = datapoint.value_bool;
|
||||
if (this->has_linked_lights_) {
|
||||
if (this->is_on_) {
|
||||
this->turn_on_service_->play();
|
||||
}
|
||||
else {
|
||||
this->turn_off_service_->play();
|
||||
}
|
||||
}
|
||||
this->set_brightness();
|
||||
}
|
||||
else if (datapoint.id == *this->dimmer_id_) {
|
||||
this->brightness_pct_ = static_cast<uint32_t>(datapoint.value_uint * 100 / this->max_value_);
|
||||
if (this->has_linked_lights_) {
|
||||
if (this->is_on_) {
|
||||
this->turn_on_service_->play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TuyaLightControl::set_brightness() {
|
||||
if (!this->is_on_) {
|
||||
auto brightness_int = static_cast<uint32_t>(this->default_brightness_ * this->max_value_);
|
||||
brightness_int = std::max(brightness_int, this->min_value_);
|
||||
esphome::tuya::TuyaDatapoint datapoint{};
|
||||
datapoint.id = *this->dimmer_id_;
|
||||
datapoint.type = esphome::tuya::TuyaDatapointType::INTEGER;
|
||||
datapoint.value_uint = brightness_int;
|
||||
this->parent_->set_datapoint_value(datapoint);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user