Changed the need for seperate HA MQTT topic for speed
This commit is contained in:
parent
d406112ecf
commit
a3b950df5c
4 changed files with 20 additions and 17 deletions
|
@ -876,6 +876,10 @@ void loop() {
|
|||
strip.setColor(main_color.red, main_color.green, main_color.blue);
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == SETSPEED) {
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
mode = HOLD;
|
||||
}
|
||||
if (mode == BRIGHTNESS) {
|
||||
strip.setBrightness(brightness);
|
||||
mode = HOLD;
|
||||
|
|
|
@ -59,7 +59,6 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
|||
String mqtt_ha = "home/" + String(HOSTNAME) + "_ha/";
|
||||
String mqtt_ha_state_in = mqtt_ha + "state/in";
|
||||
String mqtt_ha_state_out = mqtt_ha + "state/out";
|
||||
String mqtt_ha_speed = mqtt_ha + "speed";
|
||||
|
||||
const char* on_cmd = "ON";
|
||||
const char* off_cmd = "OFF";
|
||||
|
@ -85,7 +84,7 @@ uint32_t autoParams[][4] = { // color, speed, mode, duration (seconds)
|
|||
#define DBG_OUTPUT_PORT Serial // Set debug output port
|
||||
|
||||
// List of all color modes
|
||||
enum MODE { SET_MODE, HOLD, OFF, ALL, SETCOLOR, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM };
|
||||
enum MODE { SET_MODE, HOLD, OFF, ALL, SETCOLOR, SETSPEED, BRIGHTNESS, WIPE, RAINBOW, RAINBOWCYCLE, THEATERCHASE, TWINKLERANDOM, THEATERCHASERAINBOW, TV, CUSTOM };
|
||||
|
||||
MODE mode = RAINBOW; // Standard mode that is active when software starts
|
||||
|
||||
|
|
|
@ -742,6 +742,14 @@ void checkForRequests() {
|
|||
mode = SETCOLOR;
|
||||
}
|
||||
|
||||
if (root.containsKey("speed")) {
|
||||
uint8_t json_speed = constrain((uint8_t) root["speed"], 0, 255);
|
||||
if (json_speed != ws2812fx_speed) {
|
||||
ws2812fx_speed = json_speed;
|
||||
mode = SETSPEED;
|
||||
}
|
||||
}
|
||||
|
||||
if (root.containsKey("color_temp")) {
|
||||
//temp comes in as mireds, need to convert to kelvin then to RGB
|
||||
color_temp = (uint16_t) root["color_temp"];
|
||||
|
@ -800,11 +808,6 @@ void checkForRequests() {
|
|||
#ifdef ENABLE_STATE_SAVE_SPIFFS
|
||||
if(!spiffs_save_state.active()) spiffs_save_state.once(3, tickerSpiffsSaveState);
|
||||
#endif
|
||||
|
||||
} else if (strcmp(topic, mqtt_ha_speed.c_str()) == 0) {
|
||||
uint8_t d = (uint8_t) strtol((const char *) &payload[0], NULL, 10);
|
||||
ws2812fx_speed = constrain(d, 0, 255);
|
||||
strip.setSpeed(convertSpeed(ws2812fx_speed));
|
||||
#ifdef ENABLE_MQTT
|
||||
} else if (strcmp(topic, (char *)mqtt_intopic) == 0) {
|
||||
#endif
|
||||
|
@ -1019,7 +1022,6 @@ void checkForRequests() {
|
|||
#ifdef ENABLE_HOMEASSISTANT
|
||||
ha_send_data.detach();
|
||||
mqtt_client.subscribe(mqtt_ha_state_in.c_str(), qossub);
|
||||
mqtt_client.subscribe(mqtt_ha_speed.c_str(), qossub);
|
||||
#endif
|
||||
|
||||
DBG_OUTPUT_PORT.printf("MQTT topic in: %s\n", mqtt_intopic);
|
||||
|
@ -1079,8 +1081,6 @@ void checkForRequests() {
|
|||
ha_send_data.detach();
|
||||
uint16_t packetIdSub2 = amqttClient.subscribe((char *)mqtt_ha_state_in.c_str(), qossub);
|
||||
DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub2);
|
||||
uint16_t packetIdSub3 = amqttClient.subscribe((char *)mqtt_ha_speed.c_str(), qossub);
|
||||
DBG_OUTPUT_PORT.printf("Subscribing at QoS %d, packetId: ", qossub); DBG_OUTPUT_PORT.println(packetIdSub3);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -87,9 +87,9 @@ automation:
|
|||
platform: state
|
||||
action:
|
||||
- data_template:
|
||||
payload_template: '{{ trigger.to_state.state | int }}'
|
||||
payload_template: '{"speed": {{ trigger.to_state.state | int }}}'
|
||||
retain: true
|
||||
topic: home/McLighting01_ha/speed
|
||||
topic: home/McLighting01_ha/state/in
|
||||
service: mqtt.publish
|
||||
|
||||
- id: 93786598732698756967
|
||||
|
|
Loading…
Reference in a new issue