Skip to content

Instantly share code, notes, and snippets.

@thomasloven
thomasloven / my-custom-card.js
Last active November 20, 2024 11:02
Simplest custom card
// Simplest possible custom card
// Does nothing. Doesn't look like anything
class MyCustomCard extends HTMLElement {
setConfig(config) {
// The config object contains the configuration specified by the user in ui-lovelace.yaml
// for your card.
// It will minimally contain:
// config.type = "custom:my-custom-card"
@thomasloven
thomasloven / fixdailylinks.js
Last active July 27, 2024 07:40
Obsidian.md templater script to update the link chain of Daily Notes
@thomasloven
thomasloven / xiaomi_room_clean.yaml
Last active July 7, 2024 18:12
Make Xiaomi vacuum cleaner vacuum certain rooms by input_boolean state. Requires Home Assistant 2021.2.0 or later.
blueprint:
name: Xiaomi vacuum- clean rooms
description: |
## Clean the specified rooms
This works for Xiaomi vacuum cleaners which have room recognition and cleaning.
Vacuum specific rooms based on the state of a number of [Toggle Helper entities](/config/helpers) (`input_boolean`).
**This automation does not have any own triggers, but must be triggered manually or by an
`automation.trigger` service call.**
@thomasloven
thomasloven / random_color.yaml
Created September 28, 2020 12:32
Turn light on to random color name
- variables:
color: >-
{{["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
"bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
"burlywood", "cadetblue", "chartreuse", "chocolate", "coral",
"cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan",
"darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki",
"darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred",
"darksalmon", "darkseagreen", "darkslateblue", "darkslategray",
"darkslategrey", "darkturquoise", "darkviolet", "deeppink", "deepskyblue",
@thomasloven
thomasloven / fix_output_filenames.py
Last active April 12, 2024 11:25
Shorten PrusaSlicer output filenames for all default printers
""" Shortens output filenames for all printers in prusa config folder.
Will turn filename into: {input_filename_base}_{nozzle_size}_{printing_filament_types}_{print_time}.gcode
Place this file in your PrusaSlicer config folder (Help->Show Configuration Folder) and run it with python.
Make a backup first.
/ Thomas Lovén 2024
"""
import glob
import configparser
@thomasloven
thomasloven / configuration.yaml
Last active October 26, 2023 09:09
Use custom fonts in Home Assistant
# /config/configuration.yaml
...
lovelace:
mode: yaml
resources:
- url: /local/myfont.css
type: css
...
@thomasloven
thomasloven / customelement-test.ts
Last active August 15, 2023 06:09
How to use ha elements when using ScopedRegistry
import { LitElement, html } from "lit";
import { customElement, property } from "lit/decorators.js";
import { ScopedRegistryHost } from "@lit-labs/scoped-registry-mixin";
@customElement("customelement-test")
class CustomElementTest extends ScopedRegistryHost(LitElement) {
@property() hass;
static elementDefinitions = {
"ha-card": customElements.get("ha-card"), // This works because ha-card is ALWAYS loaded before custom cards (for now)
@thomasloven
thomasloven / chart-colors.js
Last active May 29, 2023 03:09
Replace history graph colors in lovelace
// Add this to your lovelace resources as
// url: /local/chart-colors.js
// type: module
customElements.whenDefined('ha-chart-base').then(() => {
// Find the HaChartBase class
const HaChartBase = customElements.get('ha-chart-base');
// Write a new color list generator
hass:account
hass:alert
hass:alert-circle
hass:altimeter
hass:apple-safari
hass:apps
hass:arrow-bottom-left
hass:arrow-down
hass:arrow-left
hass:arrow-right
/*
To move a panel to below the divider in Home Assistant
Add this to your configuration.yaml
frontend:
extra_module_url:
- /local/move-panel.js
And put the following into <config-dir>/www/move-panel.js
Replace URL_TO_MOVE with the url of your panel