Skip to content

Commit

Permalink
Add hue/saturation
Browse files Browse the repository at this point in the history
  • Loading branch information
Breina committed Jul 31, 2023
1 parent 7969dda commit c6ecba6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 104 deletions.
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,22 @@ _Staticly sets the green channel on 50% brightness_
- `B` = blue, unscaled
- `w` = white, scaled for brightness
- `W` = white, unscaled
- `u` = hue
- `U` = saturation
- [`0`, `255`] = static value between the range [0, 255]


#### Compatibility

| Type | | | | | | | | | | | | | | | | | Default value |
|------------|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-------|-------|-----------|---------------|
| fixed | | | | | | | | | | | | | | | | `[0,255]` | `0` |
| binary | | | | | | | | | | | | | | | | `[0,255]` | `0` |
| dimmer | | | | | | | | | | | | | | | | `[0,255]` | `0` |
| color_temp | `d` | `c` | `C` | `h` | `H` | `t` | `T` | | | | | | | | | `[0,255]` | `ch` |
| rgb | `d` | | | | | | | `r` | `R` | `g` | `G` | `b` | `B` | `w`\* | `W`\* | `[0,255]` | `rgb` |
| rgbw | `d` | | | | | | | `r` | `R` | `g` | `G` | `b` | `B` | `w` | `W` | `[0,255]` | `rgbw` |
| rgbww | `d` | `c` | `C` | `h` | `H` | `t` | `T` | `r` | `R` | `g` | `G` | `b` | `B` | | | `[0,255]` | `rgbch` |
| Type | | | | | | | | | | | | | | | | | | | Default value |
|------------|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-------|-------|-----|-----|-----------|---------------|
| fixed | | | | | | | | | | | | | | | | | | `[0,255]` | `0` |
| binary | | | | | | | | | | | | | | | | | | `[0,255]` | `0` |
| dimmer | | | | | | | | | | | | | | | | | | `[0,255]` | `0` |
| color_temp | `d` | `c` | `C` | `h` | `H` | `t` | `T` | | | | | | | | | | | `[0,255]` | `ch` |
| rgb | `d` | | | | | | | `r` | `R` | `g` | `G` | `b` | `B` | `w`\* | `W`\* | `u` | `U` | `[0,255]` | `rgb` |
| rgbw | `d` | | | | | | | `r` | `R` | `g` | `G` | `b` | `B` | `w` | `W` | `u` | `U` | `[0,255]` | `rgbw` |
| rgbww | `d` | `c` | `C` | `h` | `H` | `t` | `T` | `r` | `R` | `g` | `G` | `b` | `B` | | | `u` | `U` | `[0,255]` | `rgbch` |

\* In the case of a white channel being used in an RGB light fixture, the white channel is automatically calculated.

Expand Down
22 changes: 18 additions & 4 deletions custom_components/artnet_led/util/channel_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Union

from homeassistant.exceptions import IntegrationError
from homeassistant.util.color import color_RGB_to_hsv, color_hsv_to_RGB

log = logging.getLogger(__name__)

Expand All @@ -12,9 +13,9 @@
"binary": "",
"dimmer": "d",
"color_temp": "dcChHtT",
"rgb": "drRgGbBwW",
"rgbw": "drRgGbBwW",
"rgbww": "dcChHtTrRgGbB"
"rgb": "drRgGbBuUwW",
"rgbw": "drRgGbBuUwW",
"rgbww": "dcChHtTrRgGbBuU"
}


Expand Down Expand Up @@ -55,6 +56,8 @@ def to_values(channel_setup: str, channel_size: int, is_on: bool = True, brightn
# H = hot (not scaled)
# t = temperature (0 = hot, 255 = cold)
# T = temperature (255 = hot, 0 = cold)
# u = hue
# U = saturation
switcher = {
"d": lambda: brightness,
"r": lambda: is_on * red * brightness / max_color,
Expand All @@ -70,7 +73,9 @@ def to_values(channel_setup: str, channel_size: int, is_on: bool = True, brightn
"h": lambda: is_on * warm_white * brightness / max_color,
"H": lambda: is_on * warm_white * 255 / max_color,
"t": lambda: cold_white,
"T": lambda: warm_white
"T": lambda: warm_white,
"u": lambda: color_RGB_to_hsv(red, green ,blue)[0] * 255 / 360,
"U": lambda: color_RGB_to_hsv(red, green, blue)[1] * 255 / 100,
}

values: list[int] = list()
Expand All @@ -94,6 +99,8 @@ def from_values(channel_setup: str, channel_size: int, values: list[int],
red: int | None = None
green: int | None = None
blue: int | None = None
hue: int | None = None
saturation: int | None = None
cold_white: int | None = None
warm_white: int | None = None
color_temp_kelvin: int | None = None
Expand Down Expand Up @@ -145,6 +152,10 @@ def from_values(channel_setup: str, channel_size: int, values: list[int],
cold_white = value
elif channel == "T":
warm_white = value
elif channel == "u":
hue = int(value * 360 / 255)
elif channel == "U":
saturation = int(value * 100 / 255)

if cold_white is None and warm_white is not None:
cold_white = 255 - warm_white
Expand All @@ -159,6 +170,9 @@ def from_values(channel_setup: str, channel_size: int, values: list[int],
cold_ratio = cold_white / (white_sum)
color_temp_kelvin = round(min_kelvin - min_kelvin * cold_ratio + max_kelvin * cold_ratio)

if hue is not None and saturation is not None and red is None and green is None and blue is None:
red, green, blue = color_hsv_to_RGB(hue, saturation, 1)

return is_on, brightness, red, green, blue, cold_white, warm_white, color_temp_kelvin


Expand Down
108 changes: 17 additions & 91 deletions staging/configuration.yaml
Original file line number Diff line number Diff line change
@@ -1,101 +1,27 @@
light:
# room 3 via DMX
- platform: artnet_led
host: 10.86.189.129 # IP of Art-Net Node
host: 192.168.1.239 # IP of Art-Net Node
port: 6038
max_fps: 25 # Max 40 per second
refresh_every: 1 # Resend values if no fades are running every x seconds, 0 disables automatic refresh
node_type: artnet-controller # Which protocol to use (artnet-controller / artnet-direct)
refresh_every: 2 # Resend values if no fades are running every x seconds, 0 disables automatic refresh
node_type: artnet-controller # Which protocol to use
universes: # Support for multiple universes
3: # Nr of Universe (see configuration of your Art-Net Node)
send_partial_universe: True # Only send the universe which contains data
1: # Nr of Universe (see configuration of your Art-Net Node)
send_partial_universe: false # Only send the universe which contains data
output_correction: quadratic # optional: output correction for the whole universe, will be used as default if nothing is set for the channel
devices:
# Dimmer
- channel: 1 # first channel of dmx dimmer
name: 3_DMX_1 # name
type: dimmer # type
transition: 1 # default duration of fades in sec. Will be overridden by Transition sent from HA
output_correction: quadratic # optional: quadratic, cubic or quadruple. Apply different dimming curves to the output. Default is None which means linear dimming
channel_size: 8bit # width of the channel sent to DMX device, default "8bit", "16bit", "24bit" and "32bit" available.
- channel: 2
name: 3_DMX_2
type: dimmer
transition: 1
output_correction: quadratic
channel_size: 8bit
- channel: 3
name: 3_DMX_3
type: dimmer
transition: 1
output_correction: quadratic
channel_size: 8bit
- channel: 4
name: 3_DMX_4
type: dimmer
transition: 1
output_correction: quadratic
channel_size: 8bit
- channel: 5
name: 3_DMX_5
type: dimmer
transition: 1
output_correction: quadratic
channel_size: 8bit
- channel: 6
name: 3_DMX_6
type: dimmer
transition: 1
output_correction: quadratic
channel_size: 8bit

# zaal 5 via DMX
- platform: artnet_led
host: 192.168.1.35 # IP of Art-Net Node
max_fps: 25 # Max 40 per second
refresh_every: 1 # Resend values if no fades are running every x seconds, 0 disables automatic refresh
node_type: artnet-controller # Which protocol to use
universes: # Support for multiple universes
5: # Nr of Universe (see configuration of your Art-Net Node)
send_partial_universe: True # Only send the universe which contains data
output_correction: quadratic # optional: output correction for the whole universe, will be used as default if nothing is set for the channel
devices:
# Dimmer
- channel: 1 # first channel of dmx dimmer
name: 5_DMX_1 # name
type: dimmer # type
transition: 1 # default duration of fades in sec. Will be overridden by Transition sent from HA
output_correction: quadratic # optional: quadratic, cubic or quadruple. Apply different dimming curves to the output. Default is None which means linear dimming
channel_size: 8bit # width of the channel sent to DMX device, default "8bit", "16bit", "24bit" and "32bit" available.
- channel: 2
name: 5_DMX_2
type: dimmer
transition: 1
channel_size: 8bit
output_correction: quadratic
- channel: 3
name: 5_DMX_3
type: dimmer
transition: 1
channel_size: 8bit
output_correction: quadratic
- channel: 4
name: 5_DMX_4
type: dimmer
transition: 1
channel_size: 8bit
output_correction: quadratic
- channel: 5
name: 5_DMX_5
type: dimmer
transition: 1
channel_size: 8bit
output_correction: quadratic
- channel: 6
name: 5_DMX_6
type: dimmer
transition: 1
channel_size: 8bit
output_correction: quadratic
- channel: 1
name: test_light
type: rgbww
min_temp: 1750K
max_temp: 9910K
channel_setup:
- d
- t
- u
- U
- 0

logger:
default: info
Expand Down

0 comments on commit c6ecba6

Please sign in to comment.