Light component with startup animation

Hey ESP Home community! I’m working on a smart status indicator for my 3D printer using a WS2812B LED strip, and I’m struggling with the operational logic.

I want to make it so that:

  • When powered but disconnected: Display a visual effect showing it’s searching for WiFi
  • When connected: Restore its previous state from Home Assistant
  • When connection drops: After a timeout, revert to the “connecting” indication

Since this is just a status light for my printer, I don’t mind if there’s a brief delay in state updates (e.g., showing “printing” for a few minutes after completion).

This is what I have done so far. I read a few other forum threads here, but I can’t figure out the order of operations and precedence for things like esphome.on_boot, wifi.on_connect, etc.

I wanted to display the addressable_scan effect.

Has anyone implemented something similar? I particularly need help understanding how to sequence these events correctly so they don’t overwrite each other. Any examples of implementing WiFi status indicators with ESP Home would be greatly appreciated!

esphome:
  ...
esp32:
  ...
# Enable logging
logger:
# Enable Home Assistant API
api:
  ...
ota:
  ...
wifi:
  ...
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ...
captive_portal:

light:
- platform: fastled_clockless
  rgb_order: GRB
  chipset: WS2812B
  pin: GPIO13
  num_leds: 36
  name: "Andon light"
  default_transition_length: 
    seconds: 1
    
  effects: 
    - pulse:
        name: "Slow Pulse"
    - addressable_scan:

  restore_mode: RESTORE_AND_ON

You can use on_boot and wifi: on_disconnect for the scan effect. Wifi: on_connect for the “normal” effect.
But you need to rethink your restore strategy. I’m pretty sure you get some input from your 3D printer to restore the status.

1 Like

Thanks!

I reread your comment about the restore logic and was confused because I thought that the state in HA could change independent of the device.

I used restore_mode because I thought that the state of entities could change when the device is offline, but it can’t and I hadn’t experienced it so far. I never had the light offline when the printer switched states, so I assumed that the state in HA worked as a “desired” state, rather than a mirror of the real state.

Anyway, this is the GitHub issue: Add `light.adjust` service call · home-assistant/architecture · Discussion #537 · GitHub

I’m surprised that this isn’t a more common scenario, given how flaky IoT devices can be. Other IoT platforms, especially the industrial ones (AWS, ThingWorx), treat entities on the platform as a desired or target state, and then leave state reconcilation logic to the device.

I.e. automations can change the desired state of the entity online multiple times while the entity is offline, and when it comes back online, the entity itself can do the logic to figure out what makes sense to restore.

Anyway, I’ll check out a few more options, but I reckon that I’ll have to create some shadow entity in config which the automations will be able to update at will, and then HA will have to restore the state of the espHome device as soon as it connects.