Closed ax42 closed 2 years ago
I would like to see this feature as well.
If someone else wonders how to do this with partitions and call it from the Home Assistant then here is an example for m5stack atom matrix turning on the 2x2 leds on the top-left corner of the led matrix. The leds of Atom Matrix gets quite hot if the brightness is 100% for longer time so I set the brightness here to the recommended 20%. For short flashes 100% brightness is just fine.
light:
# Light segment source M5Stack Atom Matrix:
- platform: fastled_clockless
chipset: WS2812B
pin: 27
num_leds: 25
rgb_order: GRB
id: matrix_led
name: Atom Matrix Light
# Partitions:
- platform: partition
name: Atom Matrix Light Partition 1
id: matrix_led_partition_1
segments:
- id: matrix_led
from: 0
to: 1
- platform: partition
name: Atom Matrix Light Partition 2
id: matrix_led_partition_2
segments:
- id: matrix_led
from: 5
to: 6
# Enable Home Assistant API
api:
services:
# Turn on leds on top-left corner
- service: matrix_top_left_on
variables:
red: int # color values between 0-255
green: int
blue: int
then:
- light.turn_on:
id: matrix_led_partition_1
transition_length: 0s
brightness: 20% # NOTE: recommended brightness level is 20%
red: !lambda 'return red;'
green: !lambda 'return green;'
blue: !lambda 'return blue;'
- light.turn_on:
id: matrix_led_partition_2
transition_length: 0s
brightness: 20%
red: !lambda 'return red;'
green: !lambda 'return green;'
blue: !lambda 'return blue;'
I found out that you can also configure Display component to use led matrix. You need to set the platform as addressable_light
as explained here: https://esphome.io/components/display/addressable_light.html
Using Display component takes control of the leds and you can the use display rendering engine commands, eg. rectangle
, to control what individual leds are on in the matrix. Here is the same example as before of turning on 2x2 leds on the top-left corner with m5stack atom matrix using Addressable Light platform feature. The API service simply sets global variables of the colors. The display component will then automatically change the color of leds accordingly.
# Configuration of global variables
globals:
- id: color_red
type: int
initial_value: '0'
- id: color_green
type: int
initial_value: '0'
- id: color_blue
type: int
initial_value: '0'
# Main light configuration
light:
- platform: fastled_clockless
chipset: WS2812B
pin: 27
num_leds: 25
rgb_order: GRB
id: matrix_led
name: Atom Matrix Light
# Take control what leds to light.
#
# By setting the values to the global variables we control the color of leds realtime.
display:
- platform: addressable_light
id: matrix_led_display
addressable_light_id: matrix_led
width: 5
height: 5
lambda: |-
// Use global variables to set color
Color color = Color( id(color_red), id(color_green), id(color_blue) );
it.rectangle(0, 0, 2, 2, color);
# Enable Home Assistant API
api:
services:
- service: matrix_square_1
variables:
red: int # color values between 0-255
green: int
blue: int
then:
- lambda: |-
// Set global variables for display:
id(color_red) = red;
id(color_green) = green;
id(color_blue) = blue;
Describe the problem you have/What new integration you would like
Currently, I can't find a way to set
addressable_sets
or partitions of non-contiguous groups. Concretely, I have a 5x5 display (m5stack Atom, uses FastLED) and I would like to address the 4 LEDS in each corner in a group, so if the LEDS are numbered:00 01 02 03 04
05 06 07 08 09
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
these would be [0,1,5,6], [3,4,8,9], [15,16,20,21] and [18,19,23,24].
Please describe your use case for this integration and alternatives you've tried:
Use Case: make little 2x2 squares in the display for better visibility.
It seems possible to do this with addressable_set (and gets much more complicated if you turn the display 90 degrees), however that is quite cumbersome.
Additional context