fix esphome reboots on no wifi
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
############################################################################################
|
||||
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
|
||||
# If NOT using a secrets file, just replace
|
||||
# If NOT using a secrets file, just replace
|
||||
# these with the values (in quotes)
|
||||
###########################################################################################
|
||||
substitutions:
|
||||
@@ -25,10 +25,10 @@ time:
|
||||
# Change sync interval from default 5min to 6 hours (or as set in substitutions)
|
||||
update_interval: ${sntp_update_interval}
|
||||
# Set specific sntp servers to use
|
||||
servers:
|
||||
servers:
|
||||
- "${sntp_server_1}"
|
||||
- "${sntp_server_2}"
|
||||
- "${sntp_server_3}"
|
||||
- "${sntp_server_3}"
|
||||
# Publish the time the device was last restarted
|
||||
on_time_sync:
|
||||
then:
|
||||
@@ -65,11 +65,27 @@ text_sensor:
|
||||
update_interval: "1min"
|
||||
entity_category: diagnostic
|
||||
lambda: |-
|
||||
auto time_text = id(sntp_time).now().strftime("%H:%M:%S - %d-%m-%Y");
|
||||
return { time_text };
|
||||
// If SNTP time is valid, show real time/date.
|
||||
if (id(sntp_time).now().is_valid()) {
|
||||
auto t = id(sntp_time).now().strftime("%H:%M:%S - %d-%m-%Y");
|
||||
return { t };
|
||||
}
|
||||
|
||||
// Fallback: show internal clock based on current_mins (minutes from midnight).
|
||||
// NOTE: current_mins is expected to be a global defined in the main device YAML.
|
||||
int mins = id(current_mins);
|
||||
if (mins < 0) mins = 0;
|
||||
if (mins >= 1440) mins = mins % 1440;
|
||||
|
||||
int hour = mins / 60;
|
||||
int minute = mins % 60;
|
||||
|
||||
char buff[32];
|
||||
snprintf(buff, sizeof(buff), "%02d:%02d (fallback)", hour, minute);
|
||||
return { std::string(buff) };
|
||||
|
||||
- platform: template
|
||||
name: "Time: Sync Status"
|
||||
id: time_sync
|
||||
update_interval: "1min"
|
||||
entity_category: diagnostic
|
||||
entity_category: diagnostic
|
||||
|
||||
Reference in New Issue
Block a user