Skip to content

Instantly share code, notes, and snippets.

@mpflaga
mpflaga / office-sofa-lamp.yaml
Created March 25, 2024 01:34
Output of ESPhome composite config for SONOFF S31 ESP8266 - 2024.03.24
(.env.2024.3.0) PS C:\Users\micha\OneDrive\Documents\esphome> esphome config .\office-sofa-lamp.yaml
INFO ESPHome 2024.3.0
INFO Reading configuration .\office-sofa-lamp.yaml...
INFO Detected timezone 'America/New_York'
substitutions:
model_name: Sonoff S31
update_interval: 60s
esphome_name: office-sofa-lamp
friendly_name: Office Sofa Lamp
esphome:
@mpflaga
mpflaga / timezone_clocks.html
Created December 21, 2023 17:23
A quick web page displaying numerous time zones. It is meant to be a simple and easily editable list of zones for quick viewing.
<!DOCTYPE html>
<html>
<head>
<title>World Clocks</title>
<style>
body {
font-family: Arial, sans-serif;
}
.clock {
display: inline-block;
@mpflaga
mpflaga / ..ESPHome - Ping watchdog readme.md
Last active December 30, 2023 02:51
ESPHome recipe using SonOff S31 as an external Ping Watchdog.

This watchdog will power cycle the relay after the prescribed number of ping failure occurs. Additionally, the package is setting up metering sensors for testing and monitoring purposes.

Notes:

  1. This project relies on trombik/esphome-component-ping. The ./components/ping/. directory and files must be manually installed/copied into the `./esphome/config/.' directory, or equivalent, that will be compiling the firmware. It is straightforward, just follow the installation instructions on the Github README.

  2. Substitutions in the main homeassistant-watchdog-ping.yaml have been provided allowing "End Users" to customize the target_ip_address, ping_loss_threshold, off_delay and possibly the ping_hold_off to fit their specific needs.

@mpflaga
mpflaga / ..ESPHome - homeassistant API watchdog readme.md
Last active December 30, 2023 02:49
ESPHome recipe using SonOff S31 as an external Home Assistant Watchdog.

This watchdog relies on the native API connection reboot_timeout, to do the work. On Boot the ESP the .api-watchdog.yaml toggles off the switch’s relay supplying power to the Home Assistant for the specified time, ensuring the relay will properly power cycle the device. Additionally, the package is setting up metering sensors for testing and monitoring purposes.

Notes:

  1. This project has multiple files arranged as packages for modular setup of hardware, network and features.
    • homeassistant-watchdog.yaml - Top level file, that combines the below.
      • .api-watchdog.yaml - Abstracting particulars for the watchdog.
      • .network.yaml - Abstracting network setup.
      • .sonoff-s31.yaml - Abstracting hardware setup.
@mpflaga
mpflaga / Arduino-PhotoCellArrayAveraged.ino
Last active January 31, 2022 01:12
Arduino library of an array of averaged Analog Inputs connected PhotoCells (aka LDR)
#include "PhotCellArrayAveraged.h"
PhotoCell ldr[] = {{Pins{A0, A1}, 10}, {Pins{A2, A3}, 10}, {Pins{A4, A5}, 10}, {Pins{A6, A7}, 10}};
unsigned period = 1000;
unsigned long nextPrintTime;
void setup() {
// initialize serial communications at 9600 bps
Serial.begin(500000);
nextPrintTime = (unsigned long) (millis() + period);
@mpflaga
mpflaga / Arduino-PhotoCellArray.ino
Last active January 30, 2022 21:44
Arduino library of an array of Analog Inputs connected PhotoCells (aka LDR)
#include "Arduino.h"
struct Pins {
uint8_t sig;
uint8_t gnd;
};
class PhotoCell
{
public:
@mpflaga
mpflaga / Arduino NeoPixel Increamenter Tester
Last active February 25, 2021 17:48
Simple sketch to increment and decrement a single NeoPixel on a string as to determine positions of interest for defining segments.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 500
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int pos = 0;
@mpflaga
mpflaga / Arduino NeoPixel Chaser
Created February 3, 2021 02:09
Simple Arudino to test a string of NeoPixels. One LED scrolls out the length, as to reduce power constraints
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 200
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
@mpflaga
mpflaga / udptcpecho.py
Created December 7, 2017 18:24
UDP TCP Echo
#! /usr/bin/python
from __future__ import absolute_import
import sys, threading, argparse, pprint, logging, logging.handlers, os, __main__, platform
from socket import *
# Setup format for pprint.
pp = pprint.PrettyPrinter(indent=4)
BUFSIZE = 1024
@mpflaga
mpflaga / IrSonicWand.ino
Last active July 2, 2018 17:39
IrSonicWand - Device to learn and simulate up to 4 MagiQuest wands, along with sound effects
# schematic - https://drive.google.com/open?id=1SUm5G0ulMR-NaRY3s6r-mbK_2PaoASEd
#define LENGTH_OF_ARRAY(x) ((sizeof(x)/sizeof(x[0])))
// define pin locations
#define IR_RECV_PIN 2
#define IR_LED_TX_PIN 3
#define BUTTON_NOCAP_PIN 4
#define BUTTON_BLK_PIN 5
#define BUTTON_BLU_PIN 6