Skip to content

Instantly share code, notes, and snippets.

@balloob
balloob / find.js
Created December 26, 2019 11:02
Icon finder
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 / ha-deno.ts
Last active May 16, 2020 15:04
Home Assistant Websocket Deno
// 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)
@balloob
balloob / debug-visibility.patch
Created June 27, 2020 06:57
Patch for HA frontend to debug visiblitychange behavior on Android
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 / example-panel.js
Last active August 31, 2020 13:34
Example Panel for Home Assistant
/*
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 / demo.js
Created August 1, 2017 15:50
Example using home-assistant-js-websocket with Node
const WebSocket = require('ws');
global.WebSocket = WebSocket;
const HAWS = require("home-assistant-js-websocket");
const getWsUrl = haUrl => `ws://${haUrl}/api/websocket`;
HAWS.createConnection(getWsUrl('localhost:8123')).then(conn => {
HAWS.subscribeEntities(conn, logEntities);
});
@balloob
balloob / example-card.js
Created February 20, 2021 03:26
Example custom card for Home Assistant. Created during Github Open Source Friday on Feb 19, 2021.
/*
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 November 14, 2020 22:50
Custom card for Home Assistant that shows a pull Light Card. Video at https://twitter.com/balloob/status/1327745146633510912
/*
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 / sensor_example.py
Last active November 23, 2021 16:31
Example platforms and automation component for Home Assistant
"""
Copy this file to <config_dir>/example/sensor.py
Add to your configuration.yaml:
sensor:
platform: example
"""
from homeassistant.const import TEMP_CELSIUS
from homeassistant.helpers.entity import Entity
@balloob
balloob / user-agent-card.js
Created December 29, 2021 06:55
User agent card
/*
Copy file to <config>/www/user-agent-card.js
Restart Home Assitant if www folder didn't exist.
In Home Assistant:
- Profile -> Enable advanced mode
- Config -> Dashboards -> Resources
- New resource. `/local/user-agent-card.js`. Type: JS Module
@balloob
balloob / demo-strategy.js
Last active May 19, 2022 20:57
Demo Lovelace strategy for Home Assistant
/*
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'