Arduino newbie here.
I'm thinking about building an Arduino-based light switch to control the Philips Hue light system in my living room. I have standard wall light switches that power ceiling lamps, and I basically want all Hue lamps that are scattered around the room to be on when the switch is on, and off when the switch is off, so that I don't necessarily need the app or the Hue remote to turn the room's lights on.
My idea is to install an Arduino on the ceiling instead of a normal lamp, so that its power supply is switchable through the light switch.
I would configure it as a Hue remote control, e.g. with ArduinoHue; if all works well, this would control the Hue lamps directly via ZigBee or via WiFi through the bridge - in both cases without having to use additional wiring.
Whenever it gets power, I would have it
turnOn() all lamps, and whenever its power supply is turned off, I would have it
turnOff() all lamps.
The first part seems simple to me, the second part - not so much.
So here's my question: Can I execute code in the event of the Arduino losing power, i.e. turn off my Hue lights with its last energy before shutting down? Is there maybe some hardware configuration that would allow me to detect the power off event and retain enough energy through a battery or capacitors to still run the code?
I have never worked with Arduino before, but I do have some colleagues that can help me out when there's trouble.