MQTT variable publish frequency

I’m working on a esp32 based water level sensor. Measuring the water level works by pumping air down a tube and measuring the pressure. I want the measuring frequency to be higher when water is being drained and lower while it is refilling, this information is available through the status of a switch. My plan is to implement communication via MQTT
My question:
From my understanding the esp32 would decide when to measure and publish the result. How can I set an automation to change the measuring frequency?

the closest I found in the documentation is scan interval, but that only seems to be relevant for polling based devices

Hi @DanielJutz, HA doesn’t need to know the update interval since you are pushing the values. Each time a value is received via MQTT the sensor entity in HA is updated.
I have devices that publish on a fixed time interval or when a value changes.