Slider widget to control dimming of lamps

Hello,

I’m using an ESP8266 NodeMcu ESP-12E, with a dimmer module (https://robotdyn.com/ac-light-dimmer-module-1-channel-3-3v-5v-logic-ac-50-60hz-220v-110v.html) to control the dimming of lamps/fans,etc.

I’m using the browser, website version of cayenne dashboard.

I’m using a slider widget, on cayenne dashboard, to control the dimming level of the load connected to the dimmer module. That dimmer module is powered and controled by the NodeMcu.

When I use this code, to control the dimmer with the serial monitor of Arduino IDE, it works perfectly:

#include <RBDdimmer.h>//

//#define USE_SERIAL SerialUSB //Serial for boards whith USB serial port
#define USE_SERIAL Serial
#define outputPin 12
#define zerocross 5 // for boards with CHANGEBLE input pins

dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
//dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero

int outVal = 0;

void setup() {
USE_SERIAL.begin(9600);
dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE)
USE_SERIAL.println(“Dimmer Program is starting…”);
USE_SERIAL.println(“Set value”);
}

void printSpace(int val)
{
if ((val / 100) == 0) USE_SERIAL.print(" “);
if ((val / 10) == 0) USE_SERIAL.print(” ");
}

void loop() {
int preVal = outVal;

if (USE_SERIAL.available())
{
int buf = USE_SERIAL.parseInt();
if (buf != 0) outVal = buf;
delay(200);
}
dimmer.setPower(outVal); // setPower(0-100%);

if (preVal != outVal)
{
USE_SERIAL.print(“lampValue -> “);
printSpace(dimmer.getPower());
USE_SERIAL.print(dimmer.getPower());
USE_SERIAL.println(”%”);

}
delay(50);
}

I use this code to control the dimmer with the slider bar widget of cayenne:

#include <RBDdimmer.h>//
#include <CayenneMQTTESP8266.h>

//#define USE_SERIAL SerialUSB //Serial for boards whith USB serial port
//#define USE_SERIAL Serial
#define CAYENNE_PRINT Serial
#define outputPin 12
#define zerocross 5 // for boards with CHANGEBLE input pins

dimmerLamp dimmer(outputPin, zerocross); //initialase port for dimmer for ESP8266, ESP32, Arduino due boards
//dimmerLamp dimmer(outputPin); //initialase port for dimmer for MEGA, Leonardo, UNO, Arduino M0, Arduino Zero

int outVal = 0;
float tensao = 0;

char ssid = “xx”;
char wifiPassword = “xx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xx”;
char password = “xx”;
char clientID = “xx”;

void setup() {
Serial.begin(115200);
dimmer.begin(NORMAL_MODE, ON); //dimmer initialisation: name.begin(MODE, STATE)
dimmer.setPower(outVal);
// USE_SERIAL.println(“Dimmer Program is starting…”);
// USE_SERIAL.println(“Set value”);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
Cayenne.loop();
dimmer.setPower(outVal);

}

CAYENNE_IN(2)
{
outVal = getValue.asInt();
Serial.print(“Cayenne_tarBrightness->”);
Serial.println(outVal);
}

I can control the dimming level of the lamp, but sometimes the lamp turns off randomly, sometimes it turns off without my order, sometimes it turns on witout my order.
The widget normally is like this:


But when I click on the cayenne dashboard on another device, the slider widget appears with a “-” in the numerical % value visually.

Is it a bug?

Thank you

check your serial monitor if you are getting the data when the slider position is changed.

add this in the CAYENNE_IN(2),so that it only changes when the slider is changed.