custom-cards / circle-sensor-card

A custom component for displaying sensor values as cards or elements
Apache License 2.0
174 stars 23 forks source link

[Feature Request] Template value for max #25

Open clandestine-avocado opened 3 years ago

clandestine-avocado commented 3 years ago

This card is great, and would be perfect for countdown timers like next_timer for Alexa if we could pass a templated state value into the max field.

For example, if I set a 5 minute timer, I could set an input_text or input_number with the timers initial (and static) value of 5. Then, as the timer value decreases for the whatever entity is set, the card would start as a full circle, and dynamically decease relative to the templated max value. Of course I have no idea how to build these great cards, just an idea - no idea how difficult this would be to implement!

salvq commented 2 years ago

Just as workaround, you can create template sensor which will use whatever data as input.

Create new template sensor with attribute values which can be used to define current / max data, example below are input data from entity sensor.lg_drayer_remain_time and sensor.lg_drayer_initial_time

template:
  - sensor:
      - name: "Custom Drayer Time"
        state: >
          {{ states('sensor.lg_drayer') }}
        attributes:
          remaining_time: >
            {% set mins_hours = states('sensor.lg_drayer_remain_time').split(':') %}
            {% set mins = mins_hours[0] | int * 60 + mins_hours[1] | int %}
            {{ mins }} 
          initial_time: >
            {% set mins_hours = states('sensor.lg_drayer_initial_time').split(':') %}
            {% set mins = mins_hours[0] | int * 60 + mins_hours[1] | int %}
            {{ mins }}

and then assign to

  - entity: sensor.custom_drayer_time
    type: custom:circle-sensor-card
    attribute: remaining_time
    attribute_max: initial_time