Skip to content

Instantly share code, notes, and snippets.

View nickbalch's full-sized avatar
🎯
Focusinging

nickbalch

🎯
Focusinging
View GitHub Profile
@nickbalch
nickbalch / googledirections.py
Last active August 16, 2021 22:28
Google API directions extractor. I have a need to export Google turn directions into a structured format so that they can be presented as printouts. Google Python reference is here: https://googlemaps.github.io/google-maps-services-python/docs/. Google's github for the python lib - https://github.com/googlemaps/google-maps-services-python which …
# https://stackoverflow.com/questions/13206695/json-parsing-of-google-maps-direction-api-in-python
import re
import csv
from googlemaps import Client
mapService = Client(key='')
directions = mapService.directions('start','end',waypoints'one|two|three')
directions = directions[0]
@nickbalch
nickbalch / homie-3-wemos-co2
Created June 26, 2021 17:12
Homie esp8266 arduino sketch for MHZ-16
#include <Homie.h>
#include <SoftwareSerial.h>
/***************************************************
* Infrared CO2 Sensor 0-50000ppm(Wide Range)
* ****************************************************
* The follow example is used to detect CO2 concentration.
* @author lg.gang(lg.gang@qq.com)
@nickbalch
nickbalch / Picture Frame photo slideshow Raspberry Pi Framebuffer working code
Last active August 7, 2020 18:54
Incomplete Picture Frame / Photo Slideshow Python code for Raspberry Pi and Touchscreen Display using Framebuffer.
import os
import stat
import pygame
import time
import random
# https://learn.adafruit.com/pi-video-output-using-pygame/pointing-pygame-to-the-framebuffer
drivers = ['directfb', 'fbcon', 'svgalib']
background = (255,255,0)
@nickbalch
nickbalch / arch.png
Last active November 30, 2021 21:04
Home Automation architecture - Openhab, MQTT, CurrentCost, PYWWS, Moteino, Arduino, RFXCOM
arch.png
@nickbalch
nickbalch / Moteino-Python-MQTT Bridge.md
Last active August 21, 2018 14:39
Moteino-Python-MQTT Bridge. Assumes a connected (via USB) moteino, and supports a number of specific formats for the data received. Refer to the arduino files where I have shared versions that use external temp sensors, or motion detectors. I relied very heavily on the sample sketches provided for the Moteinos plus code written by Gareth Naylor -

These are samples of my moteino to MQTT solution. Various moteino nodes send data to a central moteino node (Gateway) that is connected to a RaspberryPI via USB This Pi runs a python program that parses the recieved data and sends to various MQTT topics Other systems subscribe to the MQTT topics (for example, Openhab)

Moteinos are battery operated, run for many months on a 9V cell

@nickbalch
nickbalch / automation.rules
Last active April 26, 2017 17:09
Openhab presence rules for a living area and office. Takes input from PIRs, records presence, and turns on / off lights
rule "Working from home"
when
Item Presence_HomeOffice received command ON or
Item Presence_Living received command OFF
then
if (Presence_HomeOffice.state == ON && SCENE_LateNight.state != ON && Presence_Living.state != ON && GF_Living_Lights.state != OFF && SCENE_Watching.state != ON && SCENE_Evening.state != ON) {
//** if only home office is occupied, turn off lights **//
sendCommand(ALL_GF_LIGHTS,OFF)
}
end
@nickbalch
nickbalch / download_flickr_group.py
Last active August 9, 2022 07:36 — forked from Jarvl/download_flickr_set.py
Python scripts for downloading and maintaining flickr images from a group or set into a subfolder, then generating a RSS feed from a folder that could contain the downloaded flickr folder and/or additional images from elsewhere. Resulting file can be served up by any webserver to (for example) a LCD picture frame that can accept RSS feeds. RSS g…
#!/usr/bin/env python
# import libraries
#import sys
import datetime
import time
import random
import flickrapi
import requests
@nickbalch
nickbalch / RSSgen.py
Last active July 5, 2016 09:23
Python scripts for generating RSS feed of images in a directory. Resulting file can be served up by any webserver to (for example) a LCD picture frame that can accept RSS feeds. Adapted from http://www.stuffaboutcode.com/2012/09/python-create-rss-podcast-of-mp3-files.html
# import libraries
import os
import sys
import datetime
import time
import random
# import constants from stat library
from stat import * # ST_SIZE ST_MTIME
@nickbalch
nickbalch / moteino.items
Last active June 20, 2016 09:27
Moteino items and rules for Openhab. An MQTT broker is used to send data from the nodes. Openhab subscribes to the broker and picks up the updates. Nodes are configured to send data every 15 minutes. For ease of configuration and transparency, I have chosed to use a rule to map the nodes 1-5 to specific items. Moteinos are very mobile, so if one…
Group Moteino (State)
Group Moteino_batt (Moteino,Battery)
Group Moteino_temp (Temperature)
Group Moteino_signal (Moteino)
Group Moteino_monitor (Moteino,Status)
Group Moteino_version
Switch moteino_0_monitor "Node 0 Monitor" (Moteino_monitor)
Switch moteino_1_monitor "Node 1 Monitor" (Moteino_monitor)
Switch moteino_2_monitor "Node 2 Monitor" (Moteino_monitor)
@nickbalch
nickbalch / currentcost.rules
Last active October 27, 2019 12:55
Openhab items and rules for a currentcost installation but should work for any energy monitoring solution where device state shall be derived from the energy consumption. To avoid flapping or false detection, a timer is used to ensure temporary fluctations are ignored
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer
var Timer timer_tumble
var Timer timer_dishwasher_on
var Timer timer_dishwasher_off