I would like to know how to define a constraint to set a limit for switching to 0 for a decision variable? So I have a linear variable $x(t)$ which quantifies the modulation degree of a heating device. It can be between $0$ (meaning that the device is switched off) and $1$ (meaning that the device is heating with full power). My $t$ is between $1$ and $288$ (timeslots for every $5$ minutes of $1$ day). As you can imagine it is not really good to change frequently between $0$ and a non-zero value because this would mean, that the heating device starts and stopps frequently during one day (sometime I have $5$ starts and stopps during $1$ hour) which should be avoided as it increases the wear of the device.
So I would like to set a limit to switching to 0 during one day. Is there a way how I could define a constraint for that? The rule in pseudocode is basically
if x(t-1)>0 and x(t)=0 then increase count by 1
Constraint: count <= limit
Do you have an idea how I could model that (if it is possible)? I'd appreciate every comment and would be thankful for your help.