mirror of
https://github.com/wled/WLED.git
synced 2025-07-15 06:46:34 +00:00
Merge pull request #4001 from DevilPro1/smartnest
Fixed code of Smartnest and updated documentation
This commit is contained in:
commit
1bb06106fd
@ -1,61 +1,41 @@
|
|||||||
# Smartnest
|
# 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/).
|
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
|
## MQTT API
|
||||||
|
|
||||||
The API is described in the Smartnest [Github repo](https://github.com/aososam/Smartnest/blob/master/Devices/lightRgb/lightRgb.ino).
|
The API is described in the Smartnest [Github repo](https://github.com/aososam/Smartnest/blob/master/Devices/lightRgb/lightRgb.ino).
|
||||||
|
|
||||||
|
|
||||||
## Usermod installation
|
## 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`.
|
1. Use `#define USERMOD_SMARTNEST` in wled.h or `-D USERMOD_SMARTNEST` in your platformio.ini (recommended).
|
||||||
or
|
|
||||||
2. Use `#define USERMOD_SMARTNEST` in wled.h or `-D USERMOD_SMARTNEST` in your platformio.ini
|
|
||||||
|
|
||||||
|
|
||||||
Example **usermods_list.cpp**:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#include "wled.h"
|
|
||||||
/*
|
|
||||||
* Register your v2 usermods here!
|
|
||||||
* (for v1 usermods using just usermod.cpp, you can ignore this file)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Add/uncomment your usermod filename here (and once more below)
|
|
||||||
* || || ||
|
|
||||||
* \/ \/ \/
|
|
||||||
*/
|
|
||||||
//#include "usermod_v2_example.h"
|
|
||||||
//#include "usermod_temperature.h"
|
|
||||||
#include "../usermods/usermod_smartnest.h"
|
|
||||||
|
|
||||||
void registerUsermods()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* Add your usermod class name here
|
|
||||||
* || || ||
|
|
||||||
* \/ \/ \/
|
|
||||||
*/
|
|
||||||
//usermods.add(new MyExampleUsermod());
|
|
||||||
//usermods.add(new UsermodTemperature());
|
|
||||||
usermods.add(new Smartnest());
|
|
||||||
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Usermod has no configuration, but it relies on the MQTT configuration.\
|
Usermod has no configuration, but it relies on the MQTT configuration.\
|
||||||
Under Config > Sync Interfaces > MQTT:
|
Under Config > Sync Interfaces > MQTT:
|
||||||
* Enable MQTT check box
|
|
||||||
* Set the `Broker` field to: `smartnest.cz`
|
* Enable `MQTT` check box.
|
||||||
* The `Username` and `Password` fields are the login information from the `smartnest.cz` website.
|
* 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`.
|
* `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
|
## Change log
|
||||||
|
|
||||||
2022-09
|
2022-09
|
||||||
* First implementation.
|
* First implementation.
|
||||||
|
|
||||||
|
2024-05
|
||||||
|
* Solved code.
|
||||||
|
* Updated documentation.
|
||||||
|
* Second implementation.
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
class Smartnest : public Usermod
|
class Smartnest : public Usermod
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
bool initialized = false;
|
||||||
|
unsigned long lastMqttReport = 0;
|
||||||
|
unsigned long mqttReportInterval = 60000; // Report every minute
|
||||||
|
|
||||||
void sendToBroker(const char *const topic, const char *const message)
|
void sendToBroker(const char *const topic, const char *const message)
|
||||||
{
|
{
|
||||||
if (!WLED_MQTT_CONNECTED)
|
if (!WLED_MQTT_CONNECTED)
|
||||||
@ -61,7 +65,7 @@ private:
|
|||||||
int position = 0;
|
int position = 0;
|
||||||
|
|
||||||
// We need to copy the string in order to keep it read only as strtok_r function requires mutable string
|
// 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_) {
|
if (NULL == color_) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -150,7 +154,7 @@ public:
|
|||||||
delay(100);
|
delay(100);
|
||||||
sendToBroker("report/firmware", versionString); // Reports the firmware version
|
sendToBroker("report/firmware", versionString); // Reports the firmware version
|
||||||
delay(100);
|
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);
|
delay(100);
|
||||||
sendToBroker("report/network", (char *)WiFi.SSID().c_str()); // Reports the network name
|
sendToBroker("report/network", (char *)WiFi.SSID().c_str()); // Reports the network name
|
||||||
delay(100);
|
delay(100);
|
||||||
@ -168,4 +172,34 @@ public:
|
|||||||
{
|
{
|
||||||
return USERMOD_ID_SMARTNEST;
|
return USERMOD_ID_SMARTNEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setup() is called once at startup to initialize the usermod.
|
||||||
|
*/
|
||||||
|
void setup() {
|
||||||
|
DEBUG_PRINTF("Smartnest usermod setup initializing...");
|
||||||
|
|
||||||
|
// Publish initial status
|
||||||
|
sendToBroker("report/status", "Smartnest usermod initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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[11];
|
||||||
|
sprintf(brightnessMsg, "%u", bri);
|
||||||
|
sendToBroker("report/brightness", brightnessMsg);
|
||||||
|
|
||||||
|
// Report current signal strength
|
||||||
|
String signal(WiFi.RSSI(), 10);
|
||||||
|
sendToBroker("report/signal", signal.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user