I've been experimenting with SUPLA since yesterday on an ESP8266 board and have managed to use one of the demo sketches to control two relays, each showing as switches in the SUPLA app, and much to my delight have added both of these switches to my google home devices and can control them using my smart speaker. So far, so good!
However, my finished project will have five relays, and I only want one to be on at any one time. If possible, I'd like my project to show as one device in google home, with the ability to set 5 different states I.E. 'Set device to state 1' ( where relay one is on, and all others are off) as opposed to five separate devices with two states (on or off).
From what I've been able to tell so far, SUPLA currently does not support such a device. Can anyone tell me if that is correct? I've not been able to find a definitive device list with the relevant capabilities in the SUPLA app or when connected to google home.
Assuming that I'm right, my idea is to create something like a dummy 'dimmable' light device, where my sketch captures the dimming level sent from the SUPLA server and uses it to switch on the appropriate relays (perhaps at 100% brightness, the sketch turns on relay one, and the others off, and at 80% it turns on relay 2, and all others off etc.)
I would then set up routines in google home so that when I ask 'Set device to state 1' it sends a command to set the brightness of the light to 100%
I'd love it if someone could tell me if this is possible, and if so point me to any example sketches or other resources where I may be able to learn how to get info sent from SUPLA server to the device and use it in my sketch.
Thanks!
Controlling a Device with more than two states
-
- Posts: 19106
- Joined: Tue Jan 19, 2016 9:26 am
- Location: Paczków
There is no such device in Supla. There is a dedicated "Dimmer" channel for dimming. You can prepare your own implementation that will enable the appropriate relays for the percentage ranges.
-
- Posts: 14
- Joined: Tue Jan 12, 2021 1:22 pm
Thanks very much for your reply.
Can you point me towards any resources which may help me understand how to capture the data from the 'Dimmer' channel?
Can you point me towards any resources which may help me understand how to capture the data from the 'Dimmer' channel?
-
- Posts: 19106
- Joined: Tue Jan 19, 2016 9:26 am
- Location: Paczków
-
- Posts: 14
- Joined: Tue Jan 12, 2021 1:22 pm
I no longer need help with the below, I took a punt and just used 'addDimmer' in place of 'addRGBControllerAndDimmer' and it worked great!
I now have a dimmer device in SUPLA, controllable via google assistant. I've got the dimming % value being returned by the serial console in the Arduino IDE, which updates as soon as I make a change via the SUPLA app or google assistant - so now have all I need to get my project working with just one device showing in the google home app.
Thanks for your help, SUPLA has solved my problem when many other avenues which I explored could not!
***Thanks! I've had a good stare at these and I think I can see a way forward.
Do you happen to have an example of 'SuplaDevice.addDimmer(); ' being used on it's own (without RGB)?
The Dimmer example you linked to is using a different nomenclature which I'm having a hard time trying to understand.
I've seen it commented out in some examples which use 'SuplaDevice.addRgbControllerAndDimmer(); '
I'd love to see how an 'add.Dimmer' example would work, that way I don't have to worry about the RGB stuff that I don't need!
Thanks again.***
I now have a dimmer device in SUPLA, controllable via google assistant. I've got the dimming % value being returned by the serial console in the Arduino IDE, which updates as soon as I make a change via the SUPLA app or google assistant - so now have all I need to get my project working with just one device showing in the google home app.
Thanks for your help, SUPLA has solved my problem when many other avenues which I explored could not!
***Thanks! I've had a good stare at these and I think I can see a way forward.
Do you happen to have an example of 'SuplaDevice.addDimmer(); ' being used on it's own (without RGB)?
The Dimmer example you linked to is using a different nomenclature which I'm having a hard time trying to understand.
I've seen it commented out in some examples which use 'SuplaDevice.addRgbControllerAndDimmer(); '
I'd love to see how an 'add.Dimmer' example would work, that way I don't have to worry about the RGB stuff that I don't need!
Thanks again.***
-
- Posts: 8
- Joined: Sun May 30, 2021 3:56 pm
Hello
I want to control 4 relays with google assistant
I Have esp8266 and i want to program it with arduino ide
can you plzz help me??
I want to control 4 relays with google assistant
I Have esp8266 and i want to program it with arduino ide
can you plzz help me??
-
- Posts: 14
- Joined: Tue Jan 12, 2021 1:22 pm
Hi!pzygmunt wrote: ↑Tue Jan 12, 2021 5:00 pm https://github.com/SUPLA/supla-espressi ... d/dimmer.c
https://github.com/SUPLA/arduino/blob/d ... W/RGBW.ino
Thanks again for your help on getting my project set up a few years ago!
I'm trying to update my project to work with the newer device library and I'm struggling slightly, so just wanted to make sure I'm on the right track before I bang my head against it much more.
My project uses a dimmer channel to capture the brightness value and toggle one or more relays based on the range it falls within:
Code: Select all
#include <srpc.h>
#include <log.h>
#include <eh.h>
#include <proto.h>
#include <IEEE754tools.h>
// We define our own ethernet layer
#define SUPLADEVICE_CPP
#include <SuplaDevice.h>
#include <lck.h>
#include <WiFiClient.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiServer.h>
#include <ESP8266WiFiGeneric.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiSTA.h>
#include <WiFiUdp.h>
int Def0 = 0;
int Def1 = 12;
int Def2 = 13;
int Def3 = 14;
int Def4 = 5;
int Def5 = 4;
unsigned char _red = 0;
unsigned char _green = 0;
unsigned char _blue = 0;
unsigned char _color_brightness = 0;
unsigned char _brightness = 0;
void get_rgbw_value(int channelNumber, unsigned char *red, unsigned char *green, unsigned char *blue, unsigned char *color_brightness, unsigned char *brightness) {
*brightness = _brightness;
*color_brightness = _color_brightness;
*red = _red;
*green = _green;
*blue = _blue;
}
void set_rgbw() {
//Serial.println(_brightness);
switch (_brightness) {
case 0: //Turn off Main Relay
Serial.println("Turning off...");
digitalWrite(Def5, LOW);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, LOW);
digitalWrite(Def2, LOW);
digitalWrite(Def1, LOW);
digitalWrite(Def0, LOW);
break;
case 1 ... 20:
Serial.println("Going to DEFCON 1");
digitalWrite(Def5, LOW);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, LOW);
digitalWrite(Def2, LOW);
digitalWrite(Def1, HIGH);
digitalWrite(Def0, HIGH);
break;
case 21 ... 40:
Serial.println("Going to DEFCON 2");
digitalWrite(Def5, LOW);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, LOW);
digitalWrite(Def2, HIGH);
digitalWrite(Def1, LOW);
digitalWrite(Def0, HIGH);
break;
case 41 ... 60:
Serial.println("Going to DEFCON 3");
digitalWrite(Def5, LOW);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, HIGH);
digitalWrite(Def2, LOW);
digitalWrite(Def1, LOW);
digitalWrite(Def0, HIGH);
break;
case 61 ... 80:
Serial.println("Going to DEFCON 4");
digitalWrite(Def5, LOW);
digitalWrite(Def4, LOW);
digitalWrite(Def3, LOW);
digitalWrite(Def2, LOW);
digitalWrite(Def1, LOW);
digitalWrite(Def0, HIGH);
break;
case 81 ... 100:
Serial.println("Going to DEFCON 5");
digitalWrite(Def5, HIGH);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, LOW);
digitalWrite(Def2, LOW);
digitalWrite(Def1, LOW);
digitalWrite(Def0, HIGH);
break;
}
}
void set_rgbw_value(int channelNumber, unsigned char red, unsigned char green, unsigned char blue, unsigned char color_brightness, unsigned char brightness) {
_brightness = brightness;
_color_brightness= color_brightness;
_red = red;
_green = green;
_blue = blue;
set_rgbw();
}
WiFiClient client;
// Setup Supla connection
const char* ssid = "MY SSID";
const char* password = "MY PASS";
void setup() {
Serial.begin(115200);
delay(10);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(0, OUTPUT);
pinMode(14, OUTPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
set_rgbw();
// Set RGBW callbacks
SuplaDevice.setRGBWCallbacks(&get_rgbw_value, &set_rgbw_value);
// Replace the falowing GUID
char GUID[SUPLA_GUID_SIZE] = {"GUID""};
// with GUID that you can retrieve from https://www.supla.org/arduino/get-guid
// Ethernet MAC address
uint8_t mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
/*
* Having your device already registered at cloud.supla.org,
* you want to change CHANNEL sequence or remove any of them,
* then you must also remove the device itself from cloud.supla.org.
* Otherwise you will get "Channel conflict!" error.
*/
SuplaDevice.addDimmer();
SuplaDevice.begin(GUID, // Global Unique Identifier
mac, // Ethernet MAC address
"svr37.supla.org", // SUPLA server address
xxx, // Location ID
"xxxx"); // Location Password
}
void loop() {
SuplaDevice.iterate();
}
// Supla.org ethernet layer
int supla_arduino_tcp_read(void *buf, int count) {
_supla_int_t size = client.available();
if ( size > 0 ) {
if ( size > count ) size = count;
return client.read((uint8_t *)buf, size);
};
return -1;
};
int supla_arduino_tcp_write(void *buf, int count) {
return client.write((const uint8_t *)buf, count);
};
bool supla_arduino_svr_connect(const char *server, int port) {
return client.connect(server, 2015);
}
bool supla_arduino_svr_connected(void) {
return client.connected();
}
void supla_arduino_svr_disconnect(void) {
client.stop();
}
void supla_arduino_eth_setup(uint8_t mac[6], IPAddress *ip) {
Serial.println("WiFi init");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
// Serial.print(".");
}
Serial.print("\nlocalIP: ");
Serial.println(WiFi.localIP());
Serial.print("subnetMask: ");
Serial.println(WiFi.subnetMask());
Serial.print("gatewayIP: ");
Serial.println(WiFi.gatewayIP());
}
SuplaDeviceClass supla_arduino_get_callbacks(void) {
SuplaDeviceCallbacks cb;
cb.tcp_read = &supla_arduino_tcp_read;
cb.tcp_write = &supla_arduino_tcp_write;
cb.eth_setup = &supla_arduino_eth_setup;
cb.svr_connected = &supla_arduino_svr_connected;
cb.svr_connect = &supla_arduino_svr_connect;
cb.svr_disconnect = &supla_arduino_svr_disconnect;
cb.get_temperature = NULL;
cb.get_temperature_and_humidity = NULL;
cb.get_rgbw_value = NULL;
cb.set_rgbw_value = NULL;
return cb;
}
I've read through 'How to migrate programs written in SuplaDevice library versions 1.6 and older', and mostly that makes sense, what I'm not sure about is how the newer version of the dimmer channel ('DimmerBase' is what I want, I think?) compares to the older one, and what I should keep and what I should get rid of.
Can you confirm that my custom dimmer implementation can work with the 'DimmerBase' control?
I think that if so, I'd want to base it on this: https://github.com/SUPLA/supla-arduino/ ... r_base.cpp
Is that right? If so, can you tell me which, if any of the functions used in the old dimmer control (as used in my code) and the new dimmer_base control relate to each other?
I'd also like to include the functionality from the web interface example, would you recommend starting with that and adding what I need from dimmer_base.cpp and then my old custom parts from my project?
Last edited by Allendrome_ on Sat Jun 15, 2024 6:20 am, edited 1 time in total.
-
- Posts: 9413
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
It would be best if you'll just start with WebInterface example from Arduino Ide.Allendrome_ wrote: ↑Fri Jun 14, 2024 11:27 pm I'm trying to update my project to work with the newer device library and I'm struggling slightly, so just wanted to make sure I'm on the right track before I bang my head against it much more.
Remove from it all buttons, roller shutters, relays, so your setup() method will look like this:
Code: Select all
void setup() {
Serial.begin(115200);
// Buttons configuration
// auto buttonCfgRelay = new Supla::Control::Button(BUTTON_CFG__GPIO, true, true);
// buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
auto dimmer = new MyDimmer();
// configure defualt Supla CA certificate
SuplaDevice.setSuplaCACert(suplaCACert);
SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
SuplaDevice.begin();
}
Then add following implementation of MyDimmer class:
Code: Select all
class MyDimmer : public Supla::Control::DimmerBase {
public:
void setRGBWValueOnDevice(uint32_t red,
uint32_t green,
uint32_t blue,
uint32_t colorBrightness,
uint32_t brightness) override { } // empty method
void setRGBW(int red,
int green,
int blue,
int colorBrightness,
int brightness,
bool toggle = false) override {
Supla::Control::DimmerBase(red, green, blue, colorBrightness, brightness, toggle);
int _brightness = getChannel()->getValueBrightness();
// put here your code with "switch (_brightness)" etc
}
};
Method setRGBWValueOnDevice has to be implemted here (because it's defined in base class as pure virtual). You could also try to attach to this method, but it works differently. Brighness level there will be adjusted in steps (for fade effect) etc.
In setRGBW this call to base class is needed to setup dimmer channel value properly, and then we read channel brightness value. This way you'll also get proper handling of "toggle" parameter without any additional implementation.
I have not tested above code and not compiled it, so I can't guarantee that there are no mistakes nor typos
Kiedy będzie Supla Offline Party / SOP#2025 ?
-
- Posts: 14
- Joined: Tue Jan 12, 2021 1:22 pm
Thanks very much for your help!
I've created a sketch starting from the Webinterface example as you suggested, and I think I've added all the relevant pieces:
When I try to compile I get the following error:
I'm not sure why this. I've checked rgbw_base.h and SetRGBW() is virtual. However SetRGBW() is also defined in the DimmerBase class in dimmer_base.h. Am I including the right libraries in my sketch for this application?
I've tried removing 'override' from the line "bool toggle = false) override {" but that just causes more errors!
I've created a sketch starting from the Webinterface example as you suggested, and I think I've added all the relevant pieces:
Code: Select all
#define STATUS_LED_GPIO 2
#include <SuplaDevice.h>
#include <supla/network/esp_wifi.h>
#include <supla/control/dimmer_base.h>
#include <supla/device/status_led.h>
#include <supla/storage/littlefs_config.h>
#include <supla/network/esp_web_server.h>
#include <supla/network/html/device_info.h>
#include <supla/network/html/protocol_parameters.h>
#include <supla/network/html/status_led_parameters.h>
#include <supla/network/html/wifi_parameters.h>
#include <supla/device/supla_ca_cert.h>
#include <supla/events.h>
//define variables to assign Correct IO Pins to The correct defcon level
int Def0 = 0;
int Def1 = 12;
int Def2 = 13;
int Def3 = 14;
int Def4 = 5;
int Def5 = 4;
Supla::ESPWifi wifi;
Supla::LittleFsConfig configSupla;
Supla::Device::StatusLed statusLed(STATUS_LED_GPIO, true); // inverted state
Supla::EspWebServer suplaServer;
// HTML www component (they appear in sections according to creation
// sequence)
Supla::Html::DeviceInfo htmlDeviceInfo(&SuplaDevice);
Supla::Html::WifiParameters htmlWifi;
Supla::Html::ProtocolParameters htmlProto;
Supla::Html::StatusLedParameters htmlStatusLed;
//Class to customise Dimmer control
class MyDimmer : public Supla::Control::DimmerBase {
public:
void setRGBWValueOnDevice(uint32_t red,
uint32_t green,
uint32_t blue,
uint32_t colorBrightness,
uint32_t brightness) override { } // empty method
void setRGBW(int red,
int green,
int blue,
int colorBrightness,
int brightness,
bool toggle = false) override {
Supla::Control::DimmerBase(red, green, blue, colorBrightness, brightness, toggle);
int _brightness = getChannel()->getValueBrightness();
// put here your code with "switch (_brightness)" etc
switch (_brightness) {
case 0: //Turn off Main Relay
Serial.println("Turning off...");
digitalWrite(Def5, LOW);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, LOW);
digitalWrite(Def2, LOW);
digitalWrite(Def1, LOW);
digitalWrite(Def0, LOW);
break;
case 1 ... 20:
Serial.println("Going to DEFCON 1");
digitalWrite(Def5, LOW);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, LOW);
digitalWrite(Def2, LOW);
digitalWrite(Def1, HIGH);
digitalWrite(Def0, HIGH);
break;
case 21 ... 40:
Serial.println("Going to DEFCON 2");
digitalWrite(Def5, LOW);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, LOW);
digitalWrite(Def2, HIGH);
digitalWrite(Def1, LOW);
digitalWrite(Def0, HIGH);
break;
case 41 ... 60:
Serial.println("Going to DEFCON 3");
digitalWrite(Def5, LOW);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, HIGH);
digitalWrite(Def2, LOW);
digitalWrite(Def1, LOW);
digitalWrite(Def0, HIGH);
break;
case 61 ... 80:
Serial.println("Going to DEFCON 4");
digitalWrite(Def5, LOW);
digitalWrite(Def4, LOW);
digitalWrite(Def3, LOW);
digitalWrite(Def2, LOW);
digitalWrite(Def1, LOW);
digitalWrite(Def0, HIGH);
break;
case 81 ... 100:
Serial.println("Going to DEFCON 5");
digitalWrite(Def5, HIGH);
digitalWrite(Def4, HIGH);
digitalWrite(Def3, LOW);
digitalWrite(Def2, LOW);
digitalWrite(Def1, LOW);
digitalWrite(Def0, HIGH);
break;
}
}
};
void setup() {
Serial.begin(115200);
// Buttons configuration
// auto buttonCfgRelay = new Supla::Control::Button(BUTTON_CFG__GPIO, true, true);
// buttonCfgRelay->configureAsConfigButton(&SuplaDevice);
auto dimmer = new MyDimmer();
// configure defualt Supla CA certificate
SuplaDevice.setSuplaCACert(suplaCACert);
SuplaDevice.setSupla3rdPartyCACert(supla3rdCACert);
SuplaDevice.begin();
}
void loop() {
SuplaDevice.iterate();
}
Code: Select all
DEFCON_new_library_latest:79:10: error: 'void MyDimmer::setRGBW(int, int, int, int, int, bool)' marked 'override', but does not override
79 | void setRGBW(int red,
| ^~~~~~~
C:\Users\Alexa\Documents\Arduino\DEFCON_new_library_latest\DEFCON_new_library_latest.ino: In member function 'void MyDimmer::setRGBW(int, int, int, int, int, bool)':
DEFCON_new_library_latest:85:91: error: invalid cast to abstract class type 'Supla::Control::DimmerBase'
85 | Supla::Control::DimmerBase(red, green, blue, colorBrightness, brightness, toggle);
| ^
In file included from C:\Users\Alexa\Documents\Arduino\DEFCON_new_library_latest\DEFCON_new_library_latest.ino:36:
C:\Users\Alexa\Documents\Arduino\libraries\SuplaDevice\src/supla/control/dimmer_base.h:26:7: note: because the following virtual functions are pure within 'Supla::Control::DimmerBase':
26 | class DimmerBase : public RGBWBase {
| ^~~~~~~~~~
In file included from C:\Users\Alexa\Documents\Arduino\libraries\SuplaDevice\src/supla/control/dimmer_base.h:22,
from C:\Users\Alexa\Documents\Arduino\DEFCON_new_library_latest\DEFCON_new_library_latest.ino:36:
C:\Users\Alexa\Documents\Arduino\libraries\SuplaDevice\src/supla/control/rgbw_base.h:76:16: note: 'virtual void Supla::Control::RGBWBase::setRGBWValueOnDevice(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t)'
76 | virtual void setRGBWValueOnDevice(uint32_t red,
| ^~~~~~~~~~~~~~~~~~~~
exit status 1
'void MyDimmer::setRGBW(int, int, int, int, int, bool)' marked 'override', but does not override
I've tried removing 'override' from the line "bool toggle = false) override {" but that just causes more errors!
-
- Posts: 9413
- Joined: Thu Jun 27, 2019 12:16 pm
- Location: Wrocław
Please quote me when you reply (even empty quote) - this way I'll get notification about your post and I'll reply quicker
Change:
Code: Select all
void setRGBW(int red,
int green,
int blue,
int colorBrightness,
int brightness,
bool toggle = false) override {
Code: Select all
void setRGBW(int red,
int green,
int blue,
int colorBrightness,
int brightness,
bool toggle = false,
bool instant = false) override {
Kiedy będzie Supla Offline Party / SOP#2025 ?