Hi all, let me start off by saying… I am NOT a programmer, more of a hobbyist with IT experience. I’m building a clock using ESP8266. The base code is working as expected but I’m noticing the SNTP is not syncing, so on a fresh boot the time is not correct.
I am trying to add automation to run a sync every hour, and an input boolean to allow manual sync from HA.
I will admit, most of this has been generated with ChatGPT because I have no idea what I’m doing… any assistance is greatly appreciated!
The compile error:
INFO ESPHome 2023.11.6
INFO Reading configuration /config/led-clock.yaml...
Failed config
input_boolean: [source /config/led-clock.yaml:75]
Component not found: input_boolean.
- id: sntp_sync_manual
name: SNTP Manual Sync
initial: False
automation: [source /config/led-clock.yaml:80]
Component not found: automation.
- id: sync_sntp_startup
alias: Sync SNTP at Startup
trigger:
- platform: homeassistant
event: start
action:
- sntp.sync_time: sntp_time
- id: sync_sntp_hourly
alias: Sync SNTP Hourly
trigger:
- platform: time
at: 00:00:00
action:
- sntp.sync_time: sntp_time
- id: sync_sntp_manual
alias: Sync SNTP Manual
trigger:
- platform: state
entity_id: input_boolean.sntp_sync_manual
to: on
action:
- sntp.sync_time: sntp_time
- service: input_boolean.turn_off
target:
entity_id: input_boolean.sntp_sync_manual
The code:
api:
encryption:
key: "XXXX"
ota:
password: "XXXX"
wifi:
ssid: "XXXX"
password: "XXXX"
manual_ip:
static_ip: 192.168.2.58
gateway: 192.168.2.1
subnet: 255.255.255.0
substitutions:
device_name: led-clock
esphome:
name: led-clock
platform: ESP8266
board: d1_mini
logger:
level: DEBUG
globals:
- id: hours_red_value
type: int
restore_value: yes
initial_value: '0'
- id: hours_green_value
type: int
restore_value: yes
initial_value: '0'
- id: hours_blue_value
type: int
restore_value: yes
initial_value: '0'
- id: minutes_red_value
type: int
restore_value: yes
initial_value: '0'
- id: minutes_green_value
type: int
restore_value: yes
initial_value: '0'
- id: minutes_blue_value
type: int
restore_value: yes
initial_value: '0'
- id: dots_red_value
type: int
restore_value: yes
initial_value: '0'
- id: dots_green_value
type: int
restore_value: yes
initial_value: '0'
- id: dots_blue_value
type: int
restore_value: yes
initial_value: '0'
input_boolean:
- id: sntp_sync_manual
name: "SNTP Manual Sync"
initial: off
automation:
- id: sync_sntp_startup
alias: "Sync SNTP at Startup"
trigger:
- platform: homeassistant
event: start
action:
- sntp.sync_time: sntp_time
- id: sync_sntp_hourly
alias: "Sync SNTP Hourly"
trigger:
- platform: time
at: "00:00:00"
action:
- sntp.sync_time: sntp_time
- id: sync_sntp_manual
alias: "Sync SNTP Manual"
trigger:
- platform: state
entity_id: input_boolean.sntp_sync_manual
to: "on"
action:
- sntp.sync_time: sntp_time
- service: input_boolean.turn_off
target:
entity_id: input_boolean.sntp_sync_manual
time:
- platform: sntp
id: sntp_time
timezone: "US/Eastern"
servers:
- 0.ca.pool.ntp.org
- 1.ca.pool.ntp.org
- 2.ca.pool.ntp.org
output:
#======== Hours ============
- platform: template
id: hours_red_output
type: float
write_action:
lambda: |-
id(hours_red_value) = 255.0 * state;
- platform: template
id: hours_green_output
type: float
write_action:
- lambda: |-
id(hours_green_value) = 255.0 * state;
- platform: template
id: hours_blue_output
type: float
write_action:
lambda: |-
id(hours_blue_value) = 255.0 * state;
#========= Minutes ===========
- platform: template
id: minutes_red_output
type: float
write_action:
lambda: |-
id(minutes_red_value) = 255.0 * state;
- platform: template
id: minutes_green_output
type: float
write_action:
lambda: |-
id(minutes_green_value) = 255.0 * state;
- platform: template
id: minutes_blue_output
type: float
write_action:
lambda: |-
id(minutes_blue_value) = 255.0 * state;
#========= Dots ===========
- platform: template
id: dots_red_output
type: float
write_action:
lambda: |-
id(dots_red_value) = 255.0 * state;
- platform: template
id: dots_green_output
type: float
write_action:
lambda: |-
id(dots_green_value) = 255.0 * state;
- platform: template
id: dots_blue_output
type: float
write_action:
lambda: |-
id(dots_blue_value) = 255.0 * state;
light:
- platform: rgb
name: "${device_name} Hours Lights"
id: 'hours_lights'
red: hours_red_output
green: hours_green_output
blue: hours_blue_output
- platform: rgb
name: "${device_name} Minutes Lights"
id: 'minutes_lights'
red: minutes_red_output
green: minutes_green_output
blue: minutes_blue_output
- platform: rgb
name: "${device_name} Dots Lights"
id: 'dots_lights'
red: dots_red_output
green: dots_green_output
blue: dots_blue_output
#========= LED Strip ===========
- platform: neopixelbus
id: led_strip
name: "LED Strip"
internal: true
pin: D4
num_leds: 30
variant: WS2812
type: GRB
effects:
- addressable_lambda:
name: "${device_name} Time Effect"
update_interval: 200ms
lambda: |-
const int ledsInDigitCount = 7;
const int digitsCount = 4;
int digitsLeds[10][ledsInDigitCount] = {
{1,1,0,1,1,1,1},
{0,0,0,1,0,0,1},
{1,1,1,1,1,0,0},
{1,0,1,1,1,0,1},
{0,0,1,1,0,1,1},
{1,0,1,0,1,1,1},
{1,1,1,0,1,1,1},
{0,0,0,1,1,0,1},
{1,1,1,1,1,1,1},
{1,0,1,1,1,1,1}
};
int ledOffsets[digitsCount] = {23 , 16, 7, 0};
auto time = id(sntp_time).now();
int colors[4][3] = {
{id(hours_red_value), id(hours_green_value), id(hours_blue_value)},
{id(hours_red_value), id(hours_green_value), id(hours_blue_value)},
{id(minutes_red_value), id(minutes_green_value), id(minutes_blue_value)},
{id(minutes_red_value), id(minutes_green_value), id(minutes_blue_value)}
};
int values[digitsCount] = {};
values[0] = (time.hour % 12) / 10;
values[1] = (time.hour % 12) % 10;
values[2] = time.minute / 10;
values[3] = time.minute % 10;
it.all() = Color(0,0,0);
if ((time.second % 2) > 0) {
it[14] = Color(id(dots_red_value), id(dots_green_value), id(dots_blue_value));
it[15] = Color(id(dots_red_value), id(dots_green_value), id(dots_blue_value));
}
for (int valueI = 0; valueI < digitsCount; valueI++) {
int ledsOffset = ledOffsets[valueI];
int timeValue = values[valueI];
int *color = colors[valueI];
int *leds = digitsLeds[timeValue];
for (int ledI = 0; ledI < ledsInDigitCount; ledI++) {
if(leds[ledI] > 0) {
int ledIndex = ledI + ledsOffset;
it[ledIndex] = Color(color[0], color[1], color[2]);
}
}
}