[Example] Timer-cards with round progressbar. #937
Replies: 10 comments 27 replies
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
-
For timers in sub-buttonThis is for sub-button 1, place this code in the custom-style part. Javascript#Place all the DOM changing stuff on the bottom
${(() => {
card.timerEntity = hass.states['timer.help_house_testtimer02'];
function UpdateState(){
try {
let now = new Date();
let endTime = new Date(card.timerEntity.attributes.finishes_at);
let runningTime = Math.round((endTime - now)/1000);
let hours = Math.floor(runningTime / 3600);
let minutes = Math.floor((runningTime - (hours * 3600)) / 60);
let remainingSeconds = runningTime % 60;
card.timerResult =
(hours > 0 ? (hours + ":") : "") +
("0" + minutes).slice(-2) + ":" +
("0" + remainingSeconds).slice(-2);
card.querySelector('.bubble-sub-button-1 .bubble-sub-button-name-container').innerText = card.timerResult;
} catch (error) {
card.timerResult = card.timerEntity.attributes.duration;
card.querySelector('.bubble-sub-button-1 .bubble-sub-button-name-container').innerText = card.timerResult;
}
};
if (card.timer == null && card.timerEntity.state === 'active') {
card.timer = setInterval(()=>{UpdateState()}, 500);
}else if (card.timerEntity.state != 'active'){
clearInterval(card.timer);
card.timer = null;
if (card.timerEntity.state !='paused') {
card.querySelector('.bubble-sub-button-1 .bubble-sub-button-name-container').innerText = card.timerEntity.attributes.duration;
card.timerResult = card.timerEntity.attributes.duration;
} else if(card.timerEntity.state==='paused') {
card.querySelector('.bubble-sub-button-1 .bubble-sub-button-name-container').innerText = card.timerEntity.attributes.remaining;
card.timerResult = card.timerEntity.attributes.remaining;
}
}else{
card.querySelector('.bubble-sub-button-1 .bubble-sub-button-name-container').innerText = card.timerResult ? card.timerResult : "error" ;
}
}
)()} |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
-
Example for progressbar on sub-buttonyamltype: custom:bubble-card
card_type: button
button_type: state
entity: sensor.resting_heart_rate
name: Charge 5
sub_button:
- entity: sensor.tracker_steps
state_background: false
- entity: sensor.distance
state_background: false
icon: mdi:map-marker-path
- entity: sensor.calories
state_background: false
- entity: sensor.sleep_minutes_asleep
state_background: false
icon: mdi:bed-clock
- entity: sensor.sleep_efficiency
state_background: false
- entity: sensor.charge_5_battery_level
state_background: false
card_layout: large
styles: |-
:host{
--color-ok-icon: green ;
--color-warning-icon: orange ;
--color-alert-icon: red ;
--circle-color1: #36A1D3;
--circle-color2: #36A1D3;
--circle-color3: #36A1D3;
--circle-color4: ${hass.states['sensor.sleep_minutes_asleep'].state/5.05 > 80 ? 'var(--color-ok-icon)'
: hass.states['sensor.sleep_minutes_asleep'].state/5.05 > 65 ? 'var(--color-warning-icon)'
: 'var(--color-alert-icon)'} ;
--circle-color5: ${hass.states['sensor.sleep_efficiency'].state > 80 ? 'var(--color-ok-icon)'
: hass.states['sensor.sleep_efficiency'].state > 65 ? 'var(--color-warning-icon)'
: 'var(--color-alert-icon)'} ;
--circle-color6: ${hass.states['sensor.charge_5_battery_level'].state > 50 ? 'var(--color-ok-icon)'
: hass.states['sensor.charge_5_battery_level'].state > 20 ? 'var(--color-warning-icon)'
: 'var(--color-alert-icon)'} ;
--percentage1: ${hass.states['sensor.tracker_steps'].state / 100}%;
--percentage2: ${hass.states['sensor.distance'].state * 12.5}%;
--percentage3: ${hass.states['sensor.calories'].state / 29}%;
--percentage4: ${hass.states['sensor.sleep_minutes_asleep'].state/5.05}%;
--percentage5: ${hass.states['sensor.sleep_efficiency'].state}%;
--percentage6: ${hass.states['sensor.charge_5_battery_level'].state}%;
--bubble-sub-button-border-radius: 50%;
}
*{
.bubble-sub-button-1{
background: radial-gradient(
var(--card-background-color) 60%,
transparent 0%
), conic-gradient(
var(--circle-color1) var(--percentage1) 0%,
var(--card-background-color) 0% 100%
) !important;
}
.bubble-sub-button-1:after{
content: "" !important;
height: 100% !important;
width: 100% !important;
position: absolute !important;
border-radius: 50% !important;
background: (var(--bubble-button-icon-background-color), 0.1) !important;
}
}
*{
.bubble-sub-button-2{
background: radial-gradient(
var(--card-background-color) 60%,
transparent 0%
), conic-gradient(
var(--circle-color2) var(--percentage2) 0%,
var(--card-background-color) 0% 100%
) !important;
}
.bubble-sub-button-2:after{
content: "" !important;
height: 100% !important;
width: 100% !important;
position: absolute !important;
border-radius: 50% !important;
background: (var(--bubble-button-icon-background-color), 0.1) !important;
}
}
*{
.bubble-sub-button-3{
background: radial-gradient(
var(--card-background-color) 60%,
transparent 0%
), conic-gradient(
var(--circle-color3) var(--percentage3) 0%,
var(--card-background-color) 0% 100%
) !important;
}
.bubble-sub-button-3:after{
content: "" !important;
height: 100% !important;
width: 100% !important;
position: absolute !important;
border-radius: 50% !important;
background: (var(--bubble-button-icon-background-color), 0.1) !important;
}
}
*{
.bubble-sub-button-4{
background: radial-gradient(
var(--card-background-color) 60%,
transparent 0%
), conic-gradient(
var(--circle-color4) var(--percentage4) 0%,
var(--card-background-color) 0% 100%
) !important;
}
.bubble-sub-button-4:after{
content: "" !important;
height: 100% !important;
width: 100% !important;
position: absolute !important;
border-radius: 50% !important;
background: (var(--bubble-button-icon-background-color), 0.1) !important;
}
.bubble-sub-button-4 ha-icon{
color: var(--circle-color4);
}
}
*{
.bubble-sub-button-5{
background: radial-gradient(
var(--card-background-color) 60%,
transparent 0%
), conic-gradient(
var(--circle-color5) var(--percentage5) 0%,
var(--card-background-color) 0% 100%
) !important;
}
.bubble-sub-button-5:after{
content: "" !important;
height: 100% !important;
width: 100% !important;
position: absolute !important;
border-radius: 50% !important;
background: (var(--bubble-button-icon-background-color), 0.1) !important;
}
.bubble-sub-button-5 ha-icon{
color: var(--circle-color5);
}
}
*{
.bubble-sub-button-6{
background: radial-gradient(
var(--card-background-color) 60%,
transparent 0%
), conic-gradient(
var(--circle-color6) var(--percentage6) 0%,
var(--card-background-color) 0% 100%
) !important;
}
.bubble-sub-button-6:after{
content: "" !important;
height: 100% !important;
width: 100% !important;
position: absolute !important;
border-radius: 50% !important;
background: (var(--bubble-button-icon-background-color), 0.1) !important;
}
.bubble-sub-button-6 ha-icon{
color: var(--circle-color6);
}
} |
Beta Was this translation helpful? Give feedback.
-
Round progress bar for batteries with a picture entityyamltype: custom:bubble-card
card_type: button
button_type: state
entity: person.guest
show_attribute: false
attribute: user_id
show_state: true
sub_button:
- show_last_changed: false
show_state: true
show_background: false
state_background: true
icon: ""
name: Phone
show_name: false
entity: sensor.tablet_battery_level_2
show_attribute: false
show_icon: true
- entity: sensor.oude_tablet_battery_level
icon: ""
state_background: false
show_background: false
show_state: true
name: Watch
styles: >+
:host{
--circle-color: ${hass.states['sensor.tablet_battery_state_2'].state ==='charging' ? 'green' : 'red'};
--percentage: ${hass.states['sensor.tablet_battery_level_2'].state}%;
--degrees: ${hass.states['sensor.tablet_battery_level_2'].state *3.6}deg;
}
.bubble-button-background{
background-color: ${{'home': '#8AD926FF', 'away': '#1982C4FF'}[state] ?? '#ff0000AA' };
}
.bubble-sub-button-1 {
color: ${hass.states['sensor.tablet_battery_state_2'].state === 'charging' ? 'orange' : '' } !important;
}
.bubble-sub-button-2 {
color: ${hass.states['sensor.oude_tablet_battery_state'].state === 'charging' ? 'orange' : '' } !important;
}
.bubble-entity-picture{
height: calc(100% - 6px);
width: calc(100% - 6px);
overflow: hidden;
border-radius: inherit;
align-self: center;
justify-self: center;
}
.bubble-icon-container{
background: conic-gradient(var(--circle-color) var(--percentage) 0%, transparent 0% 100%);
}
.bubble-icon-container:before{
content: "";
width: 100%;
height: 100%;
background: conic-gradient(white 3% 0%, transparent 0% 100%);
animation: charging 4s linear ${hass.states['sensor.tablet_battery_state_2'].state ==='charging' ? '' : 'reverse'} infinite;
}
@keyframes charging {
100% { transform: rotate(var(--degrees)); }
}
#place all DOM changing stuff on the bottom
${subButtonIcon[0].setAttribute("icon",
hass.states['sensor.tablet_battery_state_2'].state === 'discharging' ?
'mdi:phone' : 'mdi:cellphone-charging')}
${subButtonIcon[1].setAttribute("icon",
hass.states['sensor.oude_tablet_battery_state'].state === 'discharging' ?
'mdi:watch' : 'mdi:watch-vibrate')}
force_icon: false
show_name: true
card_layout: large-2-rows |
Beta Was this translation helpful? Give feedback.
-
Cross-browser solution for safari and ios devices Replace the lines:
with:
In my situation I only needed to replace the "const maxtime" line. That was enough to get it to work. |
Beta Was this translation helpful? Give feedback.
-
Hi, Amazing what you have done here. I wanted to use it for my irrigation schedule, but I failed miserably. I hope you can help me out here!
|
Beta Was this translation helpful? Give feedback.
-
YAML
Only the style element
Extra Features:
Tip
Note
Edits
Beta Was this translation helpful? Give feedback.
All reactions