Skip to content

Instantly share code, notes, and snippets.

@D34DC3N73R
Last active January 29, 2024 17:10
Show Gist options
  • Save D34DC3N73R/0eda70cf6cbcbb74f3fac0b11eca1fe4 to your computer and use it in GitHub Desktop.
Save D34DC3N73R/0eda70cf6cbcbb74f3fac0b11eca1fe4 to your computer and use it in GitHub Desktop.
Add motion sensors to light button cards - Add motion.yaml to the button_card_templates directory. Add variables: motion: and define the motion sensor entity_id in your light button card. If you want the card to update with the motion sensor and light entity state (rather than only the light entity), you'll also need to add the motion entity to …
motion:
custom_fields:
motion: |
[[[
const motionSensor = states[this._config?.triggers_update];
return motionSensor && motionSensor.state == 'on'
? '<ha-icon icon="mdi:motion-sensor" style="width:100%;display:flex;color:var(--state-icon-active-color);"></ha-icon>'
: '<ha-icon icon="mdi:motion-sensor-off" style="width:100%;display:flex;color:var(--state-icon-color);"></ha-icon>';
]]]
styles:
custom_fields:
motion:
- position: absolute
- transition: 0.25s
- height: auto
- border-radius: 50%
- top: |
[[[
return entity.state === 'on'
? '-9%'
: '1%';
]]]
- right: |
[[[
return entity.state === 'on'
? '-7%'
: '3%';
]]]
- width: |
[[[
return entity.state === 'on'
? '14%'
: '20%';
]]]
- background: |
[[[
return entity.state === 'on'
? 'rgba(255, 255, 255, 0.8)'
: 'rgba(255,255,255,0.04)';
]]]
- padding: |
[[[
return entity.state === 'on'
? '4%'
: '9.2%';
]]]
- type: custom:button-card
entity: light.kitchen_lights_group
name: Kitchen
variables:
motion: binary_sensor.kitchen_motion
triggers_update: binary_sensor.kitchen_motion
template:
- light
- icon_hue
- motion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment