I am attempting to write a template to give me the time in minutes since a switch has been turned on. So far, this works in the template tool and reports the time in minutes that the switch has been turned on (repeater_7 is a simple zigbee switched outlet):
{{ relative_time(states.automation.repeater_7_auto_off.attributes.last_triggered) }}
But,
when I look at the entity created by the following template:
- platform: template
sensors:
trimmer_charge_time:
friendly_name: Trimmer Charge Time Remaining
value_template: "{{ relative_time(states.automation.repeater_7_auto_off.attributes.last_triggered) }}"
it looks good until after 1 minute and then reports a 0.
The whole point of this is to implement this automation to keep my battery from being overcharged:
- id: 'repeater_7_auto_off'
alias: 'Repeater_7 auto off'
description: 'Repeater off after 2.5 hours'
trigger:
platform: state
entity_id: switch.repeater_7
to: 'on'
action:
- delay: '02:30:00'
- service: switch.turn_off
entity_id: switch.repeater_7
The automation works but the template I’m trying to create won’t display the proper elapsed minutes.
What have I done wrong here?