Skip to content

Instantly share code, notes, and snippets.

@bram2202
Created April 2, 2021 09:16
Show Gist options
  • Save bram2202/c9c8e7d7ff4f5a53dae7660416e8a633 to your computer and use it in GitHub Desktop.
Save bram2202/c9c8e7d7ff4f5a53dae7660416e8a633 to your computer and use it in GitHub Desktop.
Led ring for displaying seconds, and red/blue strobe on command
esphome:
name: esp_unifi_clock
platform: ESP8266
board: esp01_1m
on_boot:
priority: -10
then:
- light.turn_on:
id: ring
brightness: 100%
effect: Clock
wifi:
<xxxx>
logger:
api:
password: "<xxxx>"
ota:
password: "<xxxx>"
time:
- platform: homeassistant
id: "sys_time"
light:
- platform: fastled_clockless
id: ring
chipset: WS2812B
pin: GPIO3
num_leds: 16
name: "clock_ring"
rgb_order: GRB
effects:
- strobe:
name: Strobe red
colors:
- state: True
brightness: 100%
red: 100%
green: 0%
blue: 0%
duration: 500ms
- state: False
duration: 250ms
- strobe:
name: Strobe blue
colors:
- state: True
brightness: 100%
red: 0%
green: 0%
blue: 100%
duration: 500ms
- state: False
duration: 250ms
- addressable_lambda:
name: Clock
update_interval: 500ms
lambda: |-
// Set all to black
it.all() = ESPColor::BLACK;
// Show wait on time
it[0] = ESPColor(0, 255, 0);
it[8] = ESPColor(255, 0, 0);
// Wait on time
auto time = id(sys_time).now();
if (!time.is_valid()) {
return;
}
// Calculate second led
float leds = (float)it.size();
float seconds = (float)time.second;
int ledNumber = nearbyint((leds/(float)60)*seconds);
if(ledNumber > 15){
ledNumber = 15;
}
// Set color to correct led
for (int i = 0; i < it.size(); i++) {
if(i == ledNumber){
it[i] = ESPColor(0, 0, 255);
}else{
it[i] = ESPColor::BLACK;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment