Skip to content

Instantly share code, notes, and snippets.

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 / 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 / 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 / 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 / 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 / rodauth__features__rails_conventions.rb
Created November 23, 2020 19:55
Make Rodauth routes, tables
require 'rodauth'
module Rodauth
# Clean up how we configure all of our tables, columns, etc., to use values which are more consistent with Rails than
# the defaults as well as use Rails mailers
Feature.define(:rails_conventions, :RailsConventions) do
depends :rails # rodauth-rails feature
def post_configure
# Rodauth uses dash-separated paths by default, so we'll make these underscores by default
@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 / authentication.rb
Last active January 25, 2022 16:05
Example of custom code to emulate a programmatic core in Rodauth
# frozen_string_literal: true
module Authentication
# Rodauth is pretty coupled to being in a request context, but this will provide the minimum necessary to be able
# to generate correct URLs
def self.rodauth(configuration_name = :user, params: {})
url_options = Rails.application.config.action_mailer.default_url_options
host = url_options[:host]
host += ":#{url_options[:port]}" if url_options.key?(:port)
base_url = "#{url_options[:protocol] || 'http'}://#{host}"