Need Help with Home Assistant Automation: Smart Button, Wall Plug, and Yeelight Integration

Hey Home Assistant community!

I’m currently working on an automation scenario using the UI and could use some help. Here’s my setup:

  • Sengled Wall Plug integrated through Z2M
  • Xiaomi Smart Button also integrated through Z2M
  • Smart Bulb connected through Yeelight integration

Here’s what I’m aiming for:

Single Press on Smart Button:

  1. Wall Plug should toggle its state. If it’s OFF, it should turn ON, and vice-versa.
  2. Smart Bulb should flash yellow light only when the wall plug is turned on and then go back to its previous state. This should happen only when the smart plug is off.
  3. When the smart plug is on and I press the smart button to toggle, the wall plug should toggle to off.

Long Press on Smart Button:
4. I want to change an input boolean to ON with the condition that the smart plug is already ON. If not, it needs to turn the smart plug ON and change the input boolean to ON.
5. When the smart plug is OFF, the input boolean should turn OFF (for #4 to happen when the button is pressed).

I’ve shared my current configuration here.

What I’m struggling with:

  • How to achieve #2 (flashing the smart bulb when the wall plug is turned on and then reverting to its previous state).
  • How to accomplish #5 (turning off the input boolean when the smart plug is OFF).

Any insights or suggestions would be greatly appreciated! If you have experience with similar setups or can help me refine my configuration, I’d be very thankful.