Hi everyone,
i want to display the time until my dishwasher is finished in a nice way.
For that I display a gif as “background-image” in a button card and the progress in percent over the grid system.
Now I want to display the time until it is finished. For that the dishwasher reports a Datetime when it is approximately finished which get’s nicely presented by a entites card in the form of “19 minutes remaining” or something like this.
Currently the button-card is just displaying the State of the finish time entity (I have replaced it with a temporary input_datetime so the dishwasher doesn’t need to run all the time for testing):
The Code:
type: custom:button-card
styles:
card:
- border-radius: 10%
- height: 250px
custom_fields:
progress:
- text-align: left
duration:
- text-align: left
grid:
- grid-template-areas: '"." "progress" "duration"'
- grid-template-columns: 100%
extra_styles: |
.button-card-main {
background-image: url("https://laughingsquid.com/wp-content/uploads/2021/04/Dishwasher-Interior-View-Dispensing-Soap.gif")
}
custom_fields:
progress: >
[[[ return '<span style="color: white; font-size: 40px; margin-left: 10px">'
+ states['sensor.dishwasher_program_progress'].state + '%</span>' ]]]
duration: |
[[[
return '<span style="color: white; font-size: 40px; margin-left: 10px">'
+ states['input_datetime.dt_test'].state +'</span>'
]]]
Of course I could write a JS function in the “duration” custom field to calculate the difference between now() and the finishing time, extracting hours/minutes/seconds and then compile a string which gets displayed.
My thought is: Could you reuse the Home Assistant function that does the conversion and is the “custom_fields” section of the button-card really the right location for this “big” JS function?