A classical real-time applicative software consists of periodic tasks which have regular arrival times and strict deadlines by which they must always follow through on execution. Nonetheless, there is a possibility of faults in the software, the electrical power supply may run out and the processor may experience temporary overload. All these situations result in deadline missing for the tasks, which is non acceptable in hard real-time applications. The Deadline Mechanism has been introduced to cope with this issue through software redundancy. A task has two software versions, namely the primary which produces the best quality result and the backup which guarantees a result with a just acceptable precision. The aim of the paper is to show how to optimally implement the Deadline Mechanism in an autonomous sensor that should adopt an energy neutral mode for perpetual operation. In other terms, the sensor has to satisfy all deadlines despite fluctuations of energy availability and presence of software faults even if under a degraded operational mode.