Refactor master bedroom remote configuration: Update display button labels and implement backlight control based on user interaction
This commit is contained in:
@@ -17,6 +17,9 @@ esphome:
|
|||||||
- output.set_level:
|
- output.set_level:
|
||||||
id: backlight_output
|
id: backlight_output
|
||||||
level: 100%
|
level: 100%
|
||||||
|
- lambda: |-
|
||||||
|
id(last_interaction_ms) = millis();
|
||||||
|
id(backlight_is_on) = true;
|
||||||
- component.update: my_display
|
- component.update: my_display
|
||||||
|
|
||||||
esp32:
|
esp32:
|
||||||
@@ -82,7 +85,7 @@ display:
|
|||||||
} else {
|
} else {
|
||||||
it.filled_rectangle(20, 50, 130, 80, Color(0x424242));
|
it.filled_rectangle(20, 50, 130, 80, Color(0x424242));
|
||||||
}
|
}
|
||||||
it.print(85, 90, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "ALL");
|
it.print(85, 90, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Toggle All");
|
||||||
|
|
||||||
// Button 2: Light 1 (top-right)
|
// Button 2: Light 1 (top-right)
|
||||||
if (id(light1_state)) {
|
if (id(light1_state)) {
|
||||||
@@ -90,7 +93,7 @@ display:
|
|||||||
} else {
|
} else {
|
||||||
it.filled_rectangle(170, 50, 130, 80, Color(0x424242));
|
it.filled_rectangle(170, 50, 130, 80, Color(0x424242));
|
||||||
}
|
}
|
||||||
it.print(235, 90, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Light 1");
|
it.print(235, 90, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Polly's Light");
|
||||||
|
|
||||||
// Button 3: Light 2 (bottom-left)
|
// Button 3: Light 2 (bottom-left)
|
||||||
if (id(light2_state)) {
|
if (id(light2_state)) {
|
||||||
@@ -98,7 +101,7 @@ display:
|
|||||||
} else {
|
} else {
|
||||||
it.filled_rectangle(20, 150, 130, 80, Color(0x424242));
|
it.filled_rectangle(20, 150, 130, 80, Color(0x424242));
|
||||||
}
|
}
|
||||||
it.print(85, 190, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Light 2");
|
it.print(85, 190, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Joshua's Light");
|
||||||
|
|
||||||
// Button 4: Fan (bottom-right)
|
// Button 4: Fan (bottom-right)
|
||||||
if (id(fan_state)) {
|
if (id(fan_state)) {
|
||||||
@@ -106,7 +109,7 @@ display:
|
|||||||
} else {
|
} else {
|
||||||
it.filled_rectangle(170, 150, 130, 80, Color(0x424242));
|
it.filled_rectangle(170, 150, 130, 80, Color(0x424242));
|
||||||
}
|
}
|
||||||
it.print(235, 190, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Fan");
|
it.print(235, 190, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Ceiling Fan");
|
||||||
|
|
||||||
# XPT2046 Touchscreen
|
# XPT2046 Touchscreen
|
||||||
touchscreen:
|
touchscreen:
|
||||||
@@ -121,6 +124,12 @@ touchscreen:
|
|||||||
y_max: 3860
|
y_max: 3860
|
||||||
on_touch:
|
on_touch:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
|
id(last_interaction_ms) = millis();
|
||||||
|
if (!id(backlight_is_on)) {
|
||||||
|
id(backlight).turn_on();
|
||||||
|
id(backlight_is_on) = true;
|
||||||
|
}
|
||||||
|
|
||||||
int tx = touch.x;
|
int tx = touch.x;
|
||||||
int ty = touch.y;
|
int ty = touch.y;
|
||||||
ESP_LOGD("touch", "Touch at x=%d, y=%d", tx, ty);
|
ESP_LOGD("touch", "Touch at x=%d, y=%d", tx, ty);
|
||||||
@@ -153,10 +162,10 @@ light:
|
|||||||
|
|
||||||
# Fonts
|
# Fonts
|
||||||
font:
|
font:
|
||||||
- file: "gfonts://Roboto"
|
- file: "gfonts://Nunito"
|
||||||
id: title_font
|
id: title_font
|
||||||
size: 24
|
size: 24
|
||||||
- file: "gfonts://Roboto"
|
- file: "gfonts://Nunito"
|
||||||
id: button_font
|
id: button_font
|
||||||
size: 20
|
size: 20
|
||||||
|
|
||||||
@@ -186,11 +195,23 @@ globals:
|
|||||||
- id: touch_fan
|
- id: touch_fan
|
||||||
type: bool
|
type: bool
|
||||||
initial_value: "false"
|
initial_value: "false"
|
||||||
|
- id: last_interaction_ms
|
||||||
|
type: uint32_t
|
||||||
|
initial_value: "0"
|
||||||
|
- id: backlight_is_on
|
||||||
|
type: bool
|
||||||
|
initial_value: "true"
|
||||||
|
|
||||||
# Process touch events
|
# Process touch events
|
||||||
interval:
|
interval:
|
||||||
- interval: 100ms
|
- interval: 100ms
|
||||||
then:
|
then:
|
||||||
|
- if:
|
||||||
|
condition:
|
||||||
|
lambda: 'return id(backlight_is_on) && ((uint32_t)(millis() - id(last_interaction_ms)) > 30000);'
|
||||||
|
then:
|
||||||
|
- light.turn_off: backlight
|
||||||
|
- lambda: 'id(backlight_is_on) = false;'
|
||||||
- if:
|
- if:
|
||||||
condition:
|
condition:
|
||||||
lambda: 'return id(touch_all);'
|
lambda: 'return id(touch_all);'
|
||||||
|
|||||||
Reference in New Issue
Block a user