Skip to content

Instantly share code, notes, and snippets.

@zachowj
zachowj / howtouse.json
Last active September 11, 2020 16:47
create a directory inside the node_modules directory named snips place index.js in there
[{"id":"e3bbd992.6544d8","type":"inject","z":"ffbd7f06.4a014","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":944,"wires":[["5e7064be.6a665c"]]},{"id":"e32fd63f.6e1c38","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":486,"y":944,"wires":[]},{"id":"5e7064be.6a665c","type":"function","z":"ffbd7f06.4a014","name":"","func":"const snips = global.get(\"snips\");\nmsg.payload = snips.add(1,2);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":944,"wires":[["e32fd63f.6e1c38"]]}]
@zachowj
zachowj / xfinity-data-usage.json
Created August 30, 2020 00:03
Node-RED export for xfinity-data-usage
[{"id":"b8f1078b.24ad98","type":"ha-entity","z":"530c54b8.7cee3c","name":"Xfinity Usage","server":"55a65aed.d6a484","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Xfinity Usage"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:percent"},{"property":"unit_of_measurement","value":""}],"state":"currentUsage & \"/\" & allowableUsage & \" GB (\" & $round(currentUsage / allowableUsage * 100, 0) & \"%)\"","stateType":"jsonata","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":582,"y":128,"wires":[[]]},{"id":"f35fd1cd.e4526","type":"http in","z":"530c54b8.7cee3c","name":"","url":"/xfinity","method":"post","upload":false,"swaggerDoc":"","x":182,"y":176,"wires":[["325034f4.cb3e7c","bb07c2f8.50e11"]]},{"id":"325034f4.cb3e7c","type":"http response","z":"530c54b8.7cee3c","name":"","statusCode":"","headers":{},"x":354,"y":128,"wires":[]},{"id":"da9ef037.484c1","type":"comment","z":"530c54
[{"id":"884762f5.cd0d","type":"ha-api","z":"33f42d45.e29ad2","name":"areas","debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/area_registry/list\"}","dataType":"json","location":"areas","locationType":"msg","responseType":"json","x":370,"y":256,"wires":[["611635f4.9fa17c"]]},{"id":"13514152.b154ef","type":"inject","z":"33f42d45.e29ad2","name":"Manual Update","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":176,"y":256,"wires":[["884762f5.cd0d"]]},{"id":"611635f4.9fa17c","type":"ha-api","z":"33f42d45.e29ad2","name":"devices","debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\": \"config/device_registry/list\"}","dataType":"json","location":"devices","locationType":"msg","responseType":"json","x":510,"y":256,"wires":[["4448646c.da0b7c"]]},{"id":"4448646c.da0b7c","type":"ha-api","z":"33f42d45.e29ad2","name":"entities","debugenabled":false,"protocol":"websocket","method":"get","pa
@callback
def handle_discovery_update(self, msg):
"""Update entity config"""
if CONF_REMOVE in msg:
# Remove entity
if msg[CONF_REMOVE] == CHANGE_ENTITY_TYPE:
# recreate entity if component type changed
@callback
def recreate_entity():
"""Create entity with new type"""
const WebSocket = require("ws");
const hajw = require("home-assistant-js-websocket");
global.WebSocket = WebSocket;
const server = new WebSocket.Server({
port: 8081
});
server.on("connection", function connection(ws) {
@zachowj
zachowj / thefuzz4.js
Last active December 3, 2018 02:49
@thefuzz4Today at 11:04 AM I'm trying to check to see if my not_home time is greater than 5 mins since sometimes google makrs me as away and then right back at home. I wrote this java_script but its my first java_script so I am just curious if someone can take a look at my syntax to make sure it will do what I want it to do. Oh it also basicall…
const old_date = Date(msg.data.new_state.last_updated);
const new_date = Date(msg.data.old_state.last_updated);
const new_state = msg.data.new_state.state;
const old_state = msg.data.old_state.state;
const seconds = (new_date - old_date) / 1000;
if (new_state != old_state) {
if (seconds > 300) {
msg.payload = { data: { 'entity_id': 'device_tracker.google_maps_id', 'state': 'home' } };
return msg;