button-card icon indicating copy to clipboard operation
button-card copied to clipboard

Custome_fields - display remaning time

Open cricri19top opened this issue 2 years ago • 2 comments

I want to create a button (On/OFF) for garden watering and I would like to display also the remaining time (until will be off) on the same card. I have created a timer which is triggered when button is pressed; the problem is that the remaing time is not updated (it remamins fixed 00:30:00); here is the code: custom_fields: timer: | [[[ return states['timer.timp_udare_gradina'].attributes.remaining; ]]] I have tried many variants to solved the problem, but I could not;

cricri19top avatar May 12 '23 11:05 cricri19top

Is this more a problem with the timer in core than the button-card? I set a timer going and checked the attributes in Developer Tools > States and the attribute remaining is not updating. Perhaps raise a defect in core?

A work around could be to create a template sensor which when the timer is active calculates the remaining time and use that? (you could probably do it as javascript but no idea how!)

{% if is_state('timer.water_garden', 'active') %}
{{ relative_time(now() - timedelta( seconds = as_timestamp(state_attr('timer.water_garden','finishes_at')) - as_timestamp(now())))  }}
{% endif %}

woodmj74 avatar Jun 11 '23 16:06 woodmj74

Put the timer as the main entity or the card or if you can't, then set the timer custom_field to be a custom:button-card just showing the state of the timer entity and you'll have what you want :)

RomRider avatar Jul 26 '23 00:07 RomRider