Wireless Sensor Networks are believed to be the enabling technology for Ambient Intelligence. They hold the promise of delivering to a smart communication paradigm which enables setting up an intelligent network capable of handling applications that evolve from user requirements. Cognitive agents capable of making proactive decisions based on learning, reasoning and information sharing when interspersed in sensor networks, may help achieve end-to-end goals of the network even in the presence of multiple constraints and optimization objectives. Cognitive radio at the physical layer of such agents may enable the opportunistic use of the heterogeneous wireless environment. However, research efforts have been discrete and cognitive techniques have focused on improving specific aspects of the network or benefiting specific applications. The main contribution of this paper is providing the vision and advantage of a holistic approach to cognition in sensor networks, which can be achieved by incorporating learning and reasoning in the upper layers, and opportunistic spectrum access at the physical layer. Rather than providing an ostensive survey of cognitive architectures applicable to sensor networks, this paper provides the reader with a framework based on knowledge and cognition that can help achieve end-to-end goals of application-specific sensor networks.