Skip to content

Instantly share code, notes, and snippets.

@joer14
Last active June 16, 2025 22:14
Show Gist options
  • Save joer14/7e9bf2b1d05888df4bfe822f3970a966 to your computer and use it in GitHub Desktop.
Save joer14/7e9bf2b1d05888df4bfe822f3970a966 to your computer and use it in GitHub Desktop.
esphome:
name: esp32s3-matrix
friendly_name: ESP32-S3 Matrix
min_version: 2024.11.0
name_add_mac_suffix: false
on_boot:
priority: 600
then:
- light.turn_on:
id: matrix_leds
brightness: 50%
effect: "Center Ripple"
- globals.set:
id: contact_sensor_open
value: 'false'
- globals.set:
id: is_atv_playing
value: 'false'
esp32:
board: esp32-s3-devkitc-1
framework:
type: arduino
logger:
api:
ota:
platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
captive_portal:
globals:
- id: contact_sensor_open
type: bool
restore_value: no
initial_value: 'false'
- id: is_atv_playing
type: bool
restore_value: no
initial_value: 'false'
- id: all_doors_locked_global
type: bool
restore_value: no
initial_value: 'false'
- id: all_contact_except_frontdoor
type: bool
restore_value: no
initial_value: 'false'
- id: freezer
type: bool
restore_value: no
initial_value: 'false'
binary_sensor:
- platform: homeassistant
id: any_contact_sensor_open
entity_id: binary_sensor.any_contact_sensor
on_press:
then:
- globals.set:
id: contact_sensor_open
value: 'true'
on_release:
then:
- globals.set:
id: contact_sensor_open
value: 'false'
- platform: homeassistant
id: all_doors_locked
entity_id: binary_sensor.all_doors_locked
on_press:
then:
- globals.set:
id: all_doors_locked_global
value: 'true'
on_release:
then:
- globals.set:
id: all_doors_locked_global
value: 'false'
- platform: homeassistant
id: all_contact_except_frontdoor_sensor
entity_id: binary_sensor.all_contact_except_frontdoor
on_press:
then:
- globals.set:
id: all_contact_except_frontdoor
value: 'true'
on_release:
then:
- globals.set:
id: all_contact_except_frontdoor
value: 'false'
- platform: homeassistant
id: freezer_sensor
entity_id: binary_sensor.aqara_door_and_window_sensor_door_3
on_press:
then:
- globals.set:
id: freezer
value: 'true'
on_release:
then:
- globals.set:
id: freezer
value: 'false'
text_sensor:
- platform: homeassistant
id: apple_tv_state
entity_id: media_player.appletv
internal: true
on_value:
then:
- lambda: |-
id(is_atv_playing) = (x == "playing");
light:
- platform: esp32_rmt_led_strip
id: matrix_leds
name: "Matrix LEDs"
chipset: ws2812
pin: GPIO14
num_leds: 64
rgb_order: RGB
rmt_channel: 0
restore_mode: ALWAYS_ON
default_transition_length: 0s
gamma_correct: 2.0
effects:
- addressable_lambda:
name: "Center Ripple"
update_interval: 30ms
lambda: |-
static float ripple_time = 0.0f;
ripple_time += 0.03f;
const float center_x = 3.5f;
const float center_y = 3.5f;
static int blink_counter = 0;
blink_counter = (blink_counter + 1) % 34;
bool blink_on = blink_counter < 17;
bool only_front_door_open = id(all_contact_except_frontdoor);
// Track which mode is currently active
static std::string last_mode = "";
std::string current_mode;
for (int i = 0; i < it.size(); i++) {
it[i] = Color::BLACK; // Reset pixel
int x = i % 8;
int y = i / 8;
float dx = x - center_x;
float dy = y - center_y;
float distance = sqrtf(dx * dx + dy * dy);
float wave = (sinf(distance - ripple_time) + 1.0f) / 2.0f;
if (id(freezer)) {
current_mode = "FREEZER_OPEN → BLINKING BLUE";
if (blink_on) {
float brightness = 0.1f + (wave * 0.5f);
it[i] = Color(0, 0, brightness * 255);
}
continue;
}
if (id(is_atv_playing)) {
current_mode = "TV_PLAYING → BLACK";
continue;
}
if (only_front_door_open && id(all_doors_locked_global)) {
current_mode = "ONLY_FRONT_DOOR_OPEN → BLINKING GREEN";
if (blink_on) {
float brightness = 0.1f + (wave * 0.5f);
it[i] = Color(0, brightness * 255, 0);
}
continue;
}
if (id(contact_sensor_open)) {
current_mode = "CONTACT_OPEN → RED";
float brightness = 0.1f + (wave * 0.8f);
it[i] = Color(brightness * 255, brightness * 50, 0);
continue;
}
if (!id(all_doors_locked_global)) {
current_mode = "DOORS_UNLOCKED → AMBER";
float brightness = 0.1f + (wave * 0.3f);
it[i] = Color(brightness * 255, brightness * 160, 0);
continue;
}
current_mode = "ALL_SECURE → GREEN";
float brightness = 0.05f + (wave * 0.2f);
it[i] = Color(0, brightness * 200, 0);
}
// Only log when the mode changes (to reduce log spam)
if (current_mode != last_mode) {
ESP_LOGI("matrix_mode", "Switched to mode: %s", current_mode.c_str());
last_mode = current_mode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment