Jupyter Notebook on Windows

This is a handy batch file to launch Jupyter notebook for windows in a virtual environment.


@echo off
cmd /k "cd /d C:\python36\scrape\Scripts & activate & cd /d C:\python36\scrape & jupyter notebook"
Advertisements

ImageMagick Radiology Image Annotation

Two handy commands for placing stamps on regular images and animated gif with Image Magick.

Regular Images:

magick convert etf.jpg -pointsize 35 -gravity south -stroke '#000C' -strokewidth 2 -annotate 0 'lamkerad@gmail.com' -stroke none -fill white -annotate 0 'lamkerad@gmail.com' -gravity north -stroke '#000C' -strokewidth 2 -annotate 0 'lamkerad@gmail.com' -stroke none -fill white -annotate 0 'lamkerad@gmail.com' anno_etf.jpg

etf_label
 

For animated GIF:

magick convert diastem.gif -pointsize 35 -gravity south -stroke '#000C' -strokewidth 2 -annotate +10+20 'lamkerad@gmail.com' -stroke none -fill white -annotate +10+20 'lamkerad@gmail.com' -gravity north -stroke '#000C' -strokewidth 2 -annotate +10+20 'lamkerad@gmail.com' -stroke none -fill white -annotate +10+20 'lamkerad@gmail.com' anno_diastem.gif

anno_diastem

Home Assistant on Orange Pi Zero With DietPi

NOTICE:  DUE TO CHRONIC STABILITY PROBLEMS, I DO NOT RECOMMEND USING STANDARD ARMBIAN ON OPZero.

 

Diet Pi solved my issues and I have had up to 20 days without a restart.  Even then, the only restart was because I had to change my UPS.  The steps below are essentially the same but replace Armbian with DietPi.

Home Assistant on Orange Pi Zero With DietPi

 


Guide here: https://home-assistant.io/blog/2017/05/13/home-assistant-on-orange-pi-zero/

Phase 1

Important: Have your router set the IP for the Orange Pi before you configure it. Manual configuration has broken the entire thing several times.

  1. Download Armbian for pi zero
  2. Download Etcher
  3. Extract Armbian and use etcher to burn image to microSD card (I used 2GB which may be too small)
  4. Insert mSD and plug into network.
  5. Check router for IP after giving time to boot.

Phase 2

Save a profile to putty:

  • include: keepalive 10 as per this post and enlarge the font if you are old like me and don’t like craning your neck to watch terminal output.

  • Putty to SSH into PiZero with root:1234

Change root password and create a user so you don’t have to use root.

sudo apt-get update

sudo apt-get upgrade

(directory locked and had to reboot first).   This step takes a while to download and install packages.


Phase 3

next install python and its packages:
sudo apt-get install python3-dev python3-pip python3-venv


Now execute the following:
ha@orangepizero:~$ pyvenv-3.5 homeassistant

ha@orangepizero:~$ cd homeassistant && source bin/activate


(homeassistant) ha@orangepizero:~/homeassistant$ pip3 install --upgrade pip


(homeassistant) ha@orangepizero:~/homeassistant$ pip3 install homeassistant


(homeassistant) ha@orangepizero:~/homeassistant$ hass

USE pyenv-3.4 if in dietpi

aiohttp takes quite a while to install so go get coffee or something. First loading hass also takes a while and appears to hang at several points.  That’s okay. Just give it some time.

Make sure to upgrade pip3 from the venv once it’s initiated.  Not doing that will cause a raft of errors.

There can be problems with venv so if needed, just destroy it with

sudo rm -rf homeassistant

Whoop! Dare it is!

Capture

I then restored by configs from the .homeassistant directory.

This threw errors for pylutron-caseta (because it wasn’t installed yet) and mqtt because mosquitto wasn’t installed yet.


Tackling mosquitto as a broker:

sudo apt-get install mosquitto

apt-get install mosquitto-clients

Gotta have both to monitor the messages using:

mosquitto_sub -h 127.0.0.1 -t “home-assistant/”


There is also a known issue with installation of pylutron-caseta (click for forum link).

To solve this one:

sudo apt-get install build-essential libssl-dev libffi-dev python-dev

Until you do that, you won’t get anywhere installing pylutron-caseta.

Also, be aware that pynacl take an extremely long time to install due to it only using one of the 4 cores for compilation.  There is a bug and fix enroute for this at the time of writing.

sudo -H pip3 install pylutron-caseta

This eventually installs in the venv after a reboot.  I also installed paho-mqtt through pip but am unsure if it is needed at all.

There are some super useful aliases which you’ll want to edit the .bashrc to add:

 

After you add the aliases, just

source .bashrc

to reload and implement the changes.


alias config='nano ~/.homeassistant/configuration.yaml'

alias checkconfig='hass --script check_config'


alias venv='cd ~/homeassistant && source bin/activate'


alias hasslog='nano ~/.homeassistant/home-assistant.log'


alias customize='nano ~/.homeassistant/customize.yaml'


alias restart='sudo systemctl restart home-assistant@ha'


alias status='sudo systemctl status home-assistant@ha'


alias stop='sudo systemctl stop home-assistant@ha'


alias start='sudo systemctl start home-assistant@ha'


alias secrets='nano ~/.homeassistant/secrets.yaml'

Don’t forget to enable HASS autostart.

file location:

/etc/systemd/system/home-assistant@ha.service

[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=%i

## The line below needs modification based on file location

ExecStart=/srv/homeassistant/bin/hass -c “/home/homeassistant/.homeassistant”

[Install]
WantedBy=multi-user.target


Install Armbian Monitor to use web interface for stats

sudo armbianmonitor r

Port: 8888


Samba

Setup here 


To Do list:

  1. Shell script automate backups of config files to github.  cron job.
  2. Backup to image using easus and win32 Disk Imager
    1. Test restored backups to secondary card
    2. Try restoring to disparate size card
  3.  Automate shell script complete disk image backups.
  4.  change units of some sensors so they don’t all get graphed together
    1. Particularly the DarkSky API sensor.
  5.  Automatically enter the venv from login/boot

Home Assistant on Orange Pi Zero

NOTICE:  DUE TO CHRONIC STABILITY PROBLEMS, I DO NOT RECOMMEND USING STANDARD ARMBIAN ON OPZero.  DIET PI RESOLVES STABILITY ISSUES.  NEW BLOG POST WILL BE FORTHCOMING.

 

 

Guide here: https://home-assistant.io/blog/2017/05/13/home-assistant-on-orange-pi-zero/

Phase 1

Important: Have your router set the IP for the Orange Pi before you configure it. Manual configuration has broken the entire thing several times.

  1. Download Armbian for pi zero
  2. Download Etcher
  3. Extract Armbian and use etcher to burn image to microSD card (I used 2GB which may be too small)
  4. Insert mSD and plug into network.
  5. Check router for IP after giving time to boot.

Phase 2

Save a profile to putty:

  • include: keepalive 10 as per this post and enlarge the font if you are old like me and don’t like craning your neck to watch terminal output.

  • Putty to SSH into PiZero with root:1234

Change root password and create a user so you don’t have to use root.

sudo apt-get update

sudo apt-get upgrade

(directory locked and had to reboot first).   This step takes a while to download and install packages.


Phase 3

next install python and its packages:
sudo apt-get install python3-dev python3-pip python3-venv


Now execute the following:
ha@orangepizero:~$ pyvenv-3.5 homeassistant

ha@orangepizero:~$ cd homeassistant && source bin/activate


(homeassistant) ha@orangepizero:~/homeassistant$ pip3 install --upgrade pip


(homeassistant) ha@orangepizero:~/homeassistant$ pip3 install homeassistant


(homeassistant) ha@orangepizero:~/homeassistant$ hass

USE pyenv-3.4 if in dietpi

aiohttp takes quite a while to install so go get coffee or something. First loading hass also takes a while and appears to hang at several points.  That’s okay. Just give it some time.

Make sure to upgrade pip3 from the venv once it’s initiated.  Not doing that will cause a raft of errors.

There can be problems with venv so if needed, just destroy it with

sudo rm -rf homeassistant

Whoop! Dare it is!

Capture

I then restored by configs from the .homeassistant directory.

This threw errors for pylutron-caseta (because it wasn’t installed yet) and mqtt because mosquitto wasn’t installed yet.


Tackling mosquitto as a broker:

sudo apt-get install mosquitto

apt-get install mosquitto-clients

Gotta have both to monitor the messages using:

mosquitto_sub -h 127.0.0.1 -t “home-assistant/”


There is also a known issue with installation of pylutron-caseta (click for forum link).

To solve this one:

sudo apt-get install build-essential libssl-dev libffi-dev python-dev

Until you do that, you won’t get anywhere installing pylutron-caseta.

Also, be aware that pynacl take an extremely long time to install due to it only using one of the 4 cores for compilation.  There is a bug and fix enroute for this at the time of writing.

sudo -H pip3 install pylutron-caseta

This eventually installs in the venv after a reboot.  I also installed paho-mqtt through pip but am unsure if it is needed at all.

There are some super useful aliases which you’ll want to edit the .bashrc to add:


alias config='nano ~/.homeassistant/configuration.yaml'

alias checkconfig='hass --script check_config'


alias venv='cd ~/homeassistant && source bin/activate'


alias hasslog='nano ~/.homeassistant/home-assistant.log'


alias customize='nano ~/.homeassistant/customize.yaml'


alias restart='sudo systemctl restart home-assistant@ha'


alias status='sudo systemctl status home-assistant@ha'


alias stop='sudo systemctl stop home-assistant@ha'


alias start='sudo systemctl start home-assistant@ha'


alias secrets='nano ~/.homeassistant/secrets.yaml'

Don’t forget to enable HASS autostart.

file location:

/etc/systemd/system/home-assistant@ha.service

[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=%i

## The line below needs modification based on file location

ExecStart=/srv/homeassistant/bin/hass -c “/home/homeassistant/.homeassistant”

[Install]
WantedBy=multi-user.target


Install Armbian Monitor to use web interface for stats

sudo armbianmonitor r

Port: 8888


Samba

Setup here 


To Do list:

  1. Shell script automate backups of config files to github.  cron job.
  2. Backup to image using easus and win32 Disk Imager
    1. Test restored backups to secondary card
    2. Try restoring to disparate size card
  3.  Automate shell script complete disk image backups.
  4.  change units of some sensors so they don’t all get graphed together
    1. Particularly the DarkSky API sensor.
  5.  Automatically enter the venv from login/boot

Convoy C8 Mod for Bike Light

I have wanted to get a driver that would allow me to have the fancy pants bike strobes I see on the $30 – 100 bike lights, but with all the quality and power of the convoy C8, so I am now in a quest to either find or build the driver I want.

Specifically, I’m looking for 2 modes: medium brightness and bike strobe.

High brightness is okay, but not much perceptible difference at night or daytime, which means wasted mAh.   I’d also like to not have to cycle through all the modes I don’t use to get to the strobe level. Further, standard 5-10 Hz strobes are annoying to a lot of people and combined with the brightness of the C8, I can understand.  It is at the crossroads of visibility and annoyance.

 

Convoy C8 Specifications:

  • Body Diameter: 25.5mm
  • Head Diameter: 44.5mm
  • Length:  145mm
  • Weight: 145g
  • MCPCB required: 20mm
  • Driver diameter required: 17mm
  • Reflector finish: Smooth

Product Arrived and was pretty straightforward to install.

The main advantage is the addition of the bike strobe which is a constant on at about 60% with a flicker strobe.

 

I wish I could have med and bike strobe as the only modes.  The code for the driver is available and is named “biscotti” so the next step is to use the old driver and reflash it with an arduino as an ISP to get a set of custom modes.

Digital kit cat clock update: OLED

tmp_6052-ezgif.com-video-to-gif360178373

 

I really love the Nokia 5100 display but wanted to try different varieties.  This is an SSD1306 0.96″ OLED display.  Resolution is 128 x 64 so significantly larger than the pixel size of the Nokia.

 

The contrast on the OLED is striking, so much so that it is difficult to photograph.  There will probably be more changes to the formatting and layout but the underlying code is the same as previous iterations of the clock with OTA updates, NTP sync, and WiFi Manager.