Sensors powered by energy harvesting devices (EHD) are increasingly being deployed in practice, due to the demonstrated advantage of long-term, autonomous operation, without the need for battery replacement. This paper is concerned with the following fundamental problem: how should the harvested energy be managed to ensure optimal performance, if the statistical properties of the ambient energy supply are known? To formulate the problem mathematically, we consider an EHD-powered sensor which senses data of varying importance and model the availability of ambient energy by a two-state Markov chain ('GOOD' and 'BAD'). Assuming that data transmission incurs an energy cost, our objective is to identify low-complexity transmission policies, which achieve good performance in terms of average long-term importance of the transmitted data. We derive the performance of a Balanced Policy (BP), which adapts the transmission probability to the ambient energy supply, so as to balance energy harvesting and consumption, and demonstrate that it performs within 5% of the globally optimal policy. Moreover, a BP which avoids energy overflow by always transmitting when the sensor battery is fully charged is shown to perform within 4% of the optimum. Finally, we identify a key performance parameter of the system, the relative battery capacity, defined as the ratio of the battery capacity to the expected duration of the BAD harvesting period.