Add support to friendly names

Solves #1719
This commit is contained in:
Edward Firmo
2024-01-25 11:01:46 +01:00
parent da3e1d57d1
commit e5329338df
5 changed files with 129 additions and 116 deletions

View File

@@ -34,7 +34,7 @@ substitutions:
climate:
- platform: thermostat
name: ${name} Thermostat
name: Thermostat
id: thermostat_embedded
sensor: temp_nspanel
min_idle_time: ${min_idle_time}s
@@ -71,7 +71,7 @@ globals:
switch:
##### PHYSICAL SWITCH 0 (Dummy) - Used when relay is not set #####
- name: ${name} Relay 0 (dummy)
- name: Relay 0 (dummy)
platform: template
id: relay_0
lambda: !lambda return false;

View File

@@ -50,7 +50,7 @@ api:
button:
##### UPDATE TFT DISPLAY #####
- id: tft_update
name: ${name} Update TFT display
name: Update TFT display
platform: template
icon: mdi:file-sync
entity_category: config
@@ -428,12 +428,6 @@ script:
baud_rate: 115200
- script.wait: upload_tft_sequence_attempt
### Then attempt twice again at 9600bps
- script.execute:
id: upload_tft_sequence_attempt
baud_rate: 9600
- script.wait: upload_tft_sequence_attempt
### Restart Nextion and attempt twice again at default baud rate (115200bps)
- script.execute:
id: report_upload_progress
@@ -500,14 +494,13 @@ script:
definitive: false
- script.wait: set_baud_rate
- delay: 2s
# First attempt
- script.execute: upload_tft_attempt
- script.wait: upload_tft_attempt
- delay: 5s
# Backup attempt
- script.execute: upload_tft_attempt
- script.wait: upload_tft_attempt
- delay: 5s
- repeat:
count: 2
then:
# First attempt
- script.execute: upload_tft_attempt
- script.wait: upload_tft_attempt
- delay: 5s
- id: upload_tft_sequence_attempt_v414
mode: single
@@ -1219,7 +1212,7 @@ script:
select:
- id: tft_file_branch
name: ${name} Update TFT display - Branch
name: Update TFT display - Branch
platform: template
options:
- "v${version}"
@@ -1236,7 +1229,7 @@ select:
- script.execute: set_tft_file
- id: tft_file_model
name: ${name} Update TFT display - Model
name: Update TFT display - Model
platform: template
options:
- "Use nextion_update_url"

View File

@@ -16,7 +16,7 @@ substitutions:
button:
##### EXIT REPARSE TFT DISPLAY #####
- name: ${name} Exit reparse
- name: Exit reparse
platform: template
icon: mdi:file-sync
id: tft_reparse_off
@@ -31,12 +31,12 @@ captive_portal:
sensor:
##### Uptime Sensors #####
- name: ${name} Uptime seconds
- name: Uptime seconds
id: uptime_sec
platform: uptime
internal: true
- name: ${name} API uptime
- name: API uptime
id: api_timestamp
platform: template
lambda: 'return id(time_provider).now().timestamp;'
@@ -46,7 +46,7 @@ sensor:
accuracy_decimals: 0
update_interval: never
- name: ${name} Device uptime
- name: Device uptime
id: device_timestamp
platform: template
lambda: 'return (id(time_provider).now().timestamp - id(uptime_sec).state);'
@@ -58,7 +58,7 @@ sensor:
text_sensor:
##### ESPhome version used to compile the app #####
- name: ${name} ESPhome Version
- name: ESPhome Version
platform: version
disabled_by_default: false
internal: false
@@ -66,14 +66,14 @@ text_sensor:
- platform: wifi_info
ip_address:
name: ${name} IP
name: IP
disabled_by_default: true
id: ip_address
ssid:
name: ${name} SSID
name: SSID
disabled_by_default: true
bssid:
name: ${name} BSSID
name: BSSID
disabled_by_default: true
time:

View File

@@ -15,6 +15,7 @@ substitutions:
ap_password: ${wifi_password}
device_name: NSPanel
name: ${device_name}
friendly_name: ${device_name}
wifi_timeout: '15'
##### DON'T CHANGE THIS ######
version: "4.2.5dev"
@@ -22,7 +23,7 @@ substitutions:
##### External components #####
external_components:
- source: github://pr#6128 # Remove this and update min ver when that PR is released (Hopefully v2024.1.0)
- source: github://pr#6128 # Remove this and update min ver when that PR is released (Hopefully v2024.2.0)
components:
- nextion
refresh: 300s
@@ -30,6 +31,7 @@ external_components:
##### ESPHOME CONFIGURATION #####
esphome:
name: ${name}
friendly_name: ${friendly_name}
min_version: 2023.12.0
platformio_options:
build_flags:
@@ -37,11 +39,26 @@ esphome:
on_boot:
- priority: 600.0 # This is where most sensors are set up.
then:
- lambda: |-
// Update Wi-Fi icon
disp1->set_component_text_printf("home.wifi_icon", "\uE708");
// Update Wi-Fi icon color
disp1->set_component_font_color("home.wifi_icon", 63488);
- script.execute: restore_settings
on_shutdown:
then:
- switch.turn_off: screen_power
- priority: 0
then:
- lambda: |-
// Make it unavailable to blueprint calls
nextion_init->publish_state(false);
// Update Wi-Fi icon
disp1->set_component_text_printf("home.wifi_icon", "\uE708");
// Update Wi-Fi icon color
disp1->set_component_font_color("home.wifi_icon", 63488);
- priority: 600.0
then:
- switch.turn_off: screen_power
##### TYPE OF ESP BOARD #####
esp32:
@@ -934,7 +951,7 @@ globals:
binary_sensor:
###### LEFT BUTTON BELOW DISPLAY TO TOGGLE RELAY#####
- name: ${name} Left Button
- name: Left Button
platform: gpio
id: left_button
pin:
@@ -987,7 +1004,7 @@ binary_sensor:
- script.execute: setup_sequence
##### RIGHT BUTTON BELOW DISPLAY TO TOGGLE RELAY #####
- name: ${name} Right Button
- name: Right Button
platform: gpio
id: right_button
pin:
@@ -1031,7 +1048,7 @@ binary_sensor:
- button.press: restart_nspanel
##### Restart NSPanel Button - Setting Page #####
- name: ${name} Restart
- name: Restart
platform: nextion
page_id: 7
component_id: 9
@@ -1039,7 +1056,7 @@ binary_sensor:
on_click:
- button.press: restart_nspanel
##### Restart NSPanel Button - Boot Page #####
- name: ${name} Restart
- name: Restart
platform: nextion
page_id: 8
component_id: 4
@@ -1048,7 +1065,7 @@ binary_sensor:
- button.press: restart_nspanel
## Delays initial info from HA to the display #####
- name: ${name} Nextion display
- name: Nextion display
id: nextion_init
platform: template
device_class: connectivity
@@ -1057,7 +1074,7 @@ binary_sensor:
icon: mdi:tablet-dashboard
##### API connection status
- name: ${name} Status
- name: Status
platform: status
id: api_status
on_state:
@@ -1067,7 +1084,7 @@ binary_sensor:
##### START - BUTTON CONFIGURATION #####
button:
###### Factory Reset button #####
- name: ${name} Factory reset
- name: Factory reset
platform: factory_reset
id: nspanel_factory_reset
internal: false
@@ -1075,12 +1092,12 @@ button:
icon: mdi:restart-alert
###### REBOOT BUTTON #####
- name: ${name} Restart
- name: Restart
platform: restart
id: restart_nspanel
###### Power cycle Nextion Display ######
- name: ${name} Nextion display - Power cycle
- name: Nextion display - Power cycle
id: screen_power_cycle
platform: template
internal: false
@@ -1095,7 +1112,7 @@ button:
##### START - NUMBER CONFIGURATION #####
number:
##### SCREEN BRIGHTNESS #####
- name: ${name} Display Brightness
- name: Display Brightness
id: display_brightness
platform: template
entity_category: config
@@ -1122,7 +1139,7 @@ number:
}
##### SCREEN BRIGHTNESS DIMMED DOWN #####
- name: ${name} Display Brightness Dimdown
- name: Display Brightness Dimdown
id: display_dim_brightness
platform: template
entity_category: config
@@ -1147,7 +1164,7 @@ number:
}
##### SCREEN BRIGHTNESS SLEEP #####
- name: ${name} Display Brightness Sleep
- name: Display Brightness Sleep
id: display_sleep_brightness
platform: template
entity_category: config
@@ -1166,11 +1183,11 @@ number:
page_screensaver->execute();
##### Temperature Correction #####
- name: ${name} Temperature Correction
- name: Temperature Correction
platform: template
id: temperature_correction
entity_category: config
unit_of_measurement: ${temp_units}
unit_of_measurement: °C
min_value: -10
max_value: 10
initial_value: 0
@@ -1185,7 +1202,7 @@ number:
- lambda: temp_nspanel->publish_state(temp_nspanel->raw_state);
##### Timers settings #####
- name: ${name} Timeout Page
- name: Timeout Page
platform: template
id: timeout_page
entity_category: config
@@ -1199,7 +1216,7 @@ number:
unit_of_measurement: "s"
set_action:
- lambda: timer_page->execute(current_page->state.c_str(), int(x));
- name: ${name} Timeout Dimming
- name: Timeout Dimming
platform: template
id: timeout_dim
entity_category: config
@@ -1213,7 +1230,7 @@ number:
unit_of_measurement: "s"
set_action:
- lambda: timer_dim->execute(current_page->state.c_str(), int(x));
- name: ${name} Timeout Sleep
- name: Timeout Sleep
platform: template
id: timeout_sleep
entity_category: config
@@ -1233,7 +1250,7 @@ number:
##### START - SELECT CONFIGURATION #####
select:
- id: baud_rate
name: ${name} Baud rate
name: Baud rate
platform: template
options:
- "2400"
@@ -1260,7 +1277,7 @@ select:
- lambda: set_baud_rate->execute(stoi(x), true);
- id: wakeup_page_name
name: ${name} Wake-up page
name: Wake-up page
platform: template
options:
- buttonpage01
@@ -1304,10 +1321,10 @@ sensor:
##### INTERNAL TEMPERATURE SENSOR, resistance to temperature (calculation) #####
- id: temp_nspanel
name: ${name} Temperature
name: Temperature
platform: ntc
sensor: resistance_sensor
unit_of_measurement: ${temp_units}
unit_of_measurement: °C
internal: false
calibration:
b_constant: 3950
@@ -1315,11 +1332,7 @@ sensor:
reference_resistance: 10kOhm
filters:
- lambda: |-
std::string temp_unit = "${temp_units}";
if (temp_unit == "°F" or temp_unit == "F" or temp_unit == "°f" or temp_unit == "f")
return (x * (9.0/5.0)) + 32.0 + temperature_correction->state;
else
return x + temperature_correction->state;
return x + temperature_correction->state;
on_value:
then:
# Show panel's temperature if API or Wi-Fi are out
@@ -1327,7 +1340,7 @@ sensor:
###### Display Brightness GET VALUE FROM NSPanel SLIDER #####
- id: brightslider
name: ${name} brightness Slider
name: brightness Slider
platform: nextion
variable_name: brightslider
internal: true
@@ -1341,7 +1354,7 @@ sensor:
###### Display DIM Brightness GET VALUE FROM NSPanel SLIDER #####
- id: dimslider
name: ${name} dim brightness slider
name: dim brightness slider
platform: nextion
variable_name: dimslider
internal: true
@@ -1355,7 +1368,7 @@ sensor:
###### Display Brightness - Current value (%) #####
- id: current_brightness
name: ${name} Display Current brightness
name: Display Current brightness
platform: nextion
variable_name: dim
precision: 0
@@ -1373,7 +1386,7 @@ sensor:
###### Page Id - Current #####
- id: page_id
name: ${name} Page Id
name: Page Id
platform: nextion
variable_name: dp
precision: 0
@@ -1396,7 +1409,7 @@ sensor:
##### Display mode (1 = EU, 2 = US, 3 = US Landscape)
- id: display_mode
name: ${name} Display mode
name: Display mode
platform: nextion
variable_name: display_mode
precision: 0
@@ -1406,7 +1419,7 @@ sensor:
entity_category: diagnostic
##### Charset (1 = International (original), 2 = CJK languages)
- name: ${name} Display charset
- name: Display charset
id: display_charset
platform: nextion
variable_name: charset
@@ -1417,7 +1430,7 @@ sensor:
entity_category: diagnostic
##### Wi-Fi Signal stregth
- name: ${name} RSSI
- name: RSSI
id: wifi_rssi
platform: wifi_signal
internal: false
@@ -1429,7 +1442,7 @@ sensor:
switch:
##### Notification unread #####
- name: ${name} Notification unread
- name: Notification unread
platform: template
id: notification_unread
entity_category: config
@@ -1447,7 +1460,7 @@ switch:
- lambda: set_component_color->execute("home.bt_notific", id(home_notify_icon_color_normal));
##### Notification sound #####
- name: ${name} Notification sound
- name: Notification sound
platform: template
id: notification_sound
entity_category: config
@@ -1455,7 +1468,7 @@ switch:
restore_mode: RESTORE_DEFAULT_OFF
##### PHYSICAL SWITCH 1 #####
- name: ${name} Relay 1
- name: Relay 1
platform: gpio
id: relay_1
pin:
@@ -1468,7 +1481,7 @@ switch:
then:
- script.execute: refresh_relays
##### PHYSICAL SWITCH 2 ######
- name: ${name} Relay 2
- name: Relay 2
platform: gpio
id: relay_2
pin:
@@ -1482,7 +1495,7 @@ switch:
- script.execute: refresh_relays
##### DISPLAY ALWAYS ON #####
- name: ${name} Nextion display - Power
- name: Nextion display - Power
platform: gpio
id: screen_power
entity_category: diagnostic
@@ -1507,7 +1520,7 @@ switch:
nextion_init->publish_state(false);
##### Relay Local control #####
- name: ${name} Relay 1 Local
- name: Relay 1 Local
platform: template
id: relay1_local
entity_category: config
@@ -1518,7 +1531,7 @@ switch:
- logger.log: "Relay 1 Local turned On!"
on_turn_off:
- logger.log: "Relay 1 Local turned Off!"
- name: ${name} Relay 2 Local
- name: Relay 2 Local
platform: template
id: relay2_local
entity_category: config
@@ -1535,7 +1548,7 @@ text_sensor:
##### Device name - Used for the Blueprint to identify service names when device is renamed
- id: device_name
name: ${name} Device name
name: Device name
internal: false
platform: template
update_interval: never
@@ -1555,7 +1568,7 @@ text_sensor:
- "__ -> _"
##### Entity Id of the entity displayed on the detailed pages
- name: ${name} Detailed Entity
- name: Detailed Entity
id: detailed_entity
platform: template
icon: mdi:tablet-dashboard
@@ -1563,23 +1576,23 @@ text_sensor:
disabled_by_default: false
##### Current page name #####
- name: ${name} Current page
- name: Current page
id: current_page
platform: template
icon: mdi:tablet-dashboard
internal: false
disabled_by_default: false
- name: ${name} Notification Label
- name: Notification Label
platform: template
id: notification_label
- name: ${name} Notification Text
- name: Notification Text
platform: template
id: notification_text
##### NSPanel event sensor, the main action sensor - push to HA #####
- name: ${name} NSPanel event
- name: NSPanel event
platform: nextion
nextion_id: disp1
id: disp1_nspanel_event
@@ -1617,7 +1630,7 @@ text_sensor:
});
##### NSPanel event - Execute actions from ESPHome - NO push to HA #####
- name: ${name} NSPanel local event
- name: NSPanel local event
platform: nextion
nextion_id: disp1
id: disp1_local_event
@@ -1709,7 +1722,7 @@ text_sensor:
##### Versioning #####
- id: version_blueprint
name: ${name} Version Blueprint
name: Version Blueprint
platform: template
entity_category: diagnostic
icon: mdi:tag-text-outline
@@ -1730,7 +1743,7 @@ text_sensor:
check_versions->execute();
- id: version_esphome
name: ${name} Version ESPHome
name: Version ESPHome
platform: template
entity_category: diagnostic
icon: mdi:tag-text-outline
@@ -1751,7 +1764,7 @@ text_sensor:
check_versions->execute();
- id: version_tft
name: ${name} Version TFT
name: Version TFT
platform: nextion
component_name: tft_version
entity_category: diagnostic
@@ -1835,8 +1848,12 @@ script:
mode: restart
then:
- lambda: |-
if (id(embedded_indoor_temp) or (!wifi_component->is_connected()) or (!api_server->is_connected()))
disp1->set_component_text_printf("home.current_temp", "%.1f${temp_units}", temp_nspanel->state);
if (id(embedded_indoor_temp) or (!wifi_component->is_connected()) or (!api_server->is_connected())) {
float unit_based_temperature = temp_nspanel->state;
if ("${temp_units}" == "°F" or "${temp_units}" == "°f" or "${temp_units}" == "F" or "${temp_units}" == "f")
unit_based_temperature = (unit_based_temperature * 9 / 5) + 32;
disp1->set_component_text_printf("home.current_temp", "%.1f${temp_units}", unit_based_temperature);
}
- id: display_wrapped_text
mode: queued
@@ -1879,17 +1896,17 @@ script:
- logger.log: "Exit reparse"
- uart.write: "DRAKJHSUYDGBNCJHGJKSHBDN"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "recmod=0"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "recmod=0"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "connect"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: [0xFF, 0xFF]
- uart.write: "connect"
- uart.write: [0xFF, 0xFF, 0xFF]
- uart.write: "bkcmd=3"
- uart.write: [0xFF, 0xFF, 0xFF]
# - uart.write: "recmod=0"
# - uart.write: [0xFF, 0xFF, 0xFF]
# - uart.write: "recmod=0"
# - uart.write: [0xFF, 0xFF, 0xFF]
# - uart.write: "connect"
# - uart.write: [0xFF, 0xFF, 0xFF]
# - uart.write: [0xFF, 0xFF]
# - uart.write: "connect"
# - uart.write: [0xFF, 0xFF, 0xFF]
# - uart.write: "bkcmd=3"
# - uart.write: [0xFF, 0xFF, 0xFF]
- id: global_settings
mode: restart
@@ -2720,19 +2737,22 @@ script:
- lambda: |-
static const char *const TAG = "script.setup_sequence";
ESP_LOGD(TAG, "Starting Nextion setup sequence");
ESP_LOGD(TAG, "Fetching page id");
ESP_LOGD(TAG, "Fetching TFT info");
display_mode->update();
display_charset->update();
version_tft->update();
page_id->update();
- wait_until:
condition:
- lambda: !lambda return (page_id->state > 0);
timeout: 5s
- lambda: !lambda return (not isnan(page_id->state));
timeout: 15s
- lambda: |-
static const char *const TAG = "script.setup_sequence";
ESP_LOGD(TAG, "Fetching charset");
display_charset->update();
- wait_until:
condition:
- lambda: !lambda return (display_charset->state > 0);
- lambda: !lambda return (not isnan(display_charset->state));
timeout: 5s
- lambda: |-
static const char *const TAG = "script.setup_sequence";
@@ -2740,11 +2760,11 @@ script:
display_mode->update();
- wait_until:
condition:
- lambda: !lambda return (display_mode->state > 0);
- lambda: !lambda return (not isnan(display_mode->state));
timeout: 5s
- if:
condition:
- lambda: !lambda return (display_mode->state > 0);
- lambda: !lambda return (not isnan(display_mode->state));
then: # Project's TFT detected
- lambda: |-
static const char *const TAG = "script.setup_sequence";