7 segment clock by random1101 for ESPHome by Alex18881 3d model
3dmdb logo
Thingiverse
7 segment clock by random1101 for ESPHome by Alex18881

7 segment clock by random1101 for ESPHome by Alex18881

by Thingiverse
Last crawled date: 3 years, 4 months ago
This is the electronics remix for the 7 segment clock made by random1101.
It uses the ESP-01s for everything.
Once it connected to the Home Assistant it may be controlled over the entity card. It supports separate color, brightness and on/off for hours, minutes and colon parts of the clock. Current time is syncronised with SNTP servers. Note: if you prefere to use static IP is't important to configure at leat 1 DNS server in WIFI section of the config (in my case I use the IP of my router).
WARNING There're 2 modifications of ESP-01 one has 1MB of flash memory and one with only 512kb. The firmware compiled from this configuration takes about 36kb of RAM and 404.5kb of Flash memory. If you have a 512kb there will be no room for the firmware for OTA updates.
Electronics BOM:
1) ESP-01s
2) 5v to 3.3v downshifter to power ESP-01s like this
3) Any 5v wall plug power supply on about 1 amp of current
PS, I'm still a noob in electronics. Please feel free in pointing me if there's any mistace in wiring schematics. Thanks
ESPHome configuration
substitutions:
device_name: led_clock

esphome:
name: $device_name
platform: ESP8266
board: esp01_1m
on_boot:
- light.turn_on:
id: led_strip
brightness: 100%
red: 0
green: 0
blue: 0
effect: "${device_name} Time effect"

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${device_name} Fallback Hotspot"
password: !secret wifi_fallback_api_password

logger:
level: DEBUG
# Enable Home Assistant API
api:
password: !secret hassio_api_password

ota:
password: !secret ota_password

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'

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;

time:
- platform: sntp
id: sntp_time
timezone: "Europe/Moscow"
servers:
- 0.pool.ntp.org
- 1.pool.ntp.org
- 2.pool.ntp.org

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: fastled_clockless
id: led_strip
name: "Led strip"
internal: True
pin: GPIO3
num_leds: 30
chipset: WS2812B
rgb_order: 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] = {
{0,1,3,4,5,6,-1},
{3,6,-1,-1,-1,-1,-1},
{0,1,2,3,4,-1,-1},
{0,2,3,4,6,-1,-1},
{2,3,5,6,-1,-1,-1},
{0,2,4,5,6,-1,-1},
{0,1,2,4,5,6,-1},
{3,4,6,-1,-1,-1,-1},
{0,1,2,3,4,5,6},
{0,2,3,4,5,6,-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 / 10;
values[1] = time.hour % 10;
values[2] = time.minute / 10;
values[3] = time.minute % 10;

it.all() = ESPColor::BLACK;

if ((time.second % 2) > 0) {
it[14] = ESPColor(id(dots_red_value), id(dots_green_value), id(dots_blue_value));
it[15] = ESPColor(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 = leds[ledI] + ledsOffset;
it[ledIndex] = ESPColor(color[0], color[1], color[2]);
}
}
}

Tags