Esphomelib - A comprehensive solution for using ESPs with Home Assistant

@Stoney Are you talking about a hassio addon?

Hi @OttoWinter I was looking for ways to implement speed control / dimming with ESP’s and discovered these. Would it be possible to create a component in ESPhome to drive them? (I don’t have the skills to do so, working on it…)

EDIT: Looking at the Generic Custom Component under ESPhome I guess I could try and use code from here to put something together. Thats if I get some time. I’d really like to get this working with a rotary encoder to adjust the dimming. I think they could prove to be a very cost effective HA compatible dimmer / fan controller.

Yes, I should have specified, 64-bit version of Hass.io.
From the addon page:
" NOTE : Installation on RPis running in 64-bit mode is currently not possible. Please use the 32-bit variant of HassOS instead."

Is there a way to add more light effects to FastLed light?

@INTEL, l Here’s an except out of a YAML file for a project I did with esphome where I defined a number of additional FastLED effects. I had a string of 100 WS2812 LEDs arranged as a stack of rings that looks like this:


Some of the effects are defined like this:

light:
  - platform: fastled_clockless
    chipset: WS2811
    pin: GPIO13
    num_leds: 100
    rgb_order: RGB
    name: "Tower"
    id: tower
    effects:
      - flicker:
      - fastled_rainbow:
      - fastled_color_wipe:
      - fastled_scan:
      - fastled_twinkle:
      - fastled_random_twinkle:
      - fastled_fireworks:
      - fastled_flicker:
      - fastled_lambda:
          name: rings
          update_interval: 100ms
          lambda: |-
            static uint8_t current_ring = 0;
            static uint8_t current_hue = 0;
            auto leds = it.leds();
            fadeToBlackBy(leds, it.size(), 100);
            current_ring = (current_ring + 1) % led_rings;
            for (int i = 0; i < led_ringsize; i++)
                leds[ledoffset(current_ring, i)] = CHSV(current_hue, 255, 200);
            if (current_ring >= led_rings - 1)
                leds[0] = CHSV(current_hue, 255, 255);

            if (current_ring == 0) {
                current_hue += 10;
                if (current_hue > 255)
                    current_hue = 0;
            }

            it.schedule_show();

      - fastled_lambda:
          name: "Red Alert"
          update_interval: 100ms
          lambda: |-
            static uint8_t current_ring = 0;
            fadeToBlackBy(it.leds(), it.size(), 100);
            current_ring = (current_ring + 1) % led_rings;
            for (int i = 0; i < led_ringsize; i++)
                it.leds()[ledoffset(current_ring, i)] = CHSV(0, 255, (128 * current_ring)/(led_rings - 1) + 127);

            if (current_ring >= led_rings - 1)
                it.leds()[0] = CRGB(255,255,0);

            it.schedule_show();

      - fastled_lambda:
          name: bounce
          update_interval: 100ms
          lambda: |-
            static int current_ring = 0;
            static int direction = 1;
            static uint8_t current_hue = 0;
            auto leds = it.leds();
            fadeToBlackBy(leds, it.size(), 100);

            current_ring = (current_ring + direction);
            if (current_ring < 0) {
                current_ring = 0;
                direction = 1;
            }
            if (current_ring >= led_rings) {
                current_ring = led_rings - 1;
                direction = -1;
            }

            for (int i = 0; i < led_ringsize; i++)
                leds[ledoffset(current_ring, i)] = CHSV(current_hue, 255, 200);
            if (current_ring >= led_rings - 1)
                leds[0] = CHSV(current_hue, 255, 255);

            if (current_ring == 0) {
                current_hue += 10;
                if (current_hue > 255)
                    current_hue = 0;
            }

            it.schedule_show();

      - fastled_lambda:
          name: clock
          update_interval: 100ms
          lambda: |-
            // clock
            auto time = id(sntp_time).now();
            uint8_t  seconds = time.second;
            uint8_t  minutes = time.minute;
            uint8_t  hours   = time.hour;
            uint8_t  seconds_tens = seconds / 10;
            uint8_t  minutes_tens = minutes / 10;
            uint8_t  hours_tens   = hours / 10;
            seconds = seconds % 10;
            minutes = minutes % 10;
            hours   = hours % 10;

            static int ticks = 0;
            static uint8_t col_start = 0;

            #define col_hours_tens     (col_start)
            #define col_hours          (col_start +  1)
            #define col_minutes_tens   (col_start +  2)
            #define col_minutes        (col_start +  3)
            #define col_seconds_tens   (col_start +  4)
            #define col_seconds        (col_start +  5)

            const unsigned int hue_hours = HUE_GREEN;
            const unsigned int hue_minutes = HUE_BLUE;
            const unsigned int hue_seconds = HUE_RED;

            // column 0 - tens of hours
            // column 1 - hours
            // column 2 - tens of minutes
            // column 3 - minutes
            // column 4 - tens of seconds
            // column 5 - seconds
            // flash top ring dim red/dim blue by seconds

            //if (++ticks > 150) {    // note update_interval above
            //  ticks = 0;
            //    if (--col_start < 0)
            //        col_start = led_ringsize;
            //}

            auto leds = it.leds();
            fadeToBlackBy(leds, it.size(), 200);

            CRGB flash = (seconds & 1) ? CRGB::Cyan : CRGB::Magenta;
            leds[0] = flash;
            // invert state for other
            flash = ((seconds & 1) == 0) ? CRGB::Cyan : CRGB::Magenta;
            leds[ledoffset(led_rings - 1, col_start + 8)] = flash;

            // const unsigned int led_spacer = 1;
            // const unsigned int led_rings = 9;
            // const unsigned int led_ringsize = 11;
            // int ledoffset(unsigned int ring, unsigned int member)

            for (int i = 0; i < led_rings; i++) {
                leds[ledoffset(i, col_hours_tens)]   = CHSV(hue_hours,   /*sat*/ 255, /*brightness*/ 00);
                leds[ledoffset(i, col_hours)]        = CHSV(hue_hours,   /*sat*/ 150, /*brightness*/ 00);
                leds[ledoffset(i, col_minutes_tens)] = CHSV(hue_minutes, /*sat*/ 255, /*brightness*/ 00);
                leds[ledoffset(i, col_minutes)]      = CHSV(hue_minutes, /*sat*/ 150, /*brightness*/ 00);
                leds[ledoffset(i, col_seconds_tens)] = CHSV(hue_seconds, /*sat*/ 255, /*brightness*/ 00);
                leds[ledoffset(i, col_seconds)]      = CHSV(hue_seconds, /*sat*/ 150, /*brightness*/ 00);
            }

            for (int i = 1; i <= seconds_tens; i++)
                leds[ledoffset(i - 1, col_seconds_tens)] = CHSV(hue_seconds, /*sat*/ 255, /*brightness*/ 250);
            for (int i = 1; i <= seconds; i++)
                leds[ledoffset(i - 1, col_seconds)]      = CHSV(hue_seconds, /*sat*/ 150, /*brightness*/ 250);
            for (int i = 1; i <= minutes_tens; i++)
                leds[ledoffset(i - 1, col_minutes_tens)] = CHSV(hue_minutes, /*sat*/ 255, /*brightness*/ 250);
            for (int i = 1; i <= minutes; i++)
                leds[ledoffset(i - 1, col_minutes)]      = CHSV(hue_minutes, /*sat*/ 150, /*brightness*/ 250);
            for (int i = 1; i <= hours_tens; i++)
                leds[ledoffset(i - 1, col_hours_tens)]   = CHSV(hue_hours,   /*sat*/ 255, /*brightness*/ 250);
            for (int i = 1; i <= hours; i++)
                leds[ledoffset(i - 1, col_hours)]        = CHSV(hue_hours,   /*sat*/ 150, /*brightness*/ 250);

            it.schedule_show();

This might give you an idea of how to add more effects with your own C++ code. You can get into all sorts of creative trouble using lambda in esphome…

1 Like

Awsome! Thank’s for the code!
I’m also trying to replicate some effects I had in old setup (BRUH light), fire effect to be specific. Is there a way to implement those?
I found some code here, is it possible to ‘‘convert’’ those?

It’s very likely those examples could be adapted to call the FastLED library from inside the esphome environment. The code you include inside the lambda is called repeatedly, similar to how the loop() function in the arduino environment is. The it variable refers to the FastLED object, I believe.

I think one problem that would need to be solved is that those examples you noted use a delay() function in their definition. I’m not sure that’s going to work inside the esphome environment, since you probably can’t block inside the lambda… For instance, the WiFi has be serviced as well as all the other stuff that’s going on. The code in the lambda is called on a periodic basis (which you get to specify), so you might need to re-factor that code into a state machine or something that’s called periodically.

I’m not an expert by any means with the FastLED library (or esphome, for that matter), so I just sort of fumbled around trying stuff. If you’ve questions about it, there’s a discord channel for esphome that could also be helpful; I had some questions answered over there when I was working on my simple project.

Thank’s, I’m gonna try my luck at discord. I’m not any good with coding, I’m only good with copying the code :grin:.
I hope someown is gonna figure it out sooner or later :wink:

That’s funny I came to this thread looking for an example of a fire/candle effect for FastLED as well… will have to see if I can find some code that can be adapted. Thanks for the examples @lmamakos

I didn’t see this posted yet but I have been printing these amazing modular cases for my esphomeyaml devices:

The creator was nice enough to include the source file so it is easy to adapt to other sensors. I am working on a new base to fit a Wemos D1 Mini.

I have the same issue: any idea how to solve this?
@OttoWinter

I don’t know why it initially happens but to solve it you need to go to your integrations section and delete one copy of the integrated entities for ESPHome you’ll find there. Then restart. They should all come back up OK after that with no more errors.

confirmed this solved the issue

Cool case. Thanks for that.

I’ve just tried to install the add-on (Home Assistant 0.91.1 / Intel CPU )

But the after adding the URL the add-on is not visible. The following error is in the system log:

    19-04-07 17:16:14 INFO (MainThread) [hassio.addons.git] Clone add-on https://github.com/ottowinter/esphome.yaml repository
19-04-07 17:16:15 ERROR (MainThread) [hassio.addons.git] Can't clone https://github.com/ottowinter/esphome.yaml repository: Cmd('git') failed due to: exit code(128)
  cmdline: git clone --depth=1 --recursive --shallow-submodules -v https://github.com/ottowinter/esphome.yaml /data/addons/git/4144ebc6
  stderr: 'Cloning into '/data/addons/git/4144ebc6'...
fatal: could not read Username for 'https://github.com': No such device or address
'.
19-04-07 17:16:15 ERROR (MainThread) [hassio.addons] Can't load from repository https://github.com/ottowinter/esphome.yaml
19-04-07 17:16:15 INFO (MainThread) [hassio.addons] Load add-ons: 57 all - 0 new - 0 remove
19-04-07 17:17:00 INFO (MainThread) [hassio.addons.git] Clone add-on https://github.com/ottowinter/esphomeyaml repository
19-04-07 17:17:03 ERROR (MainThread) [hassio.utils.json] Can't read json from /data/addons/git/7bce6681/repository.json: [Errno 2] No such file or directory: '/data/addons/git/7bce6681/repository.json'
19-04-07 17:17:03 WARNING (MainThread) [hassio.addons.data] Can't read repository information from /data/addons/git/7bce6681/repository.json

Has anyone seen this issue before ? I tried to google it but couldn’t find anything usefull.
Internet connection is working. Just updated a few other components so that is working also.

-edit-
It seems the main problem is the missing “repository.json” file.

-edit 2-

Seems like I’ve been using the wrong link (see log). Correct link : https://github.com/esphome/hassio

Does anyone know if the latest version of ESPHome works with the HC-SR04 Ultrasonic sensor? I heard that they didn’t work on v1.12.1.

I want to verify they now work on v1.12.2.

Not sure about that model but I have 2 of these:

https://www.ebay.co.uk/itm/Arduino-Ultrasonic-Ranging-Measuring-Transducer-Sensor-Waterproof-JSN-SR04T/292851585927?hash=item442f509387:g:GDIAAOSwiSVcCNFM

and they work fine with v1.12.2

I can’t quite tell if this is in 1.12.2, but there is an option to use the fix-ultrasonic branch, see https://github.com/esphome/esphome-core/pull/562 and https://github.com/esphome/issues/issues/147

I have one I have been meaning to try, but this weekend is looking busy with real life.

Yes solved in 1.12.2

Great!

Thanks for the info, guys (/gals? :wink:)

@lmamakos, thank you for the fantastic example. It seems that @OttoWinter has made some major changes to the fastled_lambda function and it is now named addressable_lambda. I am no longer able to use many of the fastled functions such as fadeToBlackBy.

By any chance have you found a way to modified your example to work with the current version (1.13.5) of ESPHome?