Thursday, January 18, 2018

Getting started with Snips and HomeAssistant: Part 1

So I have been using Snips to add voice controls to my Home Assistant setup. I just want to document some of the most frequent questions I get and give people some guidance.

Why use Snips instead of Alexa or Google Home? Because I really don't want a huge company recording everything I say.

Setting up Home Assistant is a whole topic in itself, but is not actually required to use snips. In a later post I'll give some example Python code you can use to set up your own voice responses.

Snips is in pretty fast development so this will probably get outdated soon enough, but will hopefully still have good information for people.

Installing Snips

Snips has their own documentation here so if you run into issues go back to their docs.

My installs are on Raspberry Pi 3 running Raspbian. I have been mucking with Linux for a long time so I prefer to have my own OS and such I can tinker with so I won't detail the docker installation.

The actual installation instructions are here: https://github.com/snipsco/snips-platform-documentation/wiki/1.-Setup-the-Snips-Voice-Platform

Hardware

I have two setups

That Jabra is a lot more expensive than when I bought it, get the Respeaker since it also give you pretty lights you can use to show when Snips is listening. Downside, is you need speakers to get sound output then, but that's a good thing since you can then use your Raspberry to play music too.

Sound Setup

The Snips software can simply use your alsa settings. Jabra is pretty straight forward, just plug it in and copy this to your asound.conf

Jabra /etc/asound.conf

pcm.!default {
  type asym
  playback.pcm {
    type plug
    slave {
      pcm "hw:0,0"
      rate 48000
      format "S16_LE"
      channels 2
    }
  }
  capture.pcm {
    type plug
    slave.pcm "hw:1,0"
  }
}

ctl.!default {
  type hw
  card 1
}


Respeaker 4 Mic Hat

This install is a little more complicated, from their oficial installation instructions here: https://github.com/SeeedDocument/ReSpeaker-4-Mic-Array-for-Raspberry-Pi/blob/master/ReSpeaker-4-Mic-Array-for-Raspberry-Pi.md

Get the seeed voice card source code.
# as your pi user on your raspberry
mkdir /home/pi/WORK
git clone https://github.com/respeaker/seeed-voicecard.git
cd seeed-voicecard
sudo ./install.sh 4mic
reboot
Then select the headphone jack on Raspberry Pi for audio output:
sudo raspi-config
# Select 7 Advanced Options
# Select A4 Audio
# Select 1 Force 3.5mm ('headphone') jack
# Select Finish
Check that the sound card name looks like this:
pi@raspberrypi:~/seeed-voicecard $ arecord -L
null
    Discard all samples (playback) or generate zero samples (capture)
playback
capture
dmixed
array
ac108
default:CARD=seeed4micvoicec
    seeed-4mic-voicecard,
    Default Audio Device
sysdefault:CARD=seeed4micvoicec
    seeed-4mic-voicecard,
    Default Audio Device
dmix:CARD=seeed4micvoicec,DEV=0
    seeed-4mic-voicecard,
    Direct sample mixing device
dsnoop:CARD=seeed4micvoicec,DEV=0
    seeed-4mic-voicecard,
    Direct sample snooping device
hw:CARD=seeed4micvoicec,DEV=0
    seeed-4mic-voicecard,
    Direct hardware device without any conversions
plughw:CARD=seeed4micvoicec,DEV=0
    seeed-4mic-voicecard,
    Hardware device with all software conversions

Respeaker 4 Mic Hat /etc/asound.conf

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "ac108"
}

pcm.playback {
    type plug
    slave.pcm "hw:0,0"
}


pcm.dmixed {
    type dmix
    slave.pcm "hw:0,0"
    ipc_key 555555
}


pcm.ac108 {
        type ac108
        slavepcm "hw:1,0"
        channels 4
}


Setting up the pretty lights

Here are the instructions for setting up the pretty led lights. In a later part we will detail how to how this go on automatically when Snips is listening.


cd /home/pi/WORK
git clone https://github.com/respeaker/4mics_hat.git
cd /home/pi/WORK/4mics_hat
sudo apt install python-virtualenv          # install python virtualenv tool
virtualenv --system-site-packages ~/env     # create a virtual python environment
source ~/env/bin/activate                   # activate the virtual environment
pip install spidev gpiozero           # install spidev and gpiozero
python pixels.py
You should see pretty lights flashing on the respeaker

Testing Sound

With the Jabra you will get sound from the speaker, for the Respeaker you need to plug in external speakers.


arecord test.wav

aplay test.wav

You should hear whatever you recorded. If that works you can now start with configuring Snips in Part 2

Sunday, December 10, 2017

Keurig WiFi Coffee Machine


So we all want a wifi enabled coffee machine, and there are some promising things on the horizon (spinn looks cool https://www.spinn.com/coffee-maker but $300 is a lot to spend, right?)

I looked at taking apart the keurig so I could do this as seamlessly as possible, but the keurig is a complete pain to disassemble, plus the possibility of destroying it made me stop pretty quickly. So why not just read leds and push buttons.

So this consists of Snips on a Rasp Pi3 doing voice stuff, talking to HomeAssistant to send an MQTT message to a NodeMcu WiFi Microcontroller with a solenoid to press the power button. There are 3 light dependent resistors to read power, heat and water empty leds and feed that back. The other two leds are auto off (amateurs, amiright?) and descale which I didn't think were critical.

It just sits on top so I can take it off if I need to, etc. It still needs solenoids for actually brewing the coffee, but I wanted to make sure the solenoid I got could produce enough force before I bought more.

So now that it works, i need to mount it on an actual pcb and add the extra solenoids and come up with a cover for the whole shebang (all the parts will live on top), since the WAF (Wife Acceptance Factor) is fairly low as it is. The nice thing is that you can still press the backside of the solenoids and access the buttons (like they did in the dark ages), so could conceivably be made pretty transparent.

Now I just need that robot arm to load the cups and put my mug in place. Maybe a cup warmer, so if I hit snooze it doesn't get cold? Maybe some sort of death clock? Bonus geek points if you get that reference.

Sunday, May 29, 2016

New Bimini for the boat

So it looks like rain for our trip so I added a bimini top, got it from Amazon for $104 shipped. Had to cut it down quite a bit, it was 46", cut it down to about 33 to fit under the boom so I could use it while sailing. 

Oh, and I finally cleaned the top sides! 

Link to the bimini (associate link): Amazon.com: Best Choice Products SKY1161 6' 600D UV Waterproof Top 3 Bow Bimini Boat Cover with Storage Case: Automotive


Thursday, May 19, 2016

Restoring the front hatch on my Spirit 23

The front hatch on our boats is a strong plastic of some variety, not acrylic or lexan. I was lucky in that my front hatch was not badly damaged, just some cracks along the back edge, but a ton of crazing. It was actually pretty solid since i did manage to step on it a few times.


 So I figured it couldn't hurt to try to pretty it up now that the windows look so good!

You can follow my thread on sailnet for more post although I will try to put them here as well now: Spirit 23 in Charlotte, NC

I epoxied the cracks in the back and then brushed the whole top of it with a couple layers of thinned epoxy to fill the cracks and crazing in it. Then covered it with about 10 coats of a semi gloss spar varnish.



The second image is just to show that it is still translucent, never be clear with all the crazing and such.

Overall really happy with it and I think it should hold up pretty well. I will probably make a cover for it for when it is stored just to keep the varnish fresh. Time will tell how it holds up.

Thursday, June 6, 2013

Got a nice sail in on the new boat, some sailing but a fair bit of motoring on the way back too. Nothing exciting which after some of sails is just right! Ignore the dirty sails...






Thursday, August 9, 2012

Sailing Lake Norman

Nothing too exciting, but I finally got the boat out for some sailing again, been quite a while! I've been doing a lot of mountain bike racing as well as playing on the powerboat. It's too bad because we have had good winds down here lately.


Going out was a straight shot downwind, then a couple lazy reaches across the bigger part of the bay. Coming in was a fair bit of tacking and I wasn't in a hurry but not super impressed with my tacking angles but really not too bad. All in all a nice relaxing day, except for a stowaway that decided to scamper across my foot partway out. A nice size wolf spider has been living down by the keel apparently. Hopefully he has moved on, really do not want to meet him again.

Wednesday, November 23, 2011

Shrink a Windows 7 Volume below Half

OK, time out from sailing for some tech talk. I could not find this solution anywhere so I thought I would post something telling how to shrink a volume in Windows 7. There are lots of answers out there that all involve spending money on 3rd party tools. But there is a fairly simple way to do it.

The issue is that Windows/NTFS stores an MFT file halfway along the drive which is an unmovable system file, which means not matter how little data you have on a drive you can't shrink past just over halfway since that file is started just past the halfway point on the volume.

This came up when I tried to restore a backup that used only 300GB of space or so onto a 640GB volume. You'd think that would work right? Well unfortunately Microsoft in all its brilliance decided that since the original backup came from a 1280GB volume, it couldn't be done. This will give an error about 'no suitable disk for restore found'.

The answer is to shrink the volume and then perform another backup with the smaller volume size which will then fit onto a smaller drive. Follow these basic steps to do that.

1. Defragment the drive. Always required. You can try using the windows utilities which should do the job. There is also a free alternative which actually uses a microsoft utility that will do a very thorough job as well. Power Defragmenter.
2. You may need to also move some system files around. You can follow steps from here. Howtogeek.com - working-around-windows-vistas-shrink-volume-inadequacy-problems
3. Create a system repair disk. Control Panel->Backup and Restore->Create a System Repair Disk.
4. Boot using that disk.
5. When it starts, cancel the restore process, and start a Windows Command Prompt.
6. Run diskpart
      list volumes
      select volume 2 # Choose the volume that corresponds to the drive you are trying to shrink.
      shrink querymax # This will tell you how much it can shrink
      shrink # Defaults to shrinking to the maximum amount.

That should be it. If you still can't shrink the disk, try doing it in Windows using Computer Management->Disk Manager. When it fails there, it will log an error in the event log telling you which file is involved, and you should be able to move that using one of the steps in step 2 above.

OK, back to sailing. Or maybe riding my bike.