Skip to content

Commit

Permalink
Basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
trip5 committed Sep 8, 2023
1 parent 5a9d429 commit dedf948
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 1 deletion.
291 changes: 291 additions & 0 deletions EHLPClock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
substitutions:
name: led-pixelclock-blue
friendly_name: Led-PixelClock-Blue
waiting: " EHLPC " # shows when waiting for time
time_zone: "Asia/Seoul" # This will be your 'home' Timezone. Check https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
scl_pin: GPIO5
sda_pin: GPIO4
clk_pin: GPIO14
mosi_pin: GPIO13
cs_pin: GPIO15
status_led_pin: GPIO2
download_button_pin: GPIO0
rotation_pin: GPIO16

esphome:
name: $name
comment: "EHLPClock from Trip5"
project:
name: "Trip5.EspHomeLedPixelClock"
version: "2023.09.00"

esp8266:
board: esp12e
restore_from_flash: True

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

font:
- file: ehmtxv2/MatrixClock-Chunky8X.bdf #
id: default_font
glyphs: |
! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz°
- file: ehmtxv2/MatrixClock-Light8X.bdf #
id: message_font
glyphs: |
! "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz°{|}~¡¢£¤¥¦§¨©ª«¬®¯±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
time:
- platform: sntp
# If you would rather use Home Assistant as a time source, delete the above line and uncomment the next line (but sntp means you can take your clock anywhere)
# - platform: homeassistant
timezone: "$time_zone"
update_interval: 8h
- platform: ds1307 # Even though it's a ds3231
id: my_time
timezone: "$time_zone"
update_interval: never

api:
services:
# This next section creates the Home Assistant services to allow messages to be displayed
- service: message
variables:
message: string
message_alive_time: int
message_display_time: int
message_clock_time: int
then:
- globals.set:
id: message
value: !lambda 'return message;'
- globals.set:
id: message_alive_time
value: !lambda 'return message_alive_time;'
- globals.set:
id: message_display_time
value: !lambda 'return message_display_time;'
- globals.set:
id: message_clock_time
value: !lambda 'return message_clock_time;'
- globals.set:
id: message_clock_time_count
value: !lambda 'return message_clock_time;'
- globals.set:
id: message_alive_time_count
value: '0'
- logger.log:
format: "Message: %s"
args: [ 'message.c_str()' ]
- logger.log:
format: "Alive Time: %i / Display Time: %i / Clock Time: %i"
args: [ 'message_alive_time', 'message_display_time' , 'message_clock_time' ]

mdns:
disabled: false

logger:

ota:
password: !secret ota_password

web_server:
port: 80
ota: true
include_internal: true

captive_portal:

text_sensor:
- platform: version
name: "ESPHome Version"
hide_timestamp: true
internal: true
- platform: wifi_info
ip_address:
id: wifi_ip
name: "$friendly_name IP Address"
ssid:
id: wifi_ssid
name: "$friendly_name SSID"

status_led:
pin:
number: $status_led_pin
inverted: true

preferences:
flash_write_interval: 15s # 0 does immediate write to memory with no mem buffer (not recommended) (only saves when persistent variables have changed)

i2c:
sda: $sda_pin
scl: $scl_pin
scan: true
id: i2cbus

spi:
clk_pin: $clk_pin
mosi_pin: $mosi_pin

# Check this section carefully!
# Also, some info how to handle multi_click options: https://community.home-assistant.io/t/esphome-button-held-double-press/136083/10
binary_sensor:
- platform: status
name: "$friendly_name Status"
- platform: gpio
pin:
number: $download_button_pin
inverted: true
name: "$friendly_name Download Button"
filters:
- delayed_on: 10ms
- delayed_off: 10ms
on_multi_click:
#Click will toggle 12-hour mode
- timing:
- ON for at most 0.5s
- OFF for at least 0.5s
then:
- switch.toggle: hour12_select
#Hold will show the IP Address
- timing:
- ON for at least 1s
then:
- button.press: display_ip
- platform: gpio
pin:
number: $rotation_pin
inverted: true
name: "$friendly_name Rotation Mode"
id: rotation_mode

display:
# https://community.home-assistant.io/t/reusable-function-for-lambdas/296435/10
- platform: max7219digit
cs_pin: $cs_pin
num_chips: 4
update_interval: 1s
reverse_enable: true # true for button-side up / false for down
rotate_chip: 0 # 0 for button-side up (default) / 180 for down
scroll_mode: continuous
lambda: |-
// Display the message if all conditions are met
if (id(my_time).now().is_valid()) {
if ((id(message_alive_time) != 0) && (id(message_clock_time_count) >= id(message_clock_time))) {
id(message_display_time_count) += 1;
id(message_alive_time_count) += 1;
auto message_text = id(message);
it.print(0, 0, id(message_font), message_text.c_str());
if (id(message_display_time_count) >= id(message_display_time)) {
id(message_display_time_count) = 0;
id(message_clock_time_count) = 0;
if (id(message_alive_time_count) >= id(message_alive_time)) {
id(message_alive_time_count) = 0;
id(message_alive_time) = 0;
ESP_LOGD("main", "Message Alive Time finished.");
}
}
} else {
if ((id(message_alive_time) != 0) && (id(message_clock_time) != 0)) {
id(message_clock_time_count) += 1;
id(message_alive_time_count) += 1;
}
if (id(hour12_mode) == 1) {
it.strftime((32 / 2), (8 / 2), id(default_font), TextAlign::CENTER, "%l:%M%p", id(my_time).now());
} else {
it.strftime((32 / 2), (8 / 2), id(default_font), TextAlign::CENTER, "%H:%M", id(my_time).now());
}
}
} else {
it.print((32 / 2), (8 / 2), id(default_font), TextAlign::CENTER, "$waiting");
}
it.intensity(id(brightness_level));
globals:
- id: brightness_level
type: int
restore_value: true
initial_value: '1'
- id: hour12_mode
type: bool
restore_value: true
initial_value: 'false'
- id: message
type: std::string
restore_value: false
initial_value: ''
- id: message_display_time
type: int
restore_value: false
initial_value: '0'
- id: message_clock_time
type: int
restore_value: false
initial_value: '0'
- id: message_alive_time
type: int
restore_value: false
initial_value: '0'
- id: message_display_time_count
type: int
restore_value: false
initial_value: '0'
- id: message_clock_time_count
type: int
restore_value: false
initial_value: '0'
- id: message_alive_time_count
type: int
restore_value: false
initial_value: '0'

button:
- platform: restart
id: "Restart"
internal: true
- platform: template
id: display_ip
name: "Display IP Address"
internal: true
on_press:
- lambda: |-
id(message_alive_time) = 10;
id(message_display_time) = 10;
id(message_clock_time) = 0;
id(message) = (" IP " + id(wifi_ip).state);
switch:
- platform: template
name: "$friendly_name 12 Hour Mode"
id: hour12_select
restore_mode: RESTORE_DEFAULT_OFF
lambda: |-
if (id(hour12_mode)) {
return true;
} else {
return false;
}
turn_on_action:
lambda: |-
id(hour12_mode) = true;
turn_off_action:
lambda: |-
id(hour12_mode) = false;
number:
- platform: template
name: "$friendly_name Brightness"
id: brightness_select
restore_value: true
optimistic: true
step: 1
min_value: 0
max_value: 15
mode: slider
set_action:
then:
lambda: |-
id(brightness_level) = x;
ESP_LOGD("main", "Brightness: %d", id(brightness_level));
Loading

0 comments on commit dedf948

Please sign in to comment.