3D printed a little light case for a wemos and a piece of WS2812 led strip I had lying around.
Schematic: NOTE: The resistor is 100-500 ohm (I forgot, just try) You can only use this trick for a few leds (I used 4), else you better can use the sacrifice a led to make a level shifter trick. (Wemos logic is 3.3V and the led strip is 5V)
I flashed ESPHome on the wemos using the flasher in Home Assistant.
I’m running loads of housekeeping scripts on my servers.
I thought it would be cool to see states in HA.
Steps:
Log into your HA instance, and press your profile icon in the bottom left. Scroll to Long-lived access tokens, and create a new token. (Save the token string in a text file, you need it later)
Goto Settings > Devices & services > Helpers Create helper: Text and give it a name (bashnotification)
Next create a script in a path on your server, or place in an existing script directly. (Change SAVEDTOKENSTRING,HA-IP and bashnotification)
Below is a solution when you want to stream IP camera’s in Kodi/Libreelec .
You can push these commands using Nodered, Bash script or whatever.
First make some camera scripts in your profile directory.
Examples:
# Kodi on Linux/Raspberry
# Place a file cam1.m3u in .kodi/userdata/profiles/(kodiprofile)/playlists/video/
rtsp://admin:secretpass@192.168.1.123:88/videoMain
#and another one in cam2.m3u (another example mjpeg example)
http://192.168.1.124:8000/stream.mjpg
#For windows it is in
C:\Users\(Username)\AppData\Roaming\Kodi\userdata\profiles\(kodiprofile)\playlists\video
Enable http access in Kodi and run the playlist using curl
curl -i -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"options":{"shuffled":false,"repeat":"off"},"item":{"file":"special://profile/playlists/video/cam2.m3u"}},"id":"1"}' http://KODISERVERIP:8080/jsonrpc
A bash loop script
while true; do
curl -i -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"options":{"shuffled":false,"repeat":"off"},"item":{"file":"special://profile/playlists/video/cam1.m3u"}},"id":"1"}' http://KODISERVERIP:8080/jsonrpc
sleep 10
curl -i -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"options":{"shuffled":false,"repeat":"off"},"item":{"file":"special://profile/playlists/video/cam2.m3u"}},"id":"1"}' http://KODISERVERIP:8080/jsonrpc
sleep 5
done
#!/bin/bash
#set -x
f=MAE
numba=$(ls *png | wc -l)
numbastart=$(( $numba - 10))
numbapadding=$( printf "%04d\n" $numba)
numbapaddingstart=$( printf "%04d\n" $numbastart)
echo "$f "
mkdir -p images/$f
mkdir -p metric/$f
for x in $(seq -w 1 $numbapaddingstart) ; do
a=$(( $x + 10))
for y in $(seq -w $a $numbapadding) ; do
compare -fuzz 20% -verbose -metric $f $x.png $y.png images/$f/$x-$y.png 2> metric/$f/$x-$y.txt
echo -n "."
done
done
echo ""
Step 3 : There are metric stats in a subdirectory, let’s find the most matching parts (top 10)
orgpwd=$PWD
: > /tmp/top10
more metric/MAE/* | grep all | awk '{ print $2 }' | cut -f1 -d. | sort -n |head | while read ; do
grep -H all metric/MAE/* | cut -f1,2 -d. | grep " $REPLY" >> /tmp/top10
done
cat /tmp/top10 | cut -f3 -d/ | cut -f1 -d. | while read part ; do
echo mkdir -p "$part"
startpart=$(echo $part | cut -f1 -d-)
endpart=$(echo $part | cut -f2 -d-)
for file in $(seq -w $startpart $endpart) ; do
echo cp 0${file}.png $part/
done
echo cd "$part"
echo ffmpeg -y -framerate 30 -pattern_type glob -i \'*.png\' -c:v libx264 -pix_fmt yuv420p out.mp4
echo cd $orgpwd
done
Run above script as ./script.sh > mybash.sh
This generates a bash file, check the contents and run using
“bash mybash.sh”
Last step : There are 10 movies in subdirs which should contain the best looping parts. check these with: (use CTRL-Q in vlc to stop looping and go to the next file
ls */out.mp4 | while read movie ; do vlc -L $movie ; done
Got a question, could I make the video viewer also for images.
Well, that is a great idea, i’ve got some panoramic photos myself.
A little modification, some added code, but here is a working example.
Some vacation pictures widescreen …
CODE imageview.py filename Use esc to stop, and enter for next image. (Has better full screen experience than my movie player. (no padding) have to revisit that one )
Nice to have?
Back button?
Comments, renaming thumb
from pathlib import Path
from sys import platform as PLATFORM
import os
import re
import PySimpleGUI as sg
from PIL import Image, ImageEnhance, ImageTk, ImageOps, ImageFilter
from xml.etree import ElementTree as ET
import sys
from sys import platform as PLATFORM
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
try:
image=sys.argv[1]
except:
print(sys.argv[0] + " filename")
exit()
def nextFile(currentfile,dir):
newfile=""
dirpath = os.path.dirname(dir)
fileList = []
for f in os.listdir(dirpath):
#fpath = os.path.join(dirpath, f)
fpath = f
if os.path.isfile(fpath) and f.endswith(('.jpg','.JPG')):
fileList.append(fpath)
fileList.sort()
for i in range(len(fileList)):
try:
if (fileList[i]) == currentfile:
newfile=fileList[i+1]
break
except:
newfile=fileList[0]
return newfile
# yeah i know .. no thumb but full image, change it yourself!
def loadthumb(thumbfile):
# IF exists
path_to_file = thumbfile
path = Path(path_to_file)
if path.is_file():
im = Image.open(thumbfile)
im=ImageOps.contain(im, (5760,5760))
thumbimage = ImageTk.PhotoImage(image=im)
window['image'].update(data=thumbimage)
else:
window['image'].update("")
sg.theme('SystemDefaultForReal')
#------- Layout image only --------#
layout = [
[[sg.Image('', size=(5760, 1080), key='image',background_color='black',pad=(0, 0))],
]]
#------- Set window --------#
window = sg.Window('Triple image player', layout, no_titlebar=True, margins=(0,0),location=(0,0), size=(5760,1080), keep_on_top=True, finalize=True,resizable=False)
window.bring_to_front()
window.Maximize()
window.bind("<Escape>", "-ESCAPE-")
window.bind("<Return>", "-ENTER-")
window['image'].expand(True, True)
loadthumb(image)
nextfile = image
#------------ The Event Loop ------------#
while True:
event, values = window.read(timeout=1000) # run with a timeout so that current location can be updated
if event == sg.WIN_CLOSED:
break
if event == '-ENTER-':
nextfile = nextFile(nextfile,'./')
loadthumb(nextfile)
if event == '-ESCAPE-':
window.close()
window.close()
Converting images for right resolution from a temp directory filled with large panorama photos
ls temp | while read; do
convert -resize 5760x -gravity center -crop 5760x1080 -auto-orient "temp/$REPLY" "$REPLY"
done
I was playing around with Phantomjs a headless browser. Using this as a scraper for a ajax enabled site.
After scraping a wallpaper site, I wanted to take the big pictures and display these as background.
First sort and resize to a better size.
Below does the following:
Image width larger than 1800 AND
Image height larger than 900
Resize to 1920×1080 ( enlarge or reduce size )
Not screen filling (portrait mode) ? Than add black bars on the side.
Place the image in wallpaper directory
Convert script, if you resize huge images beforehand, you safe cpu resources later. You also can place other colors or even another background instead of black.
mkdir -p wallpaper
ls * | while read ; do
info=$(identify "$REPLY" | awk '{ print $3 }' 2>/dev/null)
height=$( echo $info | cut -f2 -dx)
width=$( echo $info | cut -f1 -dx)
if [ $width -gt 1800 ] && [ $height -gt 900 ] ; then
convert -resize 1920x1080 -gravity center -background black -extent 1920x1080 "$REPLY" "wallpaper/$REPLY"
fi
done
Set a random wallpaper as background using cron.
#!/bin/bash
DISPLAY=":0.0"
XAUTHORITY="/home/henri/.Xauthority"
XDG_RUNTIME_DIR="/run/user/1000"
cd /home/henri/Pictures/
getranpic=$(ls wallpaper/ |sort -R |tail -1)
#gsettings set org.gnome.desktop.background picture-options 'wallpaper'
#Set different modes ( enum 'none' 'wallpaper' 'centered' 'scaled' 'stretched' 'zoom' 'spanned' )
gsettings set org.gnome.desktop.background picture-uri-dark "$(realpath wallpaper/$getranpic)"
logger "$(realpath $getranpic)"