@@ -11,9 +11,21 @@ HAMqtt mqtt(client, device);
11
11
12
12
// HALight::BrightnessFeature enables support for setting brightness of the light.
13
13
// HALight::ColorTemperatureFeature enables support for setting color temperature of the light.
14
- // Both features are optional and you can remove them if they're not needed.
14
+ // HALight::EffectsFeature enables support for setting effect of the light.
15
+ // All features are optional, and you can remove them if they're not needed.
15
16
// "prettyLight" is unique ID of the light. You should define your own ID.
16
- HALight light (" prettyLight" , HALight::BrightnessFeature | HALight::ColorTemperatureFeature | HALight::RGBFeature);
17
+ HALight light (" prettyLight" , HALight::BrightnessFeature |
18
+ HALight::ColorTemperatureFeature |
19
+ HALight::RGBFeature |
20
+ HALight::EffectsFeature);
21
+
22
+ const char * const lightEffects[] = {
23
+ " Fire" ,
24
+ " Rainbow" ,
25
+ " Polar light" ,
26
+ " Rain" ,
27
+ " Smoke"
28
+ };
17
29
18
30
void onStateCommand (bool state, HALight* sender) {
19
31
Serial.print (" State: " );
@@ -47,6 +59,15 @@ void onRGBColorCommand(HALight::RGBColor color, HALight* sender) {
47
59
sender->setRGBColor (color); // report color back to the Home Assistant
48
60
}
49
61
62
+ void onEffectCommand (uint8_t index, HALight* sender) {
63
+ Serial.print (" Effect index: " );
64
+ Serial.println (index);
65
+ Serial.print (" Effect name: " );
66
+ Serial.println (lightEffects[index]);
67
+
68
+ sender->setEffect (index); // report effect back to the Home Assistant
69
+ }
70
+
50
71
void setup () {
51
72
Serial.begin (9600 );
52
73
@@ -74,11 +95,15 @@ void setup() {
74
95
// light.setMinMireds(50);
75
96
// light.setMaxMireds(200);
76
97
98
+ // Light effects (mandatory if HALight::EffectsFeature is set, optional otherwise)
99
+ light.setEffects (lightEffects, 5 );
100
+
77
101
// handle light states
78
102
light.onStateCommand (onStateCommand);
79
103
light.onBrightnessCommand (onBrightnessCommand); // optional
80
104
light.onColorTemperatureCommand (onColorTemperatureCommand); // optional
81
105
light.onRGBColorCommand (onRGBColorCommand); // optional
106
+ light.onEffectCommand (onEffectCommand); // optional
82
107
83
108
mqtt.begin (BROKER_ADDR);
84
109
}
0 commit comments