-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed code of Smartnest and updated documentation #4001
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
# Smartnest | ||
|
||
Enables integration with `smartnest.cz` service which provides MQTT integration with voice assistants. | ||
Enables integration with `smartnest.cz` service which provides MQTT integration with voice assistants, for example Google Home, Alexa, Siri, Home Assistant and more! | ||
|
||
In order to setup Smartnest follow the [documentation](https://www.docu.smartnest.cz/). | ||
- You can create up to 5 different devices | ||
- To add the project to Google Home you can find the information [here](https://www.docu.smartnest.cz/google-home-integration) | ||
- To add the project to Alexa you can find the information [here](https://www.docu.smartnest.cz/alexa-integration) | ||
|
||
## MQTT API | ||
|
||
The API is described in the Smartnest [Github repo](https://github.com/aososam/Smartnest/blob/master/Devices/lightRgb/lightRgb.ino). | ||
|
||
|
||
## Usermod installation | ||
|
||
1. Register the usermod by adding `#include "../usermods/smartnest/usermod_smartnest.h"` at the top and `usermods.add(new Smartnest());` at the bottom of `usermods_list.cpp`. | ||
or | ||
2. Use `#define USERMOD_SMARTNEST` in wled.h or `-D USERMOD_SMARTNEST` in your platformio.ini | ||
1. Use `#define USERMOD_SMARTNEST` in wled.h or `-D USERMOD_SMARTNEST` in your platformio.ini (recommended). | ||
## It is not necessary since the main branch of WLED brings it with it | ||
|
||
2. Register the usermod by adding `#include "../usermods/smartnest/usermod_smartnest.h"` at the top and `usermods.add(new Smartnest());` at the bottom of `usermods_list.cpp`. | ||
or | ||
|
||
Example **usermods_list.cpp**: | ||
|
||
|
@@ -51,11 +56,19 @@ void registerUsermods() | |
|
||
Usermod has no configuration, but it relies on the MQTT configuration.\ | ||
Under Config > Sync Interfaces > MQTT: | ||
* Enable MQTT check box | ||
* Set the `Broker` field to: `smartnest.cz` | ||
* The `Username` and `Password` fields are the login information from the `smartnest.cz` website. | ||
|
||
* Enable `MQTT` check box. | ||
* Set the `Broker` field to: `smartnest.cz` or `3.122.209.170`(both work). | ||
* Set the `Port` field to: `1883` | ||
* The `Username` and `Password` fields are the login information from the `smartnest.cz` website (It is located above in the 3 points). | ||
* `Client ID` field is obtained from the device configuration panel in `smartnest.cz`. | ||
* `Device Topic` is obtained by entering the ClientID/report , remember to replace ClientId with your real information (Because they can ban your device). | ||
* `Group Topic` keep the same Group Topic. | ||
|
||
Wait `1 minute` after turning it on, as it usually takes a while. | ||
|
||
## Change log | ||
2022-09 | ||
* First implementation. | ||
2024-05 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In changelog append the changes instead of removing the old log. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed up |
||
* Solved code. | ||
* Updated documentation. | ||
* Second implementation. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,10 @@ | |
class Smartnest : public Usermod | ||
{ | ||
private: | ||
bool initialized = false; | ||
unsigned long lastMqttReport = 0; | ||
unsigned long mqttReportInterval = 60000; // Report every minute | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this static const (or constexpr is better) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would argue to allow it to be just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I better leave it like this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to add configuration item like other usermods. |
||
|
||
void sendToBroker(const char *const topic, const char *const message) | ||
{ | ||
if (!WLED_MQTT_CONNECTED) | ||
|
@@ -61,7 +65,7 @@ class Smartnest : public Usermod | |
int position = 0; | ||
|
||
// We need to copy the string in order to keep it read only as strtok_r function requires mutable string | ||
color_ = (char *)malloc(strlen(color)); | ||
color_ = (char *)malloc(strlen(color) + 1); | ||
if (NULL == color_) { | ||
return -1; | ||
} | ||
|
@@ -150,7 +154,7 @@ class Smartnest : public Usermod | |
delay(100); | ||
sendToBroker("report/firmware", versionString); // Reports the firmware version | ||
delay(100); | ||
sendToBroker("report/ip", (char *)WiFi.localIP().toString().c_str()); // Reports the ip | ||
sendToBroker("report/ip", (char *)WiFi.localIP().toString().c_str()); // Reports the IP | ||
delay(100); | ||
sendToBroker("report/network", (char *)WiFi.SSID().c_str()); // Reports the network name | ||
delay(100); | ||
|
@@ -168,4 +172,39 @@ class Smartnest : public Usermod | |
{ | ||
return USERMOD_ID_SMARTNEST; | ||
} | ||
|
||
/** | ||
* setup() is called once at startup to initialize the usermod. | ||
*/ | ||
void setup() { | ||
// Initialization code here | ||
if (!initialized) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly my thoughts. 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed up |
||
DEBUG_PRINTF("Smartnest usermod setup initializing..."); | ||
|
||
// Publish initial status | ||
sendToBroker("report/status", "Smartnest usermod initialized"); | ||
|
||
initialized = true; | ||
} | ||
} | ||
|
||
/** | ||
* loop() is called continuously to keep the usermod running. | ||
*/ | ||
void loop() { | ||
// Periodically report status to MQTT broker | ||
unsigned long currentMillis = millis(); | ||
if (currentMillis - lastMqttReport >= mqttReportInterval) { | ||
lastMqttReport = currentMillis; | ||
|
||
// Report current brightness | ||
char brightnessMsg[6]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Max %u output may be 4,294,967,295 which needs 11 characters (including \0) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed up |
||
sprintf(brightnessMsg, "%u", bri); | ||
sendToBroker("report/brightness", brightnessMsg); | ||
|
||
// Report current signal strength | ||
String signal(WiFi.RSSI(), 10); | ||
sendToBroker("report/signal", signal.c_str()); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is not necessary - remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed up