Skip to content

Commit ec77a1c

Browse files
f18mCopilot
andcommitted
amke sync of contact sensors more robust at startup
Co-authored-by: Copilot <copilot@github.com>
1 parent 3bc8f88 commit ec77a1c

7 files changed

Lines changed: 55 additions & 15 deletions

File tree

dev-sdl.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010

1111
# Substitution variables used through the codebase
1212
substitutions:
13-
# secrets -- these allow the ESPHome device to "talk" to your Wifi and
13+
# --------------------------------------------------------------------------
14+
# Target platform
15+
# --------------------------------------------------------------------------
16+
17+
target_platform: "sdl"
18+
19+
# --------------------------------------------------------------------------
20+
# Secrets
21+
# --------------------------------------------------------------------------
22+
23+
# these allow the ESPHome device to "talk" to your Wifi and
1424
# your HomeAssistant instance
1525
encryption_key: "I445Nv3wkiOT85A1hLs1PZZB3orL15TB9W6K6Jc9tmE="
1626
ota_password: "your_ota_password_here"
@@ -19,7 +29,6 @@ substitutions:
1929
wifi_ap_password: "your_wifi_ap_password_here"
2030

2131

22-
2332
# --------------------------------------------------------------------------
2433
# Features
2534
# --------------------------------------------------------------------------
@@ -162,6 +171,8 @@ esphome:
162171
then:
163172
- script.execute: hide_unwanted_rooms
164173
- script.execute: hide_unwanted_tabs
174+
- delay: 2s
175+
- script.execute: sync_all_window_contact_ui
165176

166177
# Webserver is exposed under regular use
167178
#web_server:
@@ -181,8 +192,6 @@ packages:
181192

182193
# 1000s of glyphs
183194
glyphs: !include include/mdi_glyph_substitutions.yaml
184-
# Some basic sensors
185-
base_sensors: !include include/sensors_base-SDL.yaml
186195
# Get the time from HA
187196
#time: !include esphome-modular-lvgl-buttons/common/time_homeassistant.yaml
188197
# Styles + Themes

include/scripts.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,15 @@ script:
8888
lv_btnmatrix_set_btn_ctrl(tab_buttons, idx_tab_rooms, hidden_state);
8989
}
9090
91+
- id: sync_all_window_contact_ui
92+
then:
93+
- script.execute: sync_window_contact_ui_${room1_id}
94+
- script.execute: sync_window_contact_ui_${room2_id}
95+
- script.execute: sync_window_contact_ui_${room3_id}
96+
- if:
97+
condition:
98+
lambda: |-
99+
return std::string("${num_rooms}") == "4";
100+
then:
101+
- script.execute: sync_window_contact_ui_${room4_id}
102+

include/sensors.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Purpose: Defines Home Assistant sensor integrations that update LVGL room
33
# temperature and heating controls.
44
# List of subtitutions:
5+
# - target_platform
56
# - room1_id, room1_ha_temperature_sensor, room1_ha_humidity_sensor,
67
# room1_ha_window_contact_sensor, room1_ha_floor_heating_switch, room1_ha_cover
78
# - room2_id, room2_ha_temperature_sensor, room2_ha_humidity_sensor,
@@ -20,6 +21,13 @@
2021

2122
packages:
2223

24+
# import basic sensors depending on the target platform
25+
basic: !include {
26+
file: "sensors_basic_${target_platform}.yaml",
27+
vars: {}
28+
}
29+
30+
2331
# Import from HA the room sensors
2432

2533
room1: !include {

include/sensors_room_status.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,20 @@ sensor:
8282
# format: "Updated labels for UP/DOWN btns for cover of room ${room_id} to %d"
8383
# args: [ 'id(cover_position_${room_id}).state' ]
8484

85-
binary_sensor:
86-
87-
# ROOM WINDOW CONTACT SENSOR
88-
- platform: homeassistant
89-
entity_id: ${ha_window_contact_sensor_id}
90-
id: sensor_contact_${room_id}
91-
on_state:
85+
script:
86+
- id: sync_window_contact_ui_${room_id}
87+
then:
9288
- lvgl.label.update:
9389
id: lbl_icon_window_${room_id}
9490
text: !lambda |-
95-
if (x) {
91+
if (id(sensor_contact_${room_id}).state) {
9692
return "${mdi_window_open_variant}";
9793
}
9894
return "${mdi_window_closed_variant}";
9995
- if:
10096
condition:
10197
lambda: |-
102-
return x;
98+
return id(sensor_contact_${room_id}).state;
10399
then:
104100
- lvgl.label.update:
105101
id: lbl_icon_window_${room_id}
@@ -112,6 +108,15 @@ binary_sensor:
112108
id: lbl_icon_window_${room_id}
113109
text_color: $icon_on_color
114110

111+
binary_sensor:
112+
113+
# ROOM WINDOW CONTACT SENSOR
114+
- platform: homeassistant
115+
entity_id: ${ha_window_contact_sensor_id}
116+
id: sensor_contact_${room_id}
117+
on_state:
118+
- script.execute: sync_window_contact_ui_${room_id}
119+
115120
switch:
116121
# FLOOR HEATING SWITCH
117122
- platform: homeassistant

main.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
# Substitution variables used through the codebase
1111
substitutions:
1212

13+
# --------------------------------------------------------------------------
14+
# Target platform
15+
# --------------------------------------------------------------------------
16+
17+
target_platform: "esp32"
18+
1319
# --------------------------------------------------------------------------
1420
# Secrets
1521
# --------------------------------------------------------------------------
@@ -172,6 +178,8 @@ esphome:
172178
then:
173179
- script.execute: hide_unwanted_rooms
174180
- script.execute: hide_unwanted_tabs
181+
- delay: 2s
182+
- script.execute: sync_all_window_contact_ui
175183

176184
# Webserver is exposed under regular use
177185
web_server:
@@ -190,8 +198,6 @@ packages:
190198

191199
# 1000s of glyphs
192200
glyphs: !include include/mdi_glyph_substitutions.yaml
193-
# Some basic sensors
194-
base_sensors: !include include/sensors_base.yaml
195201
# Styles + Themes
196202
theme_style: !include include/theme_style.yaml
197203
# Backlight control with screen saver

0 commit comments

Comments
 (0)