Yes I thought of that after I posted. Maybe a wemos or similar would do the trick.
Anyway nice hack, I love it.
Yes I thought of that after I posted. Maybe a wemos or similar would do the trick.
Anyway nice hack, I love it.
Yes the relay button still works because it’s configured to. It’s not hard wired.
If you use a diff esp platform you def could do it.
But sonoff basic has the built in psu, the relay, enclosure etc for $5
Yeah it is really good value.
The power supply used to power the wemos in HAswitchplate https://github.com/aderusha/HASwitchPlate is a pretty good option IMHO. But yes, the whole thing does end up being a quite a bit more.
For your average dimmer situation a sonoff is good, if you wanted a couple of more versatile rotaries in a couple of places, there are options. That’s the good thing about making, the possibilities are endless.
That project is nice, and I agree about the PCB the OP designed.
Its probably a better high voltage design, but def costs more (money and work)
Hello Please Help. i have this dimmer and the code for it is (attached)
i can control the dimmer from the web http page provided by seller
i want to control it over mqtt i can turn it off and on sending mqtt commands from home assistant config page pay load commands R13_ON & R13_OFF
I am a beginner trying to learn everything the guy keeps telling me the dimmer command is Dimmer as i can see in the code but it does not do any thing my home assistant config for this is
my home assistant configs are , i am able to turn off & on but not brightness from the http panel of the product i can control brightness
light:
please help Thanks in advance
boolean connectMQTT() {
if (mqttClient.connected()) {
return true;
}
Serial.print("Connecting to MQTT server “);
Serial.print(mqttServer);
Serial.print(” as ");
Serial.println(host);
if (mqttClient.connect(host)) {
Serial.println(“Connected to MQTT broker”);
if (mqttClient.subscribe((char*)subTopic.c_str())) {
Serial.println(“Subsribed to topic.”);
} else {
Serial.println(“NOT subsribed to topic!”);
}
return true;
}
else {
Serial.println("MQTT connect failed! ");
return false;
}
}
void disconnectMQTT() {
mqttClient.disconnect();
}
void mqtt_handler() {
if (toPub == 1) {
Debugln(“DEBUG: Publishing state via MQTT”);
if (pubState()) {
toPub = 0;
}
}
mqttClient.loop();
delay(100); //let things happen in background
}
void mqtt_arrived(char* subTopic, byte* payload, unsigned int length) { // handle messages arrived
int i = 0;
// Serial.print("MQTT message arrived: topic: " + String(subTopic));
// create character buffer with ending null terminator (string)
for (i = 0; i < length; i++) {
buf[i] = payload[i];
}
buf[i] = ‘\0’;
String msgString = String(buf);
Serial.println(" message: " + msgString);
if (msgString.substring(0,6) == “R13_ON”) **
** {
** Serial.println(“Dimmer:99”);**
** } **
** else if (msgString.substring(0,7) == “R13_OFF”) **
** {**
** Serial.println(“Dimmer:0”);**
}
else if (msgString.substring(0,6) == “R14_ON”)
{
Serial.println(“R_1 switched via web request to 1”);
}
else if (msgString.substring(0,7) == “R14_OFF”)
{
Serial.println(“R_1 switched via web request to 0”);
}
else if (msgString.substring(0,7) == “Dimmer:”)
{
Serial.print(“Dimmer:”);
Serial.println(msgString.substring(7,9));
}
}
boolean pubState() { //Publish the current state of the light
if (!connectMQTT()) {
delay(100);
if (!connectMQTT) {
Serial.println(“Could not connect MQTT.”);
Serial.println(“Publish state NOK”);
return false;
}
}
if (mqttClient.connected())
{
Serial.println("To publish state " + state );
if (mqttClient.publish((char*)pubTopic.c_str(), (char*) state.c_str())) {
Serial.println(“Publish state OK”);
return true;
}
else
{
Serial.println(“Publish state NOK”);
return false;
}
}
else
{
Serial.println(“Publish state NOK”);
Serial.println(“No MQTT connection.”);
}
}
String getValue(String data, char separator, int index)
{
int found = 0;
int strIndex[] = {
0, -1
};
int maxIndex = data.length() - 1;
for (int i = 0; i <= maxIndex && found <= index; i++) {
if (data.charAt(i) == separator || i == maxIndex) {
found++;
strIndex[0] = strIndex[1] + 1;
strIndex[1] = (i == maxIndex) ? i + 1 : i;
}
}
return found > index ? data.substring(strIndex[0], strIndex[1]) : “”;
}
Changing out the on trigger automation for state resulted in no errors at the 0 rotation and full scale rotation.
Using this in this string for the normalised dimmer brightness, gives a non linear or to the power of 2 increase in brightness. I set the rotary encoder at 1 pulse per revolution and for a maximum count of 16. 16 ** 2 = 256. It give alot finer control at low dimming where required and get’s to full brightness in 16 steps or just over 3/4 turn. Really like this project I learnt a lot from it. Thankyou.
Nice! Thanks for sharing
I’m getting so much out of this project, if you set up the input as a normal switch, then the mqtt output toggles 0 > 1 > 0 everytime you press it. You only need one automation to toggle the light in Home Assistant. In addition if you set up rules on the ESP easy and a second binary sensor you can get a long press on the button to give you a second functionality like a scene, ie turn off all the other lights ect…
You’re doing great!
If you find a way to do short/long press then I’d love to know!
Eg short to toggle light, long to to toggle relay or similar
I would too love to be able to toggle the relay on a long press! Great work from you both @hijinx @Paul_Fisher Just got a blanking plate and some rotary knobs so almost ready to install the final product!
OK there are two ways to do it, I’m set up on button1 with state as the variable name.
Here is the first, the issue is you have to wait 1 sec before you get a message for a short press or a long press, so the button feels unresponsive
on Button1#State=1 do
timerSet,1,1
endon
on rules#timer=1 do
if [Button1#State]=0
//Action if button is short pressed
Publish cmnd/21cameron/lounge_dimmer1/button1/state,1
Delay 100
Publish cmnd/21cameron/lounge_dimmer1/button1/state,0
else
//Action if button is still pressed
Publish cmnd/21cameron/lounge_dimmer1/button1/state,2
Delay 100
Publish cmnd/21cameron/lounge_dimmer1/button1/state,0
endif
endon
If you make a dummy device called timer1 set the value name to state and the decimals to 0 with a 1 second interval.
You will get the value 1 on the mqtt immediately after you release the button on the short press, your cycle time is still 1 sec, it may be 2 before you can press again but the button feels responsive on the short press.
on Button1#State=1 do
TaskValueSet 3,1,0
TimerSet,1,1
Delay 200
endon
on rules#timer=1 do
TaskValueSet 3,1,1
if [Button1#State]=1
//Action if button is still pressed
Publish cmnd/21cameron/lounge_dimmer1/button1/state,2
Delay 200
Publish cmnd/21cameron/lounge_dimmer1/button1/state,0
endif
endon
on Button1#State=0 do
if [Timer1#State]=0
Publish cmnd/21cameron/lounge_dimmer1/button1/state,1
Delay 200
Publish cmnd/21cameron/lounge_dimmer1/button1/state,0
endif
endon
This is my latest implementation and what I recommend, this is the rule in espeasy configuration on the dimmer
on rotary1#state do
TaskValueSet 2,1,[rotary1#state]*[rotary1#state]
Publish cmnd/21cameron/%sysname%/dimmer1/state,[dimmer1#state]
endon
on button1#state=1 do
if [dimmer1#state]!=0 and [timer1#state]=2
TaskValueSet 2,1,0
Publish cmnd/21cameron/%sysname%/dimmer1/state,[dimmer1#state]
TaskValueSet 12,1,1
else
TaskValueSet 12,1,0
endif
TimerSet,1,1
endon
on button1#state=0 do
else
if [timer1#state]=0 and [dimmer1#state]=0
TaskValueSet 2,1,256
Publish cmnd/21cameron/%sysname%/dimmer1/state,[dimmer1#state]
TaskValueSet 12,1,0
Delay 100
endif
endon
on rules#timer=1 do
TaskValueSet 12,1,2
if [button1#state]=1
TaskValueSet 2,1,[rotary1#state]*[rotary1#state]
Publish cmnd/21cameron/%sysname%/dimmer1/state,[dimmer1#state]
endif
endon