sure, here you go.
this is for one motion sensor (kitchen in this case). for a second motion sensor light button, change ‘- light_motion_kitchen’ to something else. and change ‘base_motion_kitchen’ accordingly.
- type: custom:button-card
entity: light.kitchen_main
name: Kitchen Top
template:
- light_motion_kitchen
- icon_hue
button_card_template.yaml (additional code to original)
light_motion_kitchen:
template:
- base_motion_kitchen
- motion
- hold_action_light
motion:
custom_fields:
motion: >
[[[
return `<ha-icon
icon="mdi:motion-sensor"
style="width: 20px; height: 20px;">
</ha-icon>`
]]]
base_motion_kitchen:
variables:
motion_timeout: >
[[[ return states['input_number.motion_timeout'].state; ]]]
motion_state: >
[[[ return states['binary_sensor.kitchen_motion_sensor'].state; ]]]
template:
- base_motion
styles:
custom_fields:
motion:
- color: >
[[[
if (states['binary_sensor.kitchen_motion_sensor'].state === 'on')
return 'var(--primary-color)';
return "grey";
]]]
base_motion:
variables:
state: >
[[[ return entity === undefined || entity.state; ]]]
timeout: >
[[[ return entity === undefined || Date.now() - Date.parse(entity.last_changed); ]]]
light_color: >
[[[ return entity === undefined || entity.state === 'unavailable' ? 'var(--state-icon-color)' : 'var(--button-card-light-color-no-temperature)'; ]]]
aspect_ratio: 1/1
show_state: true
show_icon: false
state_display: >
[[[ if (variables.state === true) return 'Okänd'; ]]]
tap_action:
ui_sound_tablet: |
[[[
const screensaver = states['switch.galaxy_tab_a_screensaver'] === undefined ||
states['switch.galaxy_tab_a_screensaver'].state;
if (variables.state === 'off' && screensaver === 'off') {
hass.callService('media_player', 'play_media', {
entity_id: 'media_player.galaxy_tab_a',
media_content_id: '/local/sound/on.m4a',
media_content_type: 'music'
});
}
if (variables.state === 'on' && screensaver === 'off') {
hass.callService('media_player', 'play_media', {
entity_id: 'media_player.galaxy_tab_a',
media_content_id: '/local/sound/off.m4a',
media_content_type: 'music'
});
}
]]]
animation_card: |
[[[
const animation_speed_ms = 900;
const animation = `card_bounce ${animation_speed_ms}ms cubic-bezier(0.22, 1, 0.36, 1)`;
this.shadowRoot.getElementById("card").style.animation = animation;
window.setTimeout(() => {
this.shadowRoot.getElementById("card").style.animation = "none";
}, animation_speed_ms)
]]]
action: toggle
haptic: medium
styles:
grid:
- grid-template-areas: |
"icon motion"
"n n"
"s s"
- grid-template-columns: repeat(2, 1fr)
- grid-template-rows: auto repeat(2, min-content)
- gap: 2%
- align-items: start
name:
- justify-self: start
- line-height: 115%
state:
- justify-self: start
- line-height: 115%
card:
- font-family: Sf Display
- border-radius: var(--custom-button-card-border-radius)
- -webkit-tap-highlight-color: rgba(0,0,0,0)
- transition: none
- padding: 10%
- --mdc-ripple-color: >
[[[
return (variables.state === 'on' || variables.state === 'home') ?
'rgb(0, 0, 0)' :
'rgba(255, 255, 255, 0.3)';
]]]
- color: >
[[[
return (variables.state === 'on' || variables.state === 'home') ?
'rgba(0, 0, 0, 0.6)' :
'rgba(255, 255, 255, 0.3)';
]]]
- background-color: >
[[[
return (variables.state === 'on' || variables.state === 'home') ?
'rgba(255, 255, 255, 0.8)' :
'rgba(115, 115, 115, 0.2)';
]]]
extra_styles: |
#name, #state {
font-size: 1.34vw;
letter-spacing: 0.05vw;
}
/* portrait */
@media screen and (max-width: 1200px) {
#name, #state {
font-size: 2vw;
letter-spacing: 0.05vw;
}
}
/* phone */
@media screen and (max-width: 800px) {
#name, #state {
font-size: 3.1vw;
letter-spacing: 0.12vw;
}
}
@keyframes card_bounce {
0% {
transform: scale(1);
}
15% {
transform: scale(0.9);
}
25% {
transform: scale(1);
}
30% {
transform: scale(0.98);
}
100% {
transform: scale(1);
}
}