If you have a hub generator system, they sell rear lights with controllers which detect changes in the frequency of the wheel rotation and start pulsing when you decelerate.
[1] https://www.rivbike.com/products/dyno-rack-light?srsltid=Afm...
That sounds much simpler, cheaper, and reliable than "detect changes in the frequency of the wheel rotation".
Also, it works like a car's brake lights, which drivers are accustomed to, rather than "start pulsing when you decelerate", which is when you stop pedaling (unless going downhill).