rianadon / timer-bar-card

A progress bar display for Home Assistant timers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Duration based on a timer

lmu007 opened this issue · comments

Hello,

My switch turns off the light automatically based on a standard timer.

The problem is that I cannot determine a timer entity as a duration value.

I get the message:

Error: Could not convert duration: timer.doeswork.here is not of format 0:10:00. If you are passing in a number, specify the units property

Here is my code

type: custom:timer-bar-card
entities:
  - switch.double_switch_2_2_2
duration:
  fixed: timer.doeswork.here
tap_action:
  action: `toggle`

Thanks in advance for your advices

Replace fixed with entity, then this should work. Let me know if it doesn't!

I changed it as recommended:

type: custom:timer-bar-card
entity: switch.double_switch_2_2_2
duration:
  entity: timer.timer_lumiere_bureau
tap_action:
  action: toggle
debug: true

and I got the message:
Error: Could not convert duration: idle is not of format 0:10:00. If you are passing in a number, specify the units property.

It make sense, it took the general state of the timer (idle/active) instead of duration attribute.

How I can provide the attribute duration of the timer ?

I made a workaround using the config template card, but should be nice if we can use the timer directly inside the timer bar card

type: custom:config-template-card
variables:
  TEMP: states['timer.timer_lumiere_bureau'].attributes.duration
entities:
  - timer.timer_lumiere_bureau
  - switch.double_switch_2_2_2
card:
  type: custom:timer-bar-card
  entity: switch.double_switch_2_2_2
  duration:
    fixed: ${ TEMP }
  tap_action:
    action: toggle
  invert: true
  bar_direction: rtl
  bar_width: 60%
  modifications:
    - elapsed: 60%
      bar_foreground: orange
    - elapsed: 80%
      bar_foreground: red
  icon: mdi:lightbulb
  mushroom: null

Ah right. I forgot that the timer's duration is inside an attribute.
Try the entity and attribute fields together:

type: custom:timer-bar-card
entity: switch.double_switch_2_2_2
duration:
  entity: timer.timer_lumiere_bureau
  attribute: duration
tap_action:
  action: toggle
debug: true

Thanks a lot, your code is working fine.
This is a perfect solution.