Im trying to make a esphome module (esp12S on breakout board) that included a 16 bit ws2812b ring (16 pcs led) to show the volume of my mediaplayer.
I was thinking of making a service on esphome config, that will accept a value of 0-100 for the volume in procent.
Then the esp module has to do the math to light up the individual leds to display the volume, ex. 50% volume turns on 8 pcs of leds. 75% 12 pcs and 100% all of them.
I have been reading the docs but cant figure out how to do this. I want the light to be internal, so the service should only be available for hass,
I think I have to go the lambda route, but I need some guidelines.
What I can do, is the service and accepting a value.
Light to control the ws2812 ring (all led turns on and off with same color).
Yeah, I was looking at it before, but dont know how to pass the volume value into the effects.
And if effects really is the way to go here.
for ex.
!lambda |-
// The sensor outputs values from 0 to 100. The blue
// part of the light color will be determined by the sensor value.
return id(some_sensor).state / 100.0;
id(some_sensor).state how would I write to get the value sent into the service component on the esphome?
can it be as easy as setting a ID on the service, and then call id(service_id).my_brightness (using this name from the example below).
The volume state is pushed instantly to the ESP using the Home Assistant API.
I agree, itās not pretty, and I would like something simpler. Iām also struggling with the light.addressable_set command - not doing anything for me.
Ok, tested some, but think the way to go is via a service on esphome
But it appears that addressable_set wont execute?
I added light.turn_on before addressable_set to test if something is running, that is executed and changes the light. But light.addressable_set wont do anythingā¦
Tested the 1.14.0-dev version including the fix @glmnet added.
It work!
This is how I made it work. A made the service accepting volume value (I use node-red to adjust the volume), and sending that will trigger the light.addressable_set.
The lambda do the math of what leds to turn on (here I have to try to fix it, instead of hard coding 16 as total leds I need to get a variable or the value from the light configā¦)
The only issue I have now with this is that I have to turn on the leds manually, if lights are off and I send the light.addressable_set it wont do anything, should it not turn on the leds if I send ex. red: 100% ?
Do I have to add something more?
You really have more maths in there than you need.
16*(volume/100)
is the same as
0.16*volume
But as all volumes in home assistant are expressed as a float between 0.00 and 1.00 - ie 50% volume is 0.50, so I am puzzled why you have them as a number between 0 and 100 in the first place.
Yes, I tested this out now, but that went weird.
For some reason the light.addressable_set got more or less overwritten by the light.turn_on or it is called the same time and as light.turn_on has 1s transition it takes over I think, I tested with triggering it multiple times, and notices a little flashing of the LEDs.
I added this if statement, but still, it turns the leds on if they are off, but then I have to trigger the disp_volume again to set the correct ledsā¦ (ps. had the IF statement before all addressable_set but the same result)
Cool. I am following this as I have already set up a manual volume control with a rotary encoder (there is nothing like a big volume knob, everyone understands that!).
I think coupled with a ring for visual feedback, this will be great. Need to design a case/stand for it. I have something in mind