Example of using DimmerBase

RNash2000
Posts: 7
Joined: Mon Jun 28, 2021 2:15 am

I am not a programmer, but I am a hobbyist, and I have adapted and modified code to complete several projects. I am trying to convert a project I have done that uses an ESP8266/arduino to interface Amazon Alexa with several light dimmers that use the old "X10" control technology.

I have the software and hardware working with EspAlexa (an arduino based Phillips Hue emulator) to talk with Alexa, but I believe supla would work much better. I have multiple dimmers controlled by one ESP8266 by sending serial data to another arduino. It does not have any physical pins assigned to the dimmers, the second arduino sends the correct pulses to a X10 Firechracker controller.

I have an ESP8266 registered with supla for a RGB LED/Dimmer and can see on the serial monitor that it is being controlled it with Alexa, but I cannot figure out the code being used to return the channel number and brightness value.

I simply want to do something like:
if (channelNumber == 1) { // which supla channel was changed?
AlexaBrightness = brightness; // what is the supla brightness value?
recordNumber = 1; // change recordNumber to current supla channel number
sendSerial; // send dimmer number and brightness value to the second arduino controller.
}

Also, is there a way to register a DimmerBase without RGB Led control?
Some examples of returning channel number and brightness value would be appreciated.

Thanks in advance for any help.
RNash2000
RNash2000
Posts: 7
Joined: Mon Jun 28, 2021 2:15 am

Perhaps I gave a little too much information.
Let' s try this question:

Could someone show me a supla/arduino example of the functions that were used to Serial.print the channel number and RGB values in the following line of serial monitor?
"Channel(0) value changed to RGB(0, 255, 0), colBr(0), bright(100)"

Thank you.
User avatar
klew
Posts: 8178
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Hi
You can start with checking DimmerLeds class implementation.
It is simple example how to override DimmerBase methods in order to control LEDs.
You can ignore RGB related parameters.

This print is from here: https://github.com/SUPLA/supla-arduino/ ... l.cpp#L266

However you should rather focus on DimmerLeds example.

I'll try to help more, however I'll be available on Monday
Widzimy się na Supla Offline Party vol. 2 :!:
RNash2000
Posts: 7
Joined: Mon Jun 28, 2021 2:15 am

Thank you for the reply!
Using DimmerLEDs did let me register multiple Dimmer devices without the RGB controls showing in the app.

I'm still trying to figure out how to return the brightness value.

Really appreciate your help.
User avatar
klew
Posts: 8178
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław

Hi

DimmerLeds was intended to be an example how to handle this data :).
More or less you should do something like this:

Code: Select all

class MyDimmer : public Supla::Control::DimmerBase {
  public:
    MyDimmer(....) { } // define your constructor here where you pass parameters that will identify your dimmer device on serial interface
    void onInit() {...} // here put all initialization code (this method is called once during SuplaDevice.setup()
   void setRGBWValueOnDevice(uint32_t red,
                            uint32_t green,
                            uint32_t blue,
                            uint32_t colorBrightness,
                            uint32_t brightness) {
            // you can ignore not dimmer related parameters, so "brightness" is the only one you need
            // implement here sending brightness value over serial interface
            ...
        }
};

// then in setup()
auto dim1 = new MyDimmer(...); // here you pass constructor parameters that will be used to identify your dimmer on serial interface
auto dim2 = new MyDimmer(...); 
// etc
Each instance of MyDimmer class will be visible in Supla app as single dimmer channel. Each instance should also send parameters over serial interface about single dimmer.
So you don't need to have any information about channelNumber, since setRGBWValueOnDevice() method will be called on a specific instance. So if you'll provide data that identify dimmer on serial interface to instance of MyDimmer class, then it will use those parameters to talk directly to that "device".

If you are not familiar with classes and object oriented programming, then please share your current code and I'll adjust it.
Widzimy się na Supla Offline Party vol. 2 :!:
RNash2000
Posts: 7
Joined: Mon Jun 28, 2021 2:15 am

I finally got a chance to work on this. I had not worked much with classes but your example was very helpful, Thank You!
I think I can make it work now. But I have another question.
The "setRGBWValueOnDevice" function is returning "brightness" about every 10 digits in steps - up and down - until the brightness level is reached. I guess to gradually dim and brighten.
I need the brightness level to only be returned once, so I can send my serial info one time per change.
Can the dimmer be changed at set-up not to step?
Thank for your help.
Roger
elmaya
Posts: 1482
Joined: Wed Jun 27, 2018 5:48 pm
Location: El Saucejo - Sevilla

RNash2000 wrote: Fri Jul 16, 2021 1:07 am I finally got a chance to work on this. I had not worked much with classes but your example was very helpful, Thank You!
I think I can make it work now. But I have another question.
The "setRGBWValueOnDevice" function is returning "brightness" about every 10 digits in steps - up and down - until the brightness level is reached. I guess to gradually dim and brighten.
I need the brightness level to only be returned once, so I can send my serial info one time per change.
Can the dimmer be changed at set-up not to step?
Thank for your help.
Roger
in setup, after constructor parameters

Code: Select all

  setFadeEffectTime(0);
RNash2000
Posts: 7
Joined: Mon Jun 28, 2021 2:15 am

Perfect!
Thank you very much for your help with this.
RNash2000
Posts: 7
Joined: Mon Jun 28, 2021 2:15 am

I have supla controlling /dimming 16 of my x10 controlled lights and working very well with Alexa. However, there is a problem when the light is switched on manually or with another controller. Supla does not know that it is on and will not issue a "0" brightness command to the ESP8266 when instructed from Alexa. There is no way to notify supla of the change of state. Is there a way to cause supla to execute an off command even if in the off state?
User avatar
pzygmunt
Posts: 18207
Joined: Tue Jan 19, 2016 9:26 am
Location: Paczków
Contact:

This is what the firmware determines
Post Reply

Return to “Help”