According to Charles Duhigg new habits are created by putting together a CUE, a ROUTINE, and a REWARD. James Clear agrees, and crucially adds a CRAVING which he believes drives the loop, e.g., Cue > Craving > Response > Reward. I think the CUE is often visual but in reality, can be any of the five senses. CRAVING is how you interpret the cue, and it can change depending on your current state. The RESPONSE is the action you take, and the REWARD is always some kind of consequence.
In cognitive psychology the internal states of moods, emotions, beliefs, and identity all effect your behaviour. How you interpret the “cues” should be added into the equation, and your interpretation definitely changes depending on your current state.