Hi,
The problem is most likely that the state of the sensor changes when HA is restarted.
I use ZHA and don’t have this problem. I suspect it may have something to do with z2m.
What you can try is to restart HA and then look at the ‘states’ table in sql, to see which state changes take place when restarting.
Also look at the settings in z2m to see if there is some setting to retain states.
Or you could be creative and set a boolean when restarting HA, that prevents updates to the counter, and turn the boolean off again when HA is restarted.
Oh and by the way, in the start of the thread there were others with this problem, perhaps you can find a solution there