#Set Light Brightness based on Input Number

1 messages · Page 1 of 1 (latest)

summer fable
#

This is probably simple as heck and I"m just missing something.

I'm built a dashboard to control lights sectioned off by room. I have buttons to change the color and set brightness to 75. But I wanted more control over the brightness without having to make tons of buttons for brightness to crowd around the color buttons. The idea is to have a single brightness slider, then tap a color. I.e., if you use the slider to set it to 20, then tap the purple bulb in the "Living Room" section, the living room lights will change to 20% brightness with a purple color.

I set up an input_number helper, input_helper.light_brightness_input. Then put a card at the top of the page to control that number. I'm using the living room area to test it. I went to the button that makes them 100% bright with white color.

This works
brightness_pct: 100

This doesn't
brightness_pct: "{{ states('input_number.light_brightness_input') | float }}"

And I don't know why. I put that template in the editor and it does correctly give me back the number that input_number.light_brightness_input is currently set to.

glacial pier
#

The one important piece of information that you did not include: what card are you using to turn on the lights?
Most stock cards do support templates; you may need to go with something custom. But, even then, some custom cards that can use templates may not support them in actions. The custom:button-card does but it uses a different syntax since it uses JavaScript instead of Jinja. Post your code so we can see what you're working with.

#

If you don't want to use a custom card, consider using a script or automation to handle the actual work. The button will just call the script and should be able to feed it some info, such as the entity. Then, the script/automation can apply the values to the appropriate helpers.

summer fable
#

Ah, I didn't know there would be any difference between cards. Nothing in my reading mentioned that.

I'm using the custom mushroom cards from HACS.

glacial pier
#

The Mushroom cards do not support templated actions. I did some testing a while back to see what, if anything, would work. None of these three experiments worked with the mushroom-template-card, but they did with the custom:button-card.

summer fable
glacial pier
#

Yeah. The script method will probably be the easiest route to go to. Now, with that said, if you're up for a challenge, the custom:button-card can be made to look like Mushroom cards/chips. These are two examples that I put together. The Light card is about 80 lines and the fan card is about 50 lines.

summer fable
#

I don't see too much of a point in making other custom cards look like mushroom chips. But, I'm trying to devise a way to set the color based on which chip is pressed.

#

Ideally, I'd like to keep this down to 1 script per area. (Bedroom's light is the only one without color). I've been able to get automations to have different triggers and set trigger IDs so it has different behavior based on what triggered it. Now I'm thinking this might have to be many scripts since mushroom chips probably don't support passing a trigger ID to a script. I thought maybe "fire event" would be an option.

#

Mushroom's custom cards are beautiful, but the limitations are frustrating.

#

damn, maybe I am going to have to copy some code for a custom card that looks like a mushroom chip.

summer fable
#

Just so this doesn't look like it ends with no solution, here's what I ended up doing:

#

Here's how I re-did my panel. Now I have four input_number helpers. One for brightness, one for red, one for green, one for blue.

The off buttons still turn off the lights in that area.
The dim button still turn the lights in that area to 1% brightness on their current color.
The custom button triggers a script. Each custom button goes to its own script, so one for Living Room, one for Kitchen, and one for Bathroom. The script uses the action that turns on the lights, target the area, and I use templating to pull the brightness and RGB values from the numbers.

The brightness and preview sliders at the top will update live when you change the sliders. I used card-mod to apply CSS styling which supports the use of templates in place of values. So those use templates to draw the numbers from the red/green/blue input_number helpers. For the brightness, since that's an RGB value which goes up to 255 but the number helper only goes up to 100, that template converts the brightness number to float, multiplies by 2.55, then rounds to the nearest whole number, and that template is used for red, green, and blue so it looks like a live-updating brightness slider.

#

So, in total, 4 helpers, 3 scripts. Much better than having to have a couple dozen scripts to accomplish everything.

glacial pier