UPS Battery backup remaining time

I have Sonoff POW with Tasmota firmware and works fine with HA. I thought of implementing a sensor to show the remaining battery backup whenever the power failure happens. The below is the config of the sensor:

-platform:template
sensors:
battery_backup_time:
friendly_name : BatteryBackupTime
unit_of_measurement : ‘Hours’
value_template : >
{% if is_state(‘sensor.power_source’,‘Mains’) %}
~
{% else %}
{{ ( 150 * 12 * 1 * 0.8 / states(‘sensor.power’)| float ) - ( as_timestamp(states.timer.ups_on.attributes.duration) / 3600 |float )| round(2) }}
{% endif %}

Whenever my WiFi extender connected to direct line (without UPS backup) goes off due to power cut, the sensor battery backup time will be shown on the front end. The timer component will be triggered whenever the device_tracker of the extender is off, so that it will subtract the time from the remaining backup.

The problem is the timer is not working, even tried to trigger from the front end. Any help will be appreciated.