Skip to content

Instantly share code, notes, and snippets.

@balloob
balloob / balloob-battery-strategy.js
Created Apr 28, 2021
Lovelace strategy to show all batteries grouped by area.
View balloob-battery-strategy.js
/*
Battery strategy that shows your battery entities grouped by area.
To use:
- store this file in `<config>/www/balloob-battery-strategy.js`
- Add lovelace resource: `/local/balloob-battery-strategy.js`, type JavaScript Module
- Create a new Lovelace dashboard and set as content:
views:
- title: Batteries
@balloob
balloob / demo-strategy.js
Last active Apr 25, 2021
Demo Lovelace strategy for Home Assistant
View demo-strategy.js
/*
Demo strategy that shows each area as a tab. Each tab shows the area entities.
To use:
- store this file in `<config>/www/demo-strategy.js`
- Add lovelace resource: `/local/demo-strategy.js`, type JavaScript Module
- Create a new Lovelace dashboard and set as content:
strategy:
name: 'custom:balloob-demo'
@balloob
balloob / example-card.js
Created Feb 20, 2021
Example custom card for Home Assistant. Created during Github Open Source Friday on Feb 19, 2021.
View example-card.js
/*
To use in Home Assistant, configure card:
type: 'custom:example-card'
entities:
- switch.wemo_insight
- light.bed_light
- light.ceiling_lights
- light.kitchen_lights
@balloob
balloob / pull-light-card.js
Created Nov 14, 2020
Custom card for Home Assistant that shows a pull Light Card. Video at https://twitter.com/balloob/status/1327745146633510912
View pull-light-card.js
/*
Created by @jh3yy
Adapted for Home Assistant by @balloob
Original: https://twitter.com/jh3yy/status/1327686213432717313
Only works on localhost because of restrictions MorphSVGPlugin3
Card config for usage in Home Assistant:
@balloob
balloob / example-panel.js
Last active Aug 31, 2020
Example Panel for Home Assistant
View example-panel.js
/*
Example panel.
Put this file in <config>/www/example-panel.js
In configuration.yaml:
panel_custom:
- name: example-panel
# url_path needs to be unique for each panel_custom config
@balloob
balloob / debug-visibility.patch
Created Jun 27, 2020
Patch for HA frontend to debug visiblitychange behavior on Android
View debug-visibility.patch
diff --git a/src/layouts/home-assistant.ts b/src/layouts/home-assistant.ts
index 0dae29df..663d152f 100644
--- a/src/layouts/home-assistant.ts
+++ b/src/layouts/home-assistant.ts
@@ -150,6 +150,7 @@ export class HomeAssistantAppEl extends HassElement {
protected _handleVisibilityChange() {
if (document.hidden) {
+ console.log("home-assistant handle tab hidden");
// If the document is hidden, we will prevent reconnects until we are visible again
@balloob
balloob / panel-redirect.js
Created Jun 22, 2020
Add redirects to the Home Assistant sidebar to any place in Home Assistant
View panel-redirect.js
/*
Add a link to the sidebar to any path in Home Assistant
Put this file in <config>/www/panel-redirect.js
In configuration.yaml:
panel_custom:
- name: panel-redirect
# url_path needs to be unique for each panel_custom config
@balloob
balloob / ha-deno.ts
Last active May 16, 2020
Home Assistant Websocket Deno
View ha-deno.ts
// Connect to Home Assistant from Deno
// Video: https://twitter.com/balloob/status/1261550082521919488?s=19
//
// Example is built-in as CLI. Try it out:
// deno run --allow-net https://raw-path-to-gist <home assistant url> <long lived access token>
//
// To use in your own code:
// import { createConnection } from https://raw-path-to-gist
// const conn = await createConnection(urlOfHomeAssistant, accessToken)
View find.js
const path = require("path");
const fs = require("fs");
const ICON_PACKAGE_PATH = path.resolve("./node_modules/@mdi/svg/");
const META_PATH = path.resolve(ICON_PACKAGE_PATH, "meta.json");
const ICON_PATH = path.resolve(ICON_PACKAGE_PATH, "svg");
// Print icons + sizes to create sizes.json
// const getPath = (icon) => {
// const svg = fs.readFileSync(`${ICON_PATH}/${icon}.svg`, {
@balloob
balloob / config_flow.py
Created Oct 16, 2019
Config flow to link Home Assistant with Home Assistant
View config_flow.py
"""Config flow to connect with Home Assistant."""
import logging
import voluptuous as vol
from homeassistant.helpers import config_entry_oauth2_flow
from .const import DOMAIN