Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View Elwell's full-sized avatar

Andrew Elwell Elwell

View GitHub Profile
@Elwell
Elwell / read_ds18b20.py
Created February 21, 2024 11:16
1-Wire bulk read
#!/usr/bin/python3
# bulk-read all attached 1-Wire temp sensors
# see https://docs.kernel.org/w1/slaves/w1_therm.html
bus_base = '/sys/devices/w1_bus_master1/'
def get_temp(addr):
with open(f'{bus_base}/{addr}/temperature', 'r') as t:
print (addr, int(t.read().strip())/1000)
---
esphome:
name: epever
friendly_name: epever
esp8266:
board: d1_mini
framework:
version: recommended
@Elwell
Elwell / README.md
Created July 16, 2023 11:44
ESPHome modbus configuration to read a Hiking DDS238-2 ZN/S Energy meter

ESPHome modbus polling of a single phase energy meter

This is my working configuration to poll a http://www.chinaenergymeter.com/1-1-15-dds238-2-zn-s-single-phase-din-rail-type-watt-hour-meter.html (I have the 65A hard wired variant - I've seen postings that the CT clamp version may not be as responsive

I'm using a wemos D1 mini (ESP8266) with a RS485 toTTL module (that's OK at 3.3v). This seems fine using software serial on D1/D2 at a polling rate of every 5s

GOTCHAS

  • If the wemos stays connected to home assistant but CAN'T talk to the meter, HA will re-use the last value rather than marking it offline/NaN/unavailable
@Elwell
Elwell / serialdump.py
Created August 7, 2022 06:16
Trivial script to sniff slow Tuya traffic between an embedded MCU and the TYWE3S serial pins
#!/usr/bin/python3
import serial
TX = serial.Serial(port = "/dev/ttyS2", baudrate=9600, timeout=1)
RX = serial.Serial(port = "/dev/ttyS4", baudrate=9600, timeout=1)
while True:
tx = TX.readline().hex()
if tx != '':
@Elwell
Elwell / gist:1b0421abea0fa7f90a139b3400c890f2
Created July 28, 2021 05:59
MQTT "auto" discovery for home-assistant of flashed Mi sensors
### 264902
mosquitto_pub -h broker-int -r \
-t homeassistant/sensor/ATC_264902_temp/config \
-m '{"device_class": "temperature",
"state_topic": "tele/tasmota_ble/ATC264902",
"name": "ATC_264902 Temperature",
"uniq_id": "ATC_264902_temp",
"unit_of_meas": "°C",
"value_template": "{{ value_json.Temperature}}",
"device": { "name": "ATC_264902", "sw_version": "3.1", "identifiers": ["ATC_264902"]}
@Elwell
Elwell / automations.yaml
Created May 22, 2021 13:16
Alexa notify on parsed MQTT JSON payload
- id: 'whatever'
alias: Valid SMS for gate
description: Announces sender of a valid gate trigger
trigger:
- platform: mqtt
topic: twilio/sms
payload: true
value_template: '{{ value_json.Gate_Auth }}'
condition: []
action:
root@zero-1:~# python3
Python 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tesserocr
!strcmp(locale, "C"):Error:Assert failed:in file baseapi.cpp, line 209
Segmentation fault
root@zero-1:~# dpkg -l | grep tess
ii libtesseract4:armhf 4.0.0-2 armhf Tesseract OCR library
@Elwell
Elwell / slurm_rpc.txt
Last active June 2, 2023 11:08
Slurm RPC to version mapping
Slurm RPC version is a bitwise shift as documented at
https://github.com/SchedMD/slurm/blob/master/src/common/slurm_protocol_common.h
This table is a cheat sheet of recent versions to RPC
Slurm Int RPC
--------------------------
23.11. 40. 10240 (DEVEL)
23.02. 39. 9984 (CURRENT)
22.05. 38. 9728 (SUPPORTED)
@Elwell
Elwell / rbh2influx.py
Last active August 8, 2021 22:46
robinhood rbh-report to influxdb parser
bravo:~ # cat rbh2influx.py
#!/usr/bin/python3
# rbh-report to influx publisher
# Andrew Elwell <Andrew.Elwell@pawsey.org.au>, July 2020
import time
import subprocess
import csv
import requests
@Elwell
Elwell / automations.yaml
Created May 7, 2020 22:30
Cheerlights into Mosquitto and Home assistant
- alias: 'Cheerlights to GlowOrb'
trigger:
platform: mqtt
topic: cheerlightsRGB
action:
service_template: light.turn_on
data_template:
brightness_pct: 50
rgb_color:
- "{{ trigger.payload[1:3] | int(0,16) }}"