So this is where I see for atmega 168/328, Tone lib is modding Timer2:
So that's why it's important to explicitly set every Timer2 register.
Reviewing AVR130 app note, I think I was incorrect about being able to sleep and externally clock T1 (to count pulses), as T0/T1 seem to be synchronous, meaning they require the system (i/o) clock to be running to latch in the edges of external source, and only IDLE power save mode supports running the clk_io. This mode will use way more current, e.g. w/ internal rc osc at 8MHz at 3.3v about 700uA.
Seems that only Timer2 can allow an "asynchronous" external clocking event (pulse counting) with cpu clocks off (in very low power modes).
Just blabbering, yet another aproach could be to, instead of bothering with RTC crystal on Timer2:
- use watchdog timer as a wakeup (interrupt only) source, for either an approximately 4 or 8 second interval (5 mins = 300 secs, 300 / 4 = 75 wakeups)
- use Timer2 as external event counter to count the pulses (without interrupt/wakeup?)
regarding the mysensors lib, I'm not an expert, but reviewing the code, seems like you covered it:
mysensors sleep overloads call _sleep in MySensorsCore.cpp
which call transportDisable() like you do then call hwSleep() variants in MyHwAVR.cpp (depending upon how you call sleep, e.g. with pin interrupt setups or not), which eventually call hwPowerDown()
which seems to do pretty much what you are doing (maybe a few other things, etc..) to call sleep. ref: https://www.microchip.com/webdoc/AVRLibcReferenceManual/group__avr__sleep.html
So I dont really see any additional state machine stuff happening w.r.t. MySensors itself.