cool thanks for the info! i got it working, exept now the custom:swipe-card is prohibiting me from using the slider.
So it works on normal buttons, but when i use a custom: swipe-card to allow for multiple tabs is does not work. Also the lights dont work then.
Do you have any suggestions for that?
EDIT: Strange it does work on the tablet with touch just not on the PC with the mouse
#################################################
# #
# leefkeuken #
# #
#################################################
- type: grid
title: Leefkeuken ↔
view_layout:
grid-area: leefkeuken
columns: 1
cards:
- type: custom:swipe-card
parameters:
speed: 550
spaceBetween: 40
threshold: 5
start_card: 1
cards:
- type: grid
columns: 2
cards:
- type: custom:button-card
entity: light.keuken
name: Keuken Lampen
double_tap_action:
!include popup/leefkeuken_lampen.yaml
template:
- light
- icon_spot
- type: custom:button-card
entity: light.eettafel
name: Eettafel
template:
- light
- icon_lamp
- type: custom:button-card
entity: switch.oven_power
name: Oven
double_tap_action:
!include popup/leefkeuken_oven.yaml
template:
- base
- icon_stove
# - circle
- type: custom:button-card
entity: media_player.leefkeuken
name: Leefkeuken
double_tap_action:
!include popup/leefkeuken_monitorer.yaml
template:
- mediaplayer
- icon_monitors
- type: grid
# view_layout:
# grid-area: woonkamer
columns: 2
cards:
- type: custom:button-card
entity: climate.leefkeuken
name: Verwarming
tap_action:
!include popup/woonkamer_verwarming.yaml
template:
- base
- icon_climate
- circle
variables:
circle_input: >
[[[
if (entity) {
return entity.state === 'cool'
? Math.round(entity.attributes.temperature).toString()
: Math.round(entity.attributes.current_temperature).toString();
}
]]]
circle_input_unit: '°C'
mediaplayer.yaml (template)
mediaplayer:
template:
- base
- circle
- loader
double_tap_action:
action: fire-dom-event
browser_mod:
service: browser_mod.popup
data:
title: >
[[[
return !entity || entity.attributes.friendly_name;
]]]
card_mod:
style:
#popup header
.:
content:
type: entities
card_mod:
style: |
#states {
padding-top: 0.5em;
}
entities: >
[[[
if (entity) {
let lights = [],
id = Boolean(entity.attributes.entity_id)
? [entity.entity_id].concat(entity.attributes.entity_id)
: [entity.entity_id];
for (let i = 0; i < id.length; i++) {
lights.push({
"type": "custom:mushroom-light-card",
"entity": id[i],
"fill_container": false,
"primary_info": "name",
"secondary_info": "state",
"icon_type": "icon",
"show_brightness_control": true,
"use_light_color": true,
"show_color_temp_control": true,
"show_color_control": true,
"collapsible_controls": true
});
}
return lights;
}
]]]
variables:
circle_input: >
[[[
if (entity) {
// if light group get brightness from child to remove bounce
let child = entity.attributes.entity_id,
volume = child && states[child[0]].attributes.volume_level
? Math.round(states[child[0]].attributes.volume_level * 100)
: Math.round(entity.attributes.volume_level * 100);
return volume === 0 && entity.state !== 'off'
? 1
: volume
}
]]]
circle_input_unit: '%'
mediaplayer section in circle.yaml
/* * * * * * * * * * * * * * * * * *
* *
* MEDIAPLAYER *
* *
* * * * * * * * * * * * * * * * * */
if (domain === 'media_player' && state) {
// wait 0ms for shadow dom
setTimeout(() => {
// then get elements
let elt = this.shadowRoot,
circle_slider = elt.getElementById('circle_slider'),
circle_value = elt.getElementById('circle_value'),
circle_stroke = elt.getElementById('circle_stroke');
// approximate position of thumb relative to circle
circle_slider.style.top = `${(circle_slider.value - 50) / 1.66 - 1}%`;
// debug position
let debug = true;
if (debug) circle_slider.style.opacity = 0.3;
// pass each event to handler
['click', 'input', 'mousedown', 'mouseup', 'touchstart', 'touchend'].forEach((event) => {
circle_slider.addEventListener(event, handler, { passive: true })
});
function handler(event) {
// "this" refers to slider
if (event.target === this) {
// bypass button-card tap_action
event.stopPropagation();
// update circle_value
circle_value.innerHTML = `${this.value}${tspan}${unit}</tspan>`;
// update stroke
circle_stroke.style.strokeDashoffset = c - this.value / 1 * c;
circle_stroke.style.strokeWidth = 'var(--c-stroke-width-dragging)';
// set cursor while dragging
if (event.type === 'mousedown' || event.type === 'input') {
this.style.cursor = 'grabbing';
} else {
this.style.cursor = 'grab';
}
// reset stroke width if value doesn't change
if (input == this.value && (event.type === 'click' || event.type === 'touchend'))
circle_stroke.style.strokeWidth = 'var(--c-stroke-width)';
// on release
if (event.type === 'mouseup' || event.type === 'touchend') {
// display loader if brightness is 0
if (circle_slider.value == 0 && elt.getElementById('loader')) {
elt.getElementById('loader').style.display = 'initial';
elt.getElementById('circle').style.display = 'none';
}
// set volume
hass.callService('media_player', 'volume_set', {
entity_id: entity.entity_id,
volume_level: this.value / 100
});
}
}
}
}, 0);
return circle(state, input, unit);
}
So the red arrow one is working, the blue arrow ones are showing a hand in the cursor but do not respond to a vertical swipe.