DIY Smart Diffuser: ESPHome Integration with D1 Mini

I recently received a traditional essential oil diffuser as a gift, and while it was a fun gadget, I couldn’t resist the urge to make it smarter. After some research, I decided to integrate it with an ESPHome setup using a Wemos D1 Mini. Here’s what I’ve done so far and where I need a bit of help!

Setup and Challenges
I wired the D1 Mini to mimic button presses for turning the diffuser on and off. The circuit includes an optocoupler to safely interface with the diffuser’s control board. The current setup reads the device’s state via an ADC pin, which works reliably. However, I’m struggling with controlling the LED light, which is driven by a rotary encoder. I need to figure out how to replicate the encoder’s output using the D1 Mini.

ESPHome Configuration
Here’s a snippet of my current ESPHome configuration:
yaml
switch:

  • platform: gpio
    pin: GPIO4
    name: “ON/OFF”
    icon: ‘mdi:light-switch’
    internal: True
    id: relay

  • platform: template
    name: “ON/OFF Switch”
    icon: ‘mdi:scent’
    lambda: |-
    if (id(binary_switch).state) {
    return true;
    } else {
    return false;
    }
    id: on_cycle
    turn_on_action:

    • switch.turn_on: relay
      turn_off_action:
    • if:
      condition: binary_sensor.is_on: binary_switch
      then:
      - switch.turn_on: relay
      - delay: 500ms
      - switch.turn_on: relay
      - delay: 500ms
      - switch.turn_on: relay
      - delay: 500ms
      - switch.turn_on: relay

Next Steps
I plan to measure the remaining pins on the rotary encoder to understand how they respond to rotation. Any advice on controlling the LED would be greatly appreciated!

This project has been a great learning experience, and I’m excited to see it come together. If anyone has insights or tips, please share! :busts_in_silhouette::sparkles: