Skip to content

Instantly share code, notes, and snippets.

View bjeanes's full-sized avatar
🕊️

Bo Jeanes bjeanes

🕊️
View GitHub Profile
module Authentication
class API
# Some methods we use are on the "instance" which Rodauth doesn't (yet) consider part of its API. We'll hardcode the
# ones we want to let through here so we are conscious which parts of the private API we are exposing.
@@delegated_instance_methods = [
:otp_interval,
:otp_exists?,
:account_webauthn_usage,
:set_password,
:clear_other_sessions,
@bjeanes
bjeanes / migrate_from_devise.rb
Last active November 1, 2023 12:52
Rodauth feature to migrate from Devise, including maintaining all Devise columns (that I was using) in case a rollback was necessary (it wasn't)
# frozen_string_literal: true
require 'rodauth'
# In order for Rails to reload this constant in dev, we need `require_dependency` because Rodauth expects the features
# in a specific load path, but it defines a constant against Rails' expectations, which breaks reloading.
require_dependency 'rodauth/features/remote_ip'
module Rodauth
Feature.define(:migrate_from_devise, :MigrateFromDevise) do
@bjeanes
bjeanes / configuration.yaml
Created October 25, 2023 01:36
sungrow battery maintenance home assistant
automation:
- id: dbd6c805-f5cf-4c8b-9224-6163a460d620
alias: Inverter - battery maintenance # full cycle discharge and re-charge
trigger:
# TODO trigger when the battery charge/discharge today registers are below some threshold (however these registers
# aren't resetting the way they should currently)
# In meantime, we'll just do this at the once per month
- platform: time
at: "01:00:00" # 1 am
@bjeanes
bjeanes / ph-260bd-relay.yml
Last active April 29, 2023 15:51
ESPHome definition to pick up readings from the PH-260BD water PH/EC/TDS/Temp sensor - https://www.aliexpress.com/item/1005002707585119.html / https://www.aliexpress.com/item/4001143771176.html
esphome:
name: ph-260bd-relay
platform: ESP32
board: esp32dev
# Enable logging
logger:
logs:
esp32_ble_tracker: INFO
@bjeanes
bjeanes / winet-s.md
Created August 29, 2022 10:48
winet-s request notes

Requests

Of note:

  • The responses are pretty similar between websocket requests and HTTP requests
  • The result_code is 1 for success, varying other values for different types of errors
  • The result_msg is a usually "success", but contains more detail for certain errors. In at least one observed error response, the key was missing entirely.

HTTP

inverter:
host: REPLACEME # [Required] IP Address of the Inverter or Dongle
scan_interval: 1 # [Optional] Default is 30
connection: http # [Required] options: modbus, sungrow, http
model: "SH5.0RS" # [Optional] This is autodetected on startup, only needed if detection issues or for testing
log_console: ERROR # [Optional] Default is WARNING, Options: DEBUG, INFO, WARNING, ERROR
level: 0 # [Optional] Set the amount of information to gather
# 0 = Model and Solar Generation,
# 1 (default) = Useful data, all required for exports,
# 2 everything your Inverter supports,
@bjeanes
bjeanes / telegraf.conf.toml
Created July 23, 2022 00:25
Config for collecting metrics from Sungrow inverter (tested on my SH5.0RS) with Telegraf, to publish to anywhere Telegraf supports
[[inputs.modbus]]
name = "Sungrow inverter"
controller = "tcp://$SUNGROW_IP:502"
slave_id = 1
timeout = "1s"
## Define the configuration schema
## |---register -- define fields per register type in the original style (only supports one slave ID)
## |---request -- define fields on a requests base
@bjeanes
bjeanes / AAA_uuid_generate_v6mc.sql
Last active July 22, 2022 00:27
Postgres UUIDv6 (non-standard)
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- My port of https://github.com/kurttheviking/uuid-with-v6-js
-- A hacky translation of:
-- - http://gh.peabody.io/uuidv6/
-- - https://tools.ietf.org/html/draft-peabody-dispatch-new-uuid-format
CREATE OR REPLACE FUNCTION uuid_v1_to_v6(v1 uuid)
RETURNS uuid AS $$
DECLARE
v6 text;
@bjeanes
bjeanes / README.md
Created July 18, 2022 07:10
Excon Sentry tracing and sentry-trace header

Not yet sure if this is working, but roughly ports built-in Net::HTTP tracing from Sentry to an Excon middleware.

@bjeanes
bjeanes / cost_of_amazon.rb
Created June 11, 2012 02:50
How much have I spent on amazon.com?
require 'rubygems'
require 'mechanize'
require 'date'
email = ARGV.shift
password = ARGV.shift || print('Password: ') || gets.chomp
# TODO:
# * record average product price
# * histogram of purchase volume