Design the bad-day version explicitly and give it a name, so it's a thing you do rather than a failure you settle for.
Mine is two tiers: full version and minimum version, decided in the first thirty seconds after getting up based on how I feel, not renegotiated later. Your minimum might be three minutes of stretching and one written sentence. The point is that the minimum still counts as having done it, which preserves the identity and the cue, and that's what carries a habit through a bad month.
The thing that ruins this is treating the minimum as cheating. It isn't. On bad-sleep days the minimum is the whole win.
Separately, three or four bad nights a week over a long stretch is worth mentioning to a doctor at some point. Not because it's necessarily anything, but because people put up with it for years and it's more often fixable than not.