Hello there!
In 2018 there was a discussion about it:
https://forum.duet3d.com/topic/7133/filament-remaining-sensor
Here is an example from that topic:
https://plugins.octoprint.org/plugins/filamentmanager/
The goal is to have a rough estimate by counting the used filament.