mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 05:06:44 +00:00
Add custom fan animation example
This commit is contained in:
parent
4dac1ae447
commit
3772db01fa
@ -340,6 +340,14 @@ void dispatch_topic_payload(const char* topic, const char* payload, bool update,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HASP_USE_CUSTOM > 0
|
||||||
|
if(topic == strstr_P(topic, PSTR(MQTT_TOPIC_CUSTOM "/"))) { // startsWith custom
|
||||||
|
topic += 7u;
|
||||||
|
custom_topic_payload(topic, (char*)payload, source);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
dispatch_command(topic, (char*)payload, update, source); // dispatch as is
|
dispatch_command(topic, (char*)payload, update, source); // dispatch as is
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,10 @@ bool mqttSetConfig(const JsonObject& settings);
|
|||||||
#define MQTT_TOPIC_SENSORS "sensors"
|
#define MQTT_TOPIC_SENSORS "sensors"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MQTT_TOPIC_CUSTOM
|
||||||
|
#define MQTT_TOPIC_CUSTOM "custom"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MQTT_TOPIC_LWT "LWT"
|
#define MQTT_TOPIC_LWT "LWT"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -264,6 +264,14 @@ static void onConnect(void* context)
|
|||||||
topic = mqttNodeTopic + "config/#";
|
topic = mqttNodeTopic + "config/#";
|
||||||
mqtt_subscribe(mqtt_client, topic.c_str());
|
mqtt_subscribe(mqtt_client, topic.c_str());
|
||||||
|
|
||||||
|
#if HASP_USE_CUSTOM > 0
|
||||||
|
topic = mqttGroupTopic + MQTT_TOPIC_CUSTOM "/#";
|
||||||
|
mqtt_subscribe(mqtt_client, topic.c_str());
|
||||||
|
|
||||||
|
topic = mqttNodeTopic + MQTT_TOPIC_CUSTOM "/#";
|
||||||
|
mqtt_subscribe(mqtt_client, topic.c_str());
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HASP_USE_BROADCAST
|
#ifdef HASP_USE_BROADCAST
|
||||||
topic = MQTT_PREFIX "/" MQTT_TOPIC_BROADCAST "/" MQTT_TOPIC_COMMAND "/#";
|
topic = MQTT_PREFIX "/" MQTT_TOPIC_BROADCAST "/" MQTT_TOPIC_COMMAND "/#";
|
||||||
mqtt_subscribe(mqtt_client, topic.c_str());
|
mqtt_subscribe(mqtt_client, topic.c_str());
|
||||||
|
@ -119,7 +119,7 @@ int mqtt_send_object_state(uint8_t pageid, uint8_t btnid, const char* payload)
|
|||||||
|
|
||||||
int mqtt_send_state(const char* subtopic, const char* payload)
|
int mqtt_send_state(const char* subtopic, const char* payload)
|
||||||
{
|
{
|
||||||
char tmp_topic[strlen(mqttNodeTopic) + 20];
|
char tmp_topic[strlen(mqttNodeTopic) + strlen(subtopic) + 16];
|
||||||
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic, subtopic);
|
snprintf_P(tmp_topic, sizeof(tmp_topic), PSTR("%s" MQTT_TOPIC_STATE "/%s"), mqttNodeTopic, subtopic);
|
||||||
return mqttPublish(tmp_topic, payload, false);
|
return mqttPublish(tmp_topic, payload, false);
|
||||||
}
|
}
|
||||||
@ -300,6 +300,13 @@ void mqttStart()
|
|||||||
snprintf_P(topic, sizeof(topic), PSTR("%s" MQTT_TOPIC_CONFIG "/#"), mqttNodeTopic);
|
snprintf_P(topic, sizeof(topic), PSTR("%s" MQTT_TOPIC_CONFIG "/#"), mqttNodeTopic);
|
||||||
mqttSubscribeTo(topic);
|
mqttSubscribeTo(topic);
|
||||||
|
|
||||||
|
#if HASP_USE_CUSTOM > 0
|
||||||
|
snprintf_P(topic, sizeof(topic), PSTR("%s" MQTT_TOPIC_CUSTOM "/#"), mqttGroupTopic);
|
||||||
|
mqttSubscribeTo(topic);
|
||||||
|
snprintf_P(topic, sizeof(topic), PSTR("%s" MQTT_TOPIC_CUSTOM "/#"), mqttNodeTopic);
|
||||||
|
mqttSubscribeTo(topic);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HASP_USE_BROADCAST
|
#ifdef HASP_USE_BROADCAST
|
||||||
snprintf_P(topic, sizeof(topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_BROADCAST "/" MQTT_TOPIC_COMMAND "/#"));
|
snprintf_P(topic, sizeof(topic), PSTR(MQTT_PREFIX "/" MQTT_TOPIC_BROADCAST "/" MQTT_TOPIC_COMMAND "/#"));
|
||||||
mqttSubscribeTo(topic);
|
mqttSubscribeTo(topic);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user