Closed 0rTiN closed 3 years ago
This is unfortunately not really possible, since there is no way to set the brightness directly. The brightness method setColorWithBrightness
is simply a convenience method, which scales the color values, and you can easily do that yourself by simply multiplying your color values with the brightness between 0 and 1.
For example: magic-home color <ip> 127 0 0
to set the controller to red at 50% brightness.
A standalone brightness command would require a queryState
to get the current color from the controller and then a call to set the color. This would of course be possible, but kind of out of scope for the CLI tool, which is only really made for exposing the raw library methods and not a fully fledged command line interface to conveniently control your controllers.
Using jq
you could have a bash oneliner like this however:
magic-home color <ip> $(magic-home query <ip> | jq -r '[.color.red, .color.green, .color.blue] | max as $max | "\(.[0] * 255 / $max * <brightness> | round) \(.[1] * 255 / $max * <brightness> | round) \(.[2] * 255 / $max * <brightness> | round)"')
It's not the prettiest thing (and you can probably make it shorter), but it should be sufficient for use in a script.
Ok thx for your fast feedback. I will go that way. It will be sufficient for my needs.
@jangxx
sing jq you could have a bash oneliner like this however:
can i ask what does max represent? whats the math to change the colors like R 255 / x brightness ??
can i ask what does max represent?
max is just the maximum value of any of the three components so that we can scale them up before applying the brightness. Imagine the controller was at (127,0,20)
[so red with a bit of blue at 50% brightness]. If we want to set the brightness to 70% now, we can't just multiply the values by 0.7, instead we need to multiply the current values by 255 / max(127,0,20)
to get (255,0,40)
which we can then multiply by 0.7 to get (179,0,28)
[i.e. the same color at 70% brightness].
whats the math to change the colors like R 255 / x brightness ??
I don't understand your question, sorry.
I don't understand your question, sorry.
yet i got the awnser, thanks !
so i wanted to know the current brightness
it was as easy as 100/(255/max(R,G,B))
... thanks again!
Hi, any chance to get a command to set brightness like:
magic-home setbright|bright <IP>