Refactor master bedroom remote configuration: Update entity IDs and improve touch event handling for enhanced functionality
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
substitutions:
|
substitutions:
|
||||||
name: mbr-ha-remote
|
name: cyd-remote
|
||||||
friendly_name: "Master HA Remote"
|
friendly_name: "Room Remote"
|
||||||
|
|
||||||
# Home Assistant entity IDs - UPDATE THESE TO MATCH YOUR SETUP
|
# Home Assistant entity IDs - UPDATE THESE TO MATCH YOUR SETUP
|
||||||
light_1_entity: switch.pollys_light
|
light_1_entity: switch.living_room_light_1
|
||||||
light_2_entity: switch.joshuas_light
|
light_2_entity: switch.living_room_light_2
|
||||||
fan_entity: switch.parents_ceiling_fan
|
fan_entity: switch.living_room_fan
|
||||||
# For "all" toggle, we'll control these three entities
|
|
||||||
|
|
||||||
esphome:
|
esphome:
|
||||||
name: ${name}
|
name: ${name}
|
||||||
@@ -24,25 +23,20 @@ api:
|
|||||||
key: !secret api_encryption_key
|
key: !secret api_encryption_key
|
||||||
|
|
||||||
ota:
|
ota:
|
||||||
- platform: esphome
|
platform: esphome
|
||||||
password: !secret ota_password
|
password: !secret ota_password
|
||||||
|
|
||||||
wifi:
|
wifi:
|
||||||
ssid: !secret wifi_ssid
|
ssid: !secret wifi_iot_ssid
|
||||||
password: !secret wifi_password
|
password: !secret wifi_password
|
||||||
ap:
|
ap:
|
||||||
ssid: "${name} Fallback"
|
ssid: "${name} Fallback"
|
||||||
password: !secret ap_password
|
password: !secret wifi_password
|
||||||
|
|
||||||
captive_portal:
|
captive_portal:
|
||||||
|
|
||||||
# -----------------------------
|
|
||||||
# CYD Display Configuration
|
|
||||||
# -----------------------------
|
|
||||||
|
|
||||||
# SPI for display and touchscreen
|
# SPI for display and touchscreen
|
||||||
spi:
|
spi:
|
||||||
- id: tft_spi
|
|
||||||
clk_pin: GPIO14
|
clk_pin: GPIO14
|
||||||
mosi_pin: GPIO13
|
mosi_pin: GPIO13
|
||||||
miso_pin: GPIO12
|
miso_pin: GPIO12
|
||||||
@@ -51,77 +45,74 @@ spi:
|
|||||||
display:
|
display:
|
||||||
- platform: ili9xxx
|
- platform: ili9xxx
|
||||||
model: ili9341
|
model: ili9341
|
||||||
spi_id: tft_spi
|
|
||||||
cs_pin: GPIO15
|
cs_pin: GPIO15
|
||||||
dc_pin: GPIO2
|
dc_pin: GPIO2
|
||||||
rotation: 0
|
rotation: 0
|
||||||
id: my_display
|
id: my_display
|
||||||
lambda: |-
|
lambda: |-
|
||||||
// Background
|
it.fill(Color(0x1A1A2E));
|
||||||
it.fill(Color(0x1a, 0x1a, 0x2e));
|
|
||||||
|
|
||||||
// Title
|
it.print(160, 20, id(title_font), Color(0xFFFFFF), TextAlign::TOP_CENTER, "Room Remote");
|
||||||
it.print(160, 20, id(title_font), Color(0xff, 0xff, 0xff), TextAlign::TOP_CENTER, "Room Remote");
|
|
||||||
|
|
||||||
// Draw buttons (2x2 grid)
|
|
||||||
// Button 1: All Toggle (top-left)
|
// Button 1: All Toggle (top-left)
|
||||||
auto all_color = id(all_state) ? Color(0x4c, 0xaf, 0x50) : Color(0x42, 0x42, 0x42);
|
if (id(all_state)) {
|
||||||
it.filled_rectangle(20, 50, 130, 80, all_color);
|
it.filled_rectangle(20, 50, 130, 80, Color(0x4CAF50));
|
||||||
it.print(85, 90, id(button_font), Color::WHITE, TextAlign::CENTER, "ALL");
|
} else {
|
||||||
|
it.filled_rectangle(20, 50, 130, 80, Color(0x424242));
|
||||||
|
}
|
||||||
|
it.print(85, 90, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "ALL");
|
||||||
|
|
||||||
// Button 2: Light 1 (top-right)
|
// Button 2: Light 1 (top-right)
|
||||||
auto light1_color = id(light1_state) ? Color(0xff, 0xc1, 0x07) : Color(0x42, 0x42, 0x42);
|
if (id(light1_state)) {
|
||||||
it.filled_rectangle(170, 50, 130, 80, light1_color);
|
it.filled_rectangle(170, 50, 130, 80, Color(0xFFC107));
|
||||||
it.print(235, 90, id(button_font), Color::WHITE, TextAlign::CENTER, "Light 1");
|
} else {
|
||||||
|
it.filled_rectangle(170, 50, 130, 80, Color(0x424242));
|
||||||
|
}
|
||||||
|
it.print(235, 90, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Light 1");
|
||||||
|
|
||||||
// Button 3: Light 2 (bottom-left)
|
// Button 3: Light 2 (bottom-left)
|
||||||
auto light2_color = id(light2_state) ? Color(0xff, 0xc1, 0x07) : Color(0x42, 0x42, 0x42);
|
if (id(light2_state)) {
|
||||||
it.filled_rectangle(20, 150, 130, 80, light2_color);
|
it.filled_rectangle(20, 150, 130, 80, Color(0xFFC107));
|
||||||
it.print(85, 190, id(button_font), Color::WHITE, TextAlign::CENTER, "Light 2");
|
} else {
|
||||||
|
it.filled_rectangle(20, 150, 130, 80, Color(0x424242));
|
||||||
|
}
|
||||||
|
it.print(85, 190, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Light 2");
|
||||||
|
|
||||||
// Button 4: Fan (bottom-right)
|
// Button 4: Fan (bottom-right)
|
||||||
auto fan_color = id(fan_state) ? Color(0x21, 0x96, 0xf3) : Color(0x42, 0x42, 0x42);
|
if (id(fan_state)) {
|
||||||
it.filled_rectangle(170, 150, 130, 80, fan_color);
|
it.filled_rectangle(170, 150, 130, 80, Color(0x2196F3));
|
||||||
it.print(235, 190, id(button_font), Color::WHITE, TextAlign::CENTER, "Fan");
|
} else {
|
||||||
|
it.filled_rectangle(170, 150, 130, 80, Color(0x424242));
|
||||||
|
}
|
||||||
|
it.print(235, 190, id(button_font), Color(0xFFFFFF), TextAlign::CENTER, "Fan");
|
||||||
|
|
||||||
# XPT2046 Touchscreen
|
# XPT2046 Touchscreen
|
||||||
touchscreen:
|
touchscreen:
|
||||||
- platform: xpt2046
|
- platform: xpt2046
|
||||||
spi_id: tft_spi
|
|
||||||
cs_pin: GPIO33
|
cs_pin: GPIO33
|
||||||
interrupt_pin: GPIO36
|
interrupt_pin: GPIO36
|
||||||
calibration:
|
calibration_x_min: 280
|
||||||
x_min: 280
|
calibration_x_max: 3860
|
||||||
x_max: 3860
|
calibration_y_min: 340
|
||||||
y_min: 340
|
calibration_y_max: 3860
|
||||||
y_max: 3860
|
|
||||||
on_touch:
|
on_touch:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
int x = touch.x;
|
int tx = touch.x;
|
||||||
int y = touch.y;
|
int ty = touch.y;
|
||||||
|
ESP_LOGD("touch", "Touch at x=%d, y=%d", tx, ty);
|
||||||
|
|
||||||
// Button 1: ALL (20-150, 50-130)
|
if (tx >= 20 && tx <= 150 && ty >= 50 && ty <= 130) {
|
||||||
if (x >= 20 && x <= 150 && y >= 50 && y <= 130) {
|
id(touch_all) = true;
|
||||||
id(btn_all).press();
|
|
||||||
}
|
}
|
||||||
// Button 2: Light 1 (170-300, 50-130)
|
else if (tx >= 170 && tx <= 300 && ty >= 50 && ty <= 130) {
|
||||||
else if (x >= 170 && x <= 300 && y >= 50 && y <= 130) {
|
id(touch_light1) = true;
|
||||||
id(btn_light1).press();
|
|
||||||
}
|
}
|
||||||
// Button 3: Light 2 (20-150, 150-230)
|
else if (tx >= 20 && tx <= 150 && ty >= 150 && ty <= 230) {
|
||||||
else if (x >= 20 && x <= 150 && y >= 150 && y <= 230) {
|
id(touch_light2) = true;
|
||||||
id(btn_light2).press();
|
|
||||||
}
|
}
|
||||||
// Button 4: Fan (170-300, 150-230)
|
else if (tx >= 170 && tx <= 300 && ty >= 150 && ty <= 230) {
|
||||||
else if (x >= 170 && x <= 300 && y >= 150 && y <= 230) {
|
id(touch_fan) = true;
|
||||||
id(btn_fan).press();
|
|
||||||
}
|
}
|
||||||
on_release:
|
|
||||||
- lambda: |-
|
|
||||||
id(btn_all).release();
|
|
||||||
id(btn_light1).release();
|
|
||||||
id(btn_light2).release();
|
|
||||||
id(btn_fan).release();
|
|
||||||
|
|
||||||
# Backlight control
|
# Backlight control
|
||||||
output:
|
output:
|
||||||
@@ -149,24 +140,38 @@ font:
|
|||||||
globals:
|
globals:
|
||||||
- id: all_state
|
- id: all_state
|
||||||
type: bool
|
type: bool
|
||||||
initial_value: 'false'
|
initial_value: "false"
|
||||||
- id: light1_state
|
- id: light1_state
|
||||||
type: bool
|
type: bool
|
||||||
initial_value: 'false'
|
initial_value: "false"
|
||||||
- id: light2_state
|
- id: light2_state
|
||||||
type: bool
|
type: bool
|
||||||
initial_value: 'false'
|
initial_value: "false"
|
||||||
- id: fan_state
|
- id: fan_state
|
||||||
type: bool
|
type: bool
|
||||||
initial_value: 'false'
|
initial_value: "false"
|
||||||
|
- id: touch_all
|
||||||
|
type: bool
|
||||||
|
initial_value: "false"
|
||||||
|
- id: touch_light1
|
||||||
|
type: bool
|
||||||
|
initial_value: "false"
|
||||||
|
- id: touch_light2
|
||||||
|
type: bool
|
||||||
|
initial_value: "false"
|
||||||
|
- id: touch_fan
|
||||||
|
type: bool
|
||||||
|
initial_value: "false"
|
||||||
|
|
||||||
# Binary sensors for touch buttons
|
# Process touch events
|
||||||
binary_sensor:
|
interval:
|
||||||
- platform: template
|
- interval: 100ms
|
||||||
id: btn_all
|
|
||||||
name: "Toggle All"
|
|
||||||
on_press:
|
|
||||||
then:
|
then:
|
||||||
|
- if:
|
||||||
|
condition:
|
||||||
|
lambda: 'return id(touch_all);'
|
||||||
|
then:
|
||||||
|
- lambda: 'id(touch_all) = false;'
|
||||||
- homeassistant.service:
|
- homeassistant.service:
|
||||||
service: switch.toggle
|
service: switch.toggle
|
||||||
data:
|
data:
|
||||||
@@ -179,32 +184,29 @@ binary_sensor:
|
|||||||
service: switch.toggle
|
service: switch.toggle
|
||||||
data:
|
data:
|
||||||
entity_id: ${fan_entity}
|
entity_id: ${fan_entity}
|
||||||
|
- if:
|
||||||
- platform: template
|
condition:
|
||||||
id: btn_light1
|
lambda: 'return id(touch_light1);'
|
||||||
name: "Polly's Light"
|
|
||||||
on_press:
|
|
||||||
then:
|
then:
|
||||||
|
- lambda: 'id(touch_light1) = false;'
|
||||||
- homeassistant.service:
|
- homeassistant.service:
|
||||||
service: switch.toggle
|
service: switch.toggle
|
||||||
data:
|
data:
|
||||||
entity_id: ${light_1_entity}
|
entity_id: ${light_1_entity}
|
||||||
|
- if:
|
||||||
- platform: template
|
condition:
|
||||||
id: btn_light2
|
lambda: 'return id(touch_light2);'
|
||||||
name: "Joshua's Light"
|
|
||||||
on_press:
|
|
||||||
then:
|
then:
|
||||||
|
- lambda: 'id(touch_light2) = false;'
|
||||||
- homeassistant.service:
|
- homeassistant.service:
|
||||||
service: switch.toggle
|
service: switch.toggle
|
||||||
data:
|
data:
|
||||||
entity_id: ${light_2_entity}
|
entity_id: ${light_2_entity}
|
||||||
|
- if:
|
||||||
- platform: template
|
condition:
|
||||||
id: btn_fan
|
lambda: 'return id(touch_fan);'
|
||||||
name: "Ceiling Fan"
|
|
||||||
on_press:
|
|
||||||
then:
|
then:
|
||||||
|
- lambda: 'id(touch_fan) = false;'
|
||||||
- homeassistant.service:
|
- homeassistant.service:
|
||||||
service: switch.toggle
|
service: switch.toggle
|
||||||
data:
|
data:
|
||||||
@@ -217,22 +219,21 @@ text_sensor:
|
|||||||
id: ha_light1_state
|
id: ha_light1_state
|
||||||
on_value:
|
on_value:
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: 'id(light1_state) = (x == "on");'
|
||||||
id(light1_state) = (x == "on");
|
- lambda: 'id(all_state) = id(light1_state) && id(light2_state) && id(fan_state);'
|
||||||
|
|
||||||
- platform: homeassistant
|
- platform: homeassistant
|
||||||
entity_id: ${light_2_entity}
|
entity_id: ${light_2_entity}
|
||||||
id: ha_light2_state
|
id: ha_light2_state
|
||||||
on_value:
|
on_value:
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: 'id(light2_state) = (x == "on");'
|
||||||
id(light2_state) = (x == "on");
|
- lambda: 'id(all_state) = id(light1_state) && id(light2_state) && id(fan_state);'
|
||||||
|
|
||||||
- platform: homeassistant
|
- platform: homeassistant
|
||||||
entity_id: ${fan_entity}
|
entity_id: ${fan_entity}
|
||||||
id: ha_fan_state
|
id: ha_fan_state
|
||||||
on_value:
|
on_value:
|
||||||
then:
|
then:
|
||||||
- lambda: |-
|
- lambda: 'id(fan_state) = (x == "on");'
|
||||||
id(fan_state) = (x == "on");
|
- lambda: 'id(all_state) = id(light1_state) && id(light2_state) && id(fan_state);'
|
||||||
id(all_state) = id(light1_state) && id(light2_state) && id(fan_state);
|
|
||||||
Reference in New Issue
Block a user