Mostly they run on the very quiet setting (or not at all), but they’ll automatically spin up if someone cooks, farts, opens a window or hits a vape pen.
Did something similar recently for fun and cost was ~20e for co2 sensor, attached to a raspberry pi pico or esp32 and it ends up being 27-30e. (add some more sensors like co or gas for 10e each, a mini display for 5e, hook up to home assistant or telegram and ends up being more useful)
To be fair, QA on these things tends to be valuable, so perhaps cost might be justified.
Cost likely can go down if you know what to buy, I didn't and just bought what a reputable seller had.
I guess it will be on all the time for me.
On the other hand, instead of DIY you could just buy air purifier units with integrated air quality sensors. A friend of mine uses these, they appear to work very well https://www.philips.co.uk/c-p/AC2936_33/2000i-series-air-pur...
I would not recommend it purely because they decided to use an extremely poor touch interface for control which quiet often doesn't register when I try to manually adjust something like shutting the unit down temporarily or resetting an error code
Buying a purifier that can fit standard sized “box” filters will save you $$ in the long run.
Having one very powerful air purifier hidden away in another room is not as good as having a bunch of smaller ones spread around.
Overall, yes, a cheap box filter (placed specifically in the bedroom, if limited to one room) is often the most effective.