jonathanadams / esphome-configs

ESPHome Device Configurations Repository - A database of user submitted configurations for a variety of devices which can be flashed to run ESPHome.io firmware.
https://ESPHome-Configs.io
GNU General Public License v3.0
68 stars 96 forks source link

Using MJ-SD01 for Tessan Dimmer (MJ-SD02) creates flickering LEDs #161

Open samandjt opened 3 years ago

samandjt commented 3 years ago

Thanks for the great resource. As noted, I used the configuration from MJ-SD01 and applied it as is to the Tessan Dimmer (MJ-SD02).

Everything seems to be a perfect mapping. However I noticed that in the "off" state, the LEDs flicker, which I did not notice on the MJ-SD01.

In looking at the configuration, I believe the issue is caused by the lack of nesting of the if statements in the interval:

         if (dimmer_vals.is_on()) {
            id(dimmer_lvl) = dimmer_vals.get_brightness();
          }
          if (id(dimmer_lvl) > .19) { id(led2).turn_on(); }
          if (id(dimmer_lvl) < .20) { id(led2).turn_off(); }
          if (id(dimmer_lvl) > .39) { id(led3).turn_on(); }
          if (id(dimmer_lvl) < .40) { id(led3).turn_off(); }
          if (id(dimmer_lvl) > .59) { id(led4).turn_on(); }
          if (id(dimmer_lvl) < .60) { id(led4).turn_off(); }
          if (id(dimmer_lvl) > .79) { id(led5).turn_on(); }
          if (id(dimmer_lvl) < .80) { id(led5).turn_off(); }
          if (!dimmer_vals.is_on()) {
            id(led2).turn_off();
            id(led3).turn_off();
            id(led4).turn_off();
            id(led5).turn_off();
          }

Because the if (id(dimmer_lvl) > .19) { id(led2).turn_on(); } statements are not in the if (dimmer_vals.is_on()) block the LED lights are briefly toggled on prior to being turned of in the if (!dimmer_vals.is_on()).

This reorganization addresses the flickering, at least in my case.

          if (dimmer_vals.is_on()) {
            id(dimmer_lvl) = dimmer_vals.get_brightness();
            if (id(dimmer_lvl) > .19) { id(led2).turn_on(); }
            if (id(dimmer_lvl) < .20) { id(led2).turn_off(); }
            if (id(dimmer_lvl) > .39) { id(led3).turn_on(); }
            if (id(dimmer_lvl) < .40) { id(led3).turn_off(); }
            if (id(dimmer_lvl) > .59) { id(led4).turn_on(); }
            if (id(dimmer_lvl) < .60) { id(led4).turn_off(); }
            if (id(dimmer_lvl) > .79) { id(led5).turn_on(); }
            if (id(dimmer_lvl) < .80) { id(led5).turn_off(); }
          }
          if (!dimmer_vals.is_on()) {
            id(led2).turn_off();
            id(led3).turn_off();
            id(led4).turn_off();
            id(led5).turn_off();
          }

Hope this is helpful.

Again, great resource.