A controller configured to control a light source according to a plurality of illumination states subject to determine an event of a plurality of events, wherein the controller is configured to control a power converter that converts power derived from an input voltage waveform of a mains power supply into a drive signal for the light source, the controller generating one or more control signals for controlling one or more switching elements of the power converter in accordance with a current illumination state; the controller configured to operate in a power-on mode and in a power-off mode, the controller being characterised in that it comprises: - a first clock circuit configured to generate a first clock signal, wherein the first clock circuit is enabled to operate in the power-on mode; - a first state processor configured to determine a next illumination state of the plurality of illumination states, based on a detected event and on the current illumination state, wherein the first state processor is configured to operate in the power-on mode and in accordance to the first clock signal; - a second clock circuit configured to generate a second clock signal, the second clock signal having a lower frequency than the first clock signal, wherein the second clock circuit is enabled to operate at least in the power-off mode; - a control circuit configured to operate in the power-off mode and in accordance to the second clock signal, the control circuit comprising a timing circuit for determining a power-off time value; and - a memory unit; wherein in response to detection of a mains power-off event, the controller changes the operation mode from the power-on mode to the power-off mode, and disables the first state processor and the first clock circuit, and the timing circuit is enabled to start counting based on the second clock signal, and in response to detection of a mains power-on event, the control circuit stores the power-off time value in the memory unit, the controller changes the operation mode from the power-off mode to the power-on mode, thereby enabling the first state processor and the first clock circuit, and the first state processor determines the next illumination state based on the current illumination state and the power-off time value stored in the memory unit. - a first clock circuit configured to generate a first clock signal, wherein the first clock circuit is enabled to operate in the power-on mode; - a first state processor configured to determine a next illumination state of the plurality of illumination states, based on a detected event and on the current illumination state, wherein the first state processor is configured to operate in the power-on mode and in accordance to the first clock signal; - a second clock circuit configured to generate a second clock signal, the second clock signal having a lower frequency than the first clock signal, wherein the second clock circuit is enabled to operate at least in the power-off mode; - a control circuit configured to operate in the power-off mode and in accordance to the second clock signal, the control circuit comprising a timing circuit for determining a power-off time value; and - a memory unit; wherein