ESP Home + Temperature sensor + WS2812 LED strip colour change + Lambda

Tags: #<Tag:0x00007f739aef30c0>

Hi there,

Currently having a bit of an issue with compiling code / configuration file for a simple colour change LED strip.

I’m using the FastLED library + ESPHome (to which i’m new to) + a dallas I²C temperature sensor.

I can get all working independently but not together. I have some basic experience with ESPHome but as I’m new to it, I don’t understand enough to troubleshoot it myself.

What I would like help with is if someone could point out where I’m going wrong with the code I’ve written.

I’m trying to get the WS2812 strip to change to some colour as temperature changes - at this stage all I want to do is to see it change rather than change to any specific colour.

As I understand you can do so with writing lambdas (C++, I haven’t done any since the university days so its been a while!), but I keep getting an error saying that ESPHome can’t read my temperature sensor as it hasn’t been imported into ESPHome - See below

The following is my config (using an ESP-01 module):

  name: led_ring
  platform: ESP8266
  board: esp01_1m

  ssid: ""
  password: ""

    ssid: ""
    password: ""



  password: ""

  password: ""

  - pin: GPIO2
    update_interval: 4s

  - platform: dallas
    address: 0xE73C01B556F75828
    name: "Probe Temperature"
  - platform: homeassistant
    name: "Probe Temperature"
    entity_id: sensor.probe_temperature
  - platform: fastled_clockless
    id: my_light
    chipset: WS2812
    pin: GPIO0
    num_leds: 92
    rgb_order: GRB
    name: "FastLED WS2812 Light"

       - addressable_random_twinkle:
       - addressable_fireworks:
       - addressable_flicker:
       - lambda:
          name: My Custom Effect
          update_interval: 1s
          lambda: |-
            	static int state = 0;
            	auto call = id(my_light).turn_on();
            	call.set_rgb(0.8, 1.0, (return id(sensor.probe_temperature).state/45.0));

the error is:

“Lambda contains reference to entity-id-style ID ‘sensor.sensor_temperature’. The id() wrapper only works for ESPHome-internal types. For importing states from Home Assistant use ‘homeassistant’ sensor platform”

…To which I have (used the homeassistant platform)!

The sensor is in homeassistant:

To my understanding, the ESPHome automation concept bases on information that is gathered by the ESP itself. So the inputs are coming from a sensor that is connected to the controller or from an HA Entity that is imported into the ESP.
You could do the latter, but that would mean reading the sensor in the ESP, sending the data to HA, polling it from HA and then using it.
I think (without having done this yet ind lambdas) you should just define an id (not entity_id) for the sensor and then refer to it.

BTW.: you can divide your strip into virtual segments using this:
It’s a bit fiddely to set up, but at the end you have easy to adress segments.

Hey - thanks for taking the time to reply :slight_smile:

It’s a good thing to know, so yes, this is the same as my understanding, it just seems weird that I have to poll HA to get the value of the temperature probe i’m reading within the same ESP!

I will look into the id thing as I have already defined it.

id: my_light

Thanks for the extra info :slight_smile: