Untitled
esphome: name: tesla-lights friendly_name: Tesla Lights platformio_options: board_build.flash_mode: dio esp32: board: seeed_xiao_esp32c3 variant: esp32c3 framework: type: arduino platform_version: 6.9.0 # Enable logging logger: sensor: - platform: homeassistant id: "id_tesla_battery_percentage_from_ha" entity_id: sensor.iceman_battery_level #unit_of_measurement: "%" device_class: battery state_class: "measurement" external_components: - source: github://pr#4257 components: [fastled] refresh: always # LED Control (FastLED) light: - platform: fastled name: "LED Matrix" data_pin: GPIO3 num_leds: 256 # Total number of LEDs in the strip chipset: WS2812B # Type of LEDs you're using (change if different) rgb_order: GRB internal: false restore_mode: RESTORE_DEFAULT_ON effects: - addressable_lambda: name: "Tesla battery level" lambda: |- const int leds_to_use = it.size(); // you can change that if you don't want all the leds to be used Color green = Color(0x00FF00); Color yellow = Color(0xFFFF00); Color red = Color(0xFF0000); float battery_percentage = id(id_tesla_battery_percentage_from_ha).state; if (isnan(battery_percentage)) { battery_percentage = 0; } current_color = green; if (battery_percentage < 40.0) { current_color = yellow; } if (battery_percentage < 20.0) { current_color = red; } // number of leds that are drawn with full brightness int full_leds = int(leds_to_use*battery_percentage/100.0); // set those leds to the current_color of the light it.range(0, full_leds) = current_color; // if full_leds is not the last led, render a remaining fraction of a led dimmed if (full_leds < leds_to_use) { it[full_leds] = current_color*((leds_to_use*battery_percentage/100.0-full_leds)*255); } // set the remaing leds to black if (full_leds+1 < leds_to_use) { it.range(full_leds+1, leds_to_use) = Color::BLACK; // change the color to something else if you want } - addressable_fireworks: name: Fireworks Effect With Custom Values update_interval: 32ms spark_probability: 10% use_random_color: false fade_out_rate: 120 captive_portal:
Leave a Comment