12 if (
state.supports_effects())
13 root[
"effect"] =
state.get_effect_name();
15 auto values =
state.remote_values;
16 auto traits =
state.get_output()->get_traits();
18 switch (values.get_color_mode()) {
22 root[
"color_mode"] =
"onoff";
25 root[
"color_mode"] =
"brightness";
28 root[
"color_mode"] =
"white";
31 root[
"color_mode"] =
"color_temp";
34 root[
"color_mode"] =
"cwww";
37 root[
"color_mode"] =
"rgb";
40 root[
"color_mode"] =
"rgbw";
43 root[
"color_mode"] =
"rgbct";
46 root[
"color_mode"] =
"rgbww";
51 root[
"state"] = (values.get_state() != 0.0f) ?
"ON" :
"OFF";
53 root[
"brightness"] = uint8_t(values.get_brightness() * 255);
55 JsonObject color = root.createNestedObject(
"color");
57 color[
"r"] = uint8_t(values.get_color_brightness() * values.get_red() * 255);
58 color[
"g"] = uint8_t(values.get_color_brightness() * values.get_green() * 255);
59 color[
"b"] = uint8_t(values.get_color_brightness() * values.get_blue() * 255);
62 color[
"w"] = uint8_t(values.get_white() * 255);
63 root[
"white_value"] = uint8_t(values.get_white() * 255);
67 root[
"color_temp"] = uint32_t(values.get_color_temperature());
70 color[
"c"] = uint8_t(values.get_cold_white() * 255);
71 color[
"w"] = uint8_t(values.get_warm_white() * 255);
76 if (root.containsKey(
"state")) {
93 if (root.containsKey(
"brightness")) {
97 if (root.containsKey(
"color")) {
98 JsonObject color = root[
"color"];
100 float max_rgb = 0.0f;
101 if (color.containsKey(
"r")) {
102 float r = float(color[
"r"]) / 255.0f;
103 max_rgb = fmaxf(max_rgb, r);
106 if (color.containsKey(
"g")) {
107 float g = float(color[
"g"]) / 255.0f;
108 max_rgb = fmaxf(max_rgb, g);
111 if (color.containsKey(
"b")) {
112 float b = float(color[
"b"]) / 255.0f;
113 max_rgb = fmaxf(max_rgb, b);
116 if (color.containsKey(
"r") || color.containsKey(
"g") || color.containsKey(
"b")) {
120 if (color.containsKey(
"c")) {
123 if (color.containsKey(
"w")) {
126 if (color.containsKey(
"c")) {
129 call.
set_white(
float(color[
"w"]) / 255.0f);
134 if (root.containsKey(
"white_value")) {
135 call.
set_white(
float(root[
"white_value"]) / 255.0f);
138 if (root.containsKey(
"color_temp")) {
146 if (root.containsKey(
"flash")) {
147 auto length = uint32_t(
float(root[
"flash"]) * 1000);
151 if (root.containsKey(
"transition")) {
152 auto length = uint32_t(
float(root[
"transition"]) * 1000);
156 if (root.containsKey(
"effect")) {
157 const char *effect = root[
"effect"];
This class represents a requested change in a light state.
LightCall & set_color_temperature(optional< float > color_temperature)
Set the color temperature of the light in mireds for CWWW or RGBWW lights.
LightCall & set_color_brightness(optional< float > brightness)
Set the color brightness of the light from 0.0 (no color) to 1.0 (fully on)
LightCall & set_effect(optional< std::string > effect)
Set the effect of the light by its name.
LightCall & set_white(optional< float > white)
Set the white value value of the light from 0.0 to 1.0 for RGBW[W] lights.
LightCall & set_green(optional< float > green)
Set the green RGB value of the light from 0.0 to 1.0.
LightCall & set_warm_white(optional< float > warm_white)
Set the warm white value of the light from 0.0 to 1.0.
LightCall & set_blue(optional< float > blue)
Set the blue RGB value of the light from 0.0 to 1.0.
LightCall & set_flash_length(optional< uint32_t > flash_length)
Start and set the flash length of this call in milliseconds.
LightCall & set_cold_white(optional< float > cold_white)
Set the cold white value of the light from 0.0 to 1.0.
LightCall & set_red(optional< float > red)
Set the red RGB value of the light from 0.0 to 1.0.
LightCall & set_brightness(optional< float > brightness)
Set the target brightness of the light from 0.0 (fully off) to 1.0 (fully on)
LightCall & set_state(optional< bool > state)
Set the binary ON/OFF state of the light.
LightCall & set_transition_length(optional< uint32_t > transition_length)
Set the transition length of this call in milliseconds.
static void parse_color_json(LightState &state, LightCall &call, JsonObject root)
static void parse_json(LightState &state, LightCall &call, JsonObject root)
Parse the JSON state of a light to a LightCall.
static void dump_json(LightState &state, JsonObject root)
Dump the state of a light as JSON.
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
@ ON_OFF
Only on/off control.
@ RGB_COLD_WARM_WHITE
RGB color output, and separate cold and warm white outputs.
@ BRIGHTNESS
Dimmable light.
@ UNKNOWN
No color mode configured (cannot be a supported mode, only active when light is off).
@ RGB_WHITE
RGB color output and a separate white output.
@ RGB_COLOR_TEMPERATURE
RGB color output and a separate white output with controllable color temperature.
@ COLOR_TEMPERATURE
Controllable color temperature output.
@ WHITE
White output only (use only if the light also has another color mode such as RGB).
@ COLD_WARM_WHITE
Cold and warm white output with individually controllable brightness.
@ ON_OFF
Light can be turned on/off.
@ BRIGHTNESS
Master brightness of the light can be controlled.
@ RGB
Color can be controlled using RGB format (includes a brightness control for the color).
@ COLOR_TEMPERATURE
Color temperature can be controlled.
@ WHITE
Brightness of white channel can be controlled separately from other channels.
@ COLD_WARM_WHITE
Brightness of cold and warm white output can be controlled.
Providing packet encoding functions for exchanging data with a remote host.
ParseOnOffState parse_on_off(const char *str, const char *on, const char *off)
Parse a string that contains either on, off or toggle.