Using sensor as label value

i’m using a custom:button-card to control my garden hose. i’ve managed to get the formatting right to change the color based on the state of this hose. i’m trying to get the label to display the remaining time and no matter what i do, i can’t get it to work. the hose integration provides me the start time, and i’m using a template sensor to calculate the remaining time, but i can’t get the remaining time to show as the label. it either gives me an error when i try to load the overview or the button disappears entirely. i’m stuck on how to fix it. any help would be super appreciated, i’ve spent literal hours on this

template:

- platform: template
    sensors: 
      garden_irrigation_run_time:
        friendly_name: Garden Irrigation Run Time
        value_template: >
          {{ ( now() - state_attr('switch.garden_irrigation_zone','started_watering_station_at') ) }}

button:

type: custom:button-card
layout: name_state
show_label: true
tap_action:
action: call-service
   service: input_boolean.toggle
      service_data:
         entity_id: input_boolean.garden_irrigation
name: Garden Irrigation
icon: mdi:watering-can
entity: switch.garden_irrigation_zone
label: >
   [[[return state(sensor.garden_irrigation_run_time) ]]]
state:
  - value: "on"
    styles:
      card:
        - background-color: "#2389da"
          icon:
            - color: "rgb(221,221,221)"
  - value: "off"
    styles:
      card:
        - background-color: "#1D1D1D"

Wrong template.
Ref to button-card docs.

Wrong indentation.

Wrong indentation.

Wrong indentation.

Also - do not want to seem rude, but - please start sentences with capital letters.

What an unhelpful response.

I’m curious if anyone found the answer to this?

Is it possible to set a sensor state as a label?

I’ve seen suggestions that using config-template-card could achieve this.

Only issue I’ve seen reported is that whenever your card dynamicly updates it makes the whole card refresh rather than just the sensor value changing. So if your card has something that is regularly changing in it this isn’t really a solution.

Provide your own a helpful one)

It’s been 3 years and you still prove my point.

My reply contained a solution, but it wasn’t perfect for all situations.

Your reply contains nothing , just a link to CTC card which is absolutely not needed for a custom: button-card. Suggest you to be more accurate when saying/writing something, otherwise it could seem rather silly , especially when repeated.

You are wasting everyones time. You are contributing nothing but negative opinions. I’ve reported your reply.

No, your solution is only pointing others in the wrong direction.

I’d consider attacking a post from 2022, then asking a bunch of questions without explaining anything you’ve done so far, as wasting others time!

There are multiple examples that are easy to find in this Forum. To close out this thread and stop this nonsense, here is an example.

label: |
  [[[ return states['input_number.num2'].state]]]

I’d suggest reevaluating this comment and taking a more diplomatic approach.

Almost all the core contributors on this forum volunteer their knowledge and time.

2 Likes

I agree, lets move on.

It could be a potential solution for some people and it’s not far off the desired outcome.

A label that can show a sensor state or dynamically change based on the entities value.

label: "${vars[0] === 'on' ? 'Light On' : 'Light Off'}"

label: "${states['climate.ecobee'].attributes.current_temperature > 22 ? 'Cozy' : 'Too Hot/Cold'}"

It refreshes the whole card every time the entity updates which is not ideal for my situation because my entity updates every second.

Unfortunately your example does not work for me but I do appreciate a helpful response. Maybe the card I’m using doesn’t support this functionality.

Thank you for the response.

The card being talked about here is custom:button card, your template is from template config card. They both use different template systems.

1 Like

If you expect a ready code instead of getting PRECISE descriptions of errors for PRECISE places of a code - may be it is not a good platform/forum/planet for you.