iPhone hotspot issues? Getting it to work with windows.

Had an issue the iPhone hotspot would not work on windows, it would see the network and try to connect, on the phone the hotspot bar at the top would appear and disappear. Simple solution… Go to settings and change the name of your iPhone and remove any single quotes (‘) from the name. Go back and turn the hotspot on and enjoy the connection. Well it worked on my computer :)

Getting a DietPi image running on Hyper-V

Why? Because it is faster to test installs and adding items to the DietPi installer with snapshots! Also it makes a great small Linux installation to run other items off in Hyper-V.

  1. Go get the VirtualBox VMWare x64 image from the DietPi site. http://dietpi.com/#five
  2. Download the QEMU disk image utility from https://cloudbase.it/qemu-img-windows/
  3. Extract the VirtualBox VMWare image, it is a ova file. At this point we need to take the actual disk image out of this file. I use 7zip for this purpose. Right click on the ova file and open archive. Then extract the VMDK file out.
  4. Extract the QEMU disk image utility to the same folder as the VMDK file and then run the following command changing the file names as needed:

.\qemu-img.exe convert ‘.\DietPi_v120_VirtualBox-x86_64-(Jessie)-disk1.vmdk’ -O vhdx -o subformat=dynamic ‘.\DietPi_v120_VirtualBox-x86_64-(Jessie)-disk1.vhdx’

.\qemu-img.exe convert “dietpi_vm.vmdk” -O vhdx -o subformat=dynamic ‘.\DietPi_VMWare-x86_64-Stretch.vhdx’

Now you need to open up Hyper-V and make a new VM using the image you just extracted. You may want to keep a copy around to make more images in the future. Related Posts: HA on Pine64 with DietPi

2018/01/30 - Update

Updated to use the VMWare image.

$zipexe = ‘C:\Program Files\7-Zip\7z.exe’
$qemuZip = “qemu-img-win-x64-2_3_0.zip”

Push-Location $env:TEMP
if(-not (Test-Path “dietpiimage”)) {
New-Item “dietpiimage” -Type Directory
}

Push-Location “dietpiimage”

Remove-Item * -Exclude @(‘.7z’,’.zip’)

if(-not (Test-Path $qemuZip)) {
Invoke-WebRequest -Uri “https://cloudbase.it/downloads/$qemuZip" -OutFile $qemuZip
}
& $zipexe x $qemuZip

### Image download and conversion

$imageName = “DietPi_VMWare-x86_64-Stretch”

if(-not (Test-Path “$imageName.7z”)) {
Invoke-WebRequest -Uri “http://dietpi.com/downloads/images/$imageName.7z" -OutFile “$imageName.7z”
}
& $zipexe x “$imageName.7z”

$disk = (Get-ChildItem *.vmdk)[0]
.\qemu-img.exe convert “$disk” -O vhdx -o subformat=dynamic “.\$imageName.vhdx”

Write-Host “$imageName.vhdx is ready!”

2018/07/01 - Stretch Update

Here is a PowerShell script to make it faster.

Push-Location $env:TEMP
if(-not (Test-Path “dietpiimage”)) {
New-Item “dietpiimage” -Type Directory
}

Push-Location “dietpiimage”

Remove-Item * -Exclude @(‘.7z’,’.zip’)

if(-not (Test-Path “DietPi_VirtualBox-x86_64-(Stretch).7z”)) {
Invoke-WebRequest -Uri “http://dietpi.com/downloads/images/DietPi\_VirtualBox-x86\_64-(Stretch).7z" -OutFile “DietPi_VirtualBox-x86_64-(Stretch).7z”
}

if(-not (Test-Path “qemu-img-win-x64-2_3_0.zip”)) {
Invoke-WebRequest -Uri “https://cloudbase.it/downloads/qemu-img-win-x64-2\_3\_0.zip" -OutFile “qemu-img-win-x64-2_3_0.zip”
}

$zipexe = ‘C:\Program Files\7-Zip\7z.exe’
& $zipexe x “DietPi_VirtualBox-x86_64-(Stretch).7z”
& $zipexe x “qemu-img-win-x64-2_3_0.zip”

Rename-Item (Get-ChildItem *.ova)[0] “DietPi_VirtualBox-x86_64-(Stretch)_OVA.tar”
& $zipexe x “DietPi_VirtualBox-x86_64-(Stretch)_OVA.tar”

$disk = (Get-ChildItem *.vmdk)[0]
.\qemu-img.exe convert “$disk” -O vhdx -o subformat=dynamic ‘.\DietPi_VirtualBox-x86_64-(Stretch)-disk1.vhdx’

Write-Host “DietPi_VirtualBox-x86_64-(Stretch)-disk1.vhdx is ready!”

2017/09/20 - Update

Here is a PowerShell script to make it faster.

Push-Location $env:TEMP
if(-not (Test-Path “dietpiimage”)) {
New-Item “dietpiimage” -Type Directory
}

Push-Location “dietpiimage”

Remove-Item * -Exclude @(‘.7z’,’.zip’)

if(-not (Test-Path “DietPi_VirtualBox-x86_64-(Jessie).7z”)) {
Invoke-WebRequest -Uri “http://dietpi.com/downloads/images/DietPi\_VirtualBox-x86\_64-(Jessie).7z" -OutFile “DietPi_VirtualBox-x86_64-(Jessie).7z”
}

if(-not (Test-Path “qemu-img-win-x64-2_3_0.zip”)) {
Invoke-WebRequest -Uri “https://cloudbase.it/downloads/qemu-img-win-x64-2\_3\_0.zip" -OutFile “qemu-img-win-x64-2_3_0.zip”
}

$zipexe = ‘C:\Program Files\7-Zip\7z.exe’
& $zipexe x “DietPi_VirtualBox-x86_64-(Jessie).7z”
& $zipexe x “qemu-img-win-x64-2_3_0.zip”

Rename-Item (Get-ChildItem *.ova)[0] “DietPi_VirtualBox-x86_64-(Jessie)_OVA.tar”
& $zipexe x “DietPi_VirtualBox-x86_64-(Jessie)_OVA.tar”

$disk = (Get-ChildItem *.vmdk)[0]
.\qemu-img.exe convert “$disk” -O vhdx -o subformat=dynamic ‘.\DietPi_VirtualBox-x86_64-(Jessie)-disk1.vhdx’

Write-Host “DietPi_VirtualBox-x86_64-(Jessie)-disk1.vhdx is ready!”

Getting HP Officejet Pro 8620 scan to network working...

So, tried to do this. Failed… Why? not because there was a issue with the share or the user/pass combination. It was the SMB process and stack locations in the I/O request packets (IRPs) that are used by Windows. Reference: https://technet.microsoft.com/en-us/library/cc734424(v=ws.10).aspx

To fix

To increase IRPStackSize for the server:

  1. Click Start, click Run, type regedit, and then click OK.
  2. Locate and then click to select the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Lanmanserver\Parameters
  3. On the Edit menu, point to New, and then click DWORD Value.
  4. Type IRPStackSize, and then press Enter.
  5. Right-click IRPStackSize, and then click Modify.
  6. In the Value data box, ensure decimal is selected and put in 20. Increase by 2 until it works. I ended up using 28.

Restart the server service to test or restart your PC. The process restart is faster :)

Developing Home Assistant on Windows using the Subsystem for Linux

I love Home Assistant and use it to control my house. I run it on a Pine64 board and it handles everything. However for developing and modifying it I want to have a slightly better environment than nano and a console screen :) So using the Subsystem for Linux I have a Linux based setup to run the hass instance in and can use Visual Studio code to develop the modules as I go, best of both worlds.

Installing the Windows Subsystem for Linux

To install the subsystem go to add/remove programs and tick the Windows Subsystem for Linux (Beta) then run bash.exe and this will start the installation, this may take a while as it pulls down the bits. Once completed and you restarted you can run bash again and then you are ready to start. [caption id=”attachment_1213” align=”aligncenter” width=”534”]Installing the Windows Subsystem for Linux Installing the Windows Subsystem for Linux[/caption]

Setting up the Home Assistant development environment

The https://home-assistant.io/developers/ page has lots of great information but here is how I do it condensed into a single process. In windows I have a dev folder under my user profile. This is c:\Users\myaccount\dev, in the bash console it is mapped to /mnt/c/Users/myaccount/dev/. This way you can work on the files in windows and run them in Linux, just watch out for a CR ;) Run the following in the bash terminal and replace the myaccount with your windows account and myrepo with your fork.

# ensure linux is up to date.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install git

# make local repo
mkdir /mnt/c/Users/myaccount/dev/
mkdir /mnt/c/Users/myaccount/dev/home-assistant-bash-config
cd /mnt/c/Users/myaccount/dev/
git clone https://github.com/myrepo/home-assistant.git home-assistant-bash
cd home-assistant-bash
git remote add upstream https://github.com/home-assistant/home-assistant.git

# Ensure we are up to date
git fetch upstream dev
git rebase upstream/dev

# dev environment setup
sudo apt-get install python-pip python3-dev
sudo apt-get install build-essential libssl-dev libffi-dev python-cffi
sudo pip install --upgrade virtualenv

# make and switch to virtual environment.
virtualenv -p python3 .
source ./bin/activate

# prepare dev bits and install all the requirements, this does take a while.
pip install --upgrade cryptography flake8 flake8-docstrings tox colorlog
script/setup

Using Visual Studio Code

If you do not have it download it here http://code.visualstudio.com/ once it is installed got to File -> Open Folder and navigate to c:\Users\myaccount\dev\home-assistant-bash and open that location. Visual Studio Code (or just Code from now on) is smart enough to know it is on an enlistment in Linux and will work with just LF endings so you do not have to worry about that. Code has a concept of extensions, for Python I use Python, MagicPython and Python for VSCode. These provide syntax checking, lint and other actions in the UI to make life easier. Also as you work with files Code may suggest other extension to help you along, and it handles YAML as a bonus and I do all my configuration editing in it.

Starting HASS

Open up bash and run the following.

cd /mnt/c/Users/myaccount/dev/
virtualenv -p python3 .
source ./bin/activate
hass -c /mnt/c/Users/myaccount/dev/home-assistant-bash-config

Development Cycle

This is the rough process I use.

  1. Open up bash and shift to the virtual environment and run hass as a check to see if all is good.
  2. Rebase with upstream to ensure I am not drifting to much (the code base in Home Assistant is very fast moving)
  3. Run hass again to ensure all is good.
  4. Open up Code against the hass folder code c:\Users\myaccount\dev\home-assistant-bash
  5. Open up Code against the configuration folder code c:\Users\myaccount\dev\home-assistant-bash-config
  6. Hack away!
  7. Restart hass as needed and switch between windows while drinking coffee and wondering how you can automate the walking of the dog.

Using Microsoft Flow with Home Assistant

Now that Microsoft Flow is out of Beta I thought I would play with it and integrate it with Home Assistant running my house. The Microsoft Flow is fairly flexible and has more flow options than IFTTT to make choices. To use this with Home Assistant I am going to use the REST API to make and set a sensor value, you can then take this and make it as complicated as you want. :) Settings You need to ensure you have this information at hand. * Home Assistant Endpoint - https://publicdomin:optionalPort/api * Your password for the http component. If you public expose HA without a password, stop and fix it now! * The name of the sensor you want to update. sensor.kitchen_temperature in this case.

  1. Go to https://flow.microsoft.com and login.
  2. Make a new Flow from a blank template
  3. Search for button (you can use other triggers but this is an easy start)
  4. Add a new step of type action.
  5. Select HTTP
  6. Change Method to POST
  7. In URI put the full URI of the sensor you want to change. Using the data above this is https://publicdomin:optionalPort/api/states/sensor.kitchen_temperature
  8. In headers add the following JSON blob. { “x-ha-access”: “YOURPASSWORD”, “Content-Type”: “application/json” }
  9. In Body put the JSON to update the sensor. { “state”: “25”, “attributes”: { “unit_of_measurement”: “°C” } }
  10. Save the Flow!

Now open up Flow on your phone and log in with the same account, you will see a nice big button with manual -> HTTP on it. Click that button and look at the state of the sensor in Home Assistant. You will see it with the value you set in the body. To trouble shoot, in the web UI click on the i with a circle around it. It will show a log of successes and failures. If you click on that you can drill into the details of the flow and the responses from Home Assistant.

Running Home Assistant on Pine64

This is a dump of me setting up Home Assistant on a Pine64 board I have. I am used to OpenHAB and have created bindings for it so this should be a new challenge and a way to see how well it works. The reason I am heading towards Home Assistant is the components it support fit some of my needs better. Also time to get to know python better :)

  1. Get DietPi, I am using DietPi_v127_PineA64-arm64-(Jessie) for this so over time some of the items may change, if you know what you are doing you should be good. It can be found at http://dietpi.com/
  2. Write it to a SD card and boot the Pine64 up with the card in the SD slot.
  3. Find it on the network! I just looked at the DHCP logs for my router. It I hard wired into the network so easy to find.
  4. Use a SSH client(Kitty) to connect to it, it will prompt you a few times and update. I will assume you can handle this, eventually you will connect to the Pine64 and have a system ready to go. Login details: username = root password = dietpi Things you should do.
    • Change the root password.
    • Update the firmware as needed.
    • Install Samba or FTP server is you want to edit remotely.
  5. User setup, I like to create a user for my own use. So being creative I shall call it fred! Make sure you add it to the sudo group to run admin commands. sudo adduser fred sudo adduser fred sudo
  6. Install python 3: sudo apt-get install python3 python3-pip
  7. Install Home Assistant pip3 install homeassistant
  8. Start Home Assistant: hass

Enabling MQTT abilities in OpenHab

Using your favorite editor in Linux or something like WinSCP we need to edit some OpenHAB configuration files. If you followed the guides on this site the configuration is located in /etc/openhab. Open up /etc/openhab/configurations/openhab.cfg to edit. If it does not exist you need to copy openhab_defaults.cfg in the same directory to openhab.cfg

sudo nano /etc/openhab/configurations/openhab.cfg

You need to navigate to the MQTT Transport section for transport settings. Ignore the MQTT Persistence section. The following three bolded configuration items need to be modified, I am using pimosquitto as the broker name, you can use whatever you want. Just be consistent.

################################# MQTT Transport ######################################
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace [broker] with a id you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mqtt:pimosquitto.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mqtt:pimosquitto.clientId=localpi

# Optional. User id to authenticate with the broker.
# mqtt:[broker].user=[user]

# Optional. Password to authenticate with the broker.
#mqtt:[broker].pwd=[password]

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#mqtt:[broker].qos=[qos]

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
mqtt:pimosquitto.retain=true

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#mqtt:[broker].async=[async]

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained
#mqtt:[broker].lwt=[last will definition]

Save the file. You are now ready to create a item in openhab and add it to a sitemap. I will assume you have the demo items and sitemap in place for this or already have a file ready to go. Open up the items file in the items folder under /etc/openhab/configurations. Add in a new group for testing, you can remove/comment this out when you are happy with your real configuration. Also add in a String so we can see the values in the site map. Example:

/* MQTT Testing groups, string and switches /
Group MqttTesting
/\
Inbound String for topic home/testing/message /
String MqttTestMessage “Message: [%s]“ (MqttTesting) {mqtt=”<[pimosquitto:home/testing/message:state:default]“}
/\
Inbound Switch for topic home/testing/message */
Switch MqttTestSwitch “MQTT Switch” (MqttTesting) {mqtt=”<[pimosquitto:home/testing/switch:command:ON]“}

Next we add this section to the sitemap. Open up the sitemap file in the sitemaps folder under /etc/openhab/configurations. This is a very simple frame that will list anything out in the group MqttTesting

Frame label=”Tests” {
Group item=MqttTesting label=”MQTT Testing”
}

Save the file and then open up your browser and navigate to http://:8080/openhab.app?sitemap=demo In mqtt-spy publish a message to home/testing/message with a message of hello, you should see it on the OpenHAB site. You now have MQTT working with OpenHAB.

Installing OpenHAB

To install and run OpenHab on your Pi I am recommending you use the apt-get approach, these instructions are taken from the OpenHAB Wiki, so it may be more up to date and have additional options. I also contribute to changes in the wiki every now and then so this may get out of date but in general be correct. This page does highlight the addons needed for the guides on my site. Shopping List - things you need to do this.

Just a Raspberry Pi for this, I still use V1 B+ as I have not needed to get a V2 yet. This pack has everything you need to get started.

  1. Install Java if 1.6 or higher is not already installed. The following will display your current Java version.

    java -version
  1. Add the openHAB Bintray Repositories key to the apt-keyring using wget:

    wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
or using curl:

    curl 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
  1. Add openHAB apt repository to the apt sources list (Note: the current openhab.list file will be overwritten)

    echo "deb http://dl.bintray.com/openhab/apt-repo stable main" | sudo tee /etc/apt/sources.list.d/openhab.list
  1. Resynchronize the package index

    sudo apt-get update
  1. Install the openHAB runtime

    sudo apt-get install openhab-runtime
  1. If you have more than one OpenHAB binding with a USB device (Z-Wave, RFXCOM, etc), refer to [[symlinks]]

  2. Start openHAB - manually

    1. Init based on sysVinit (e.g. Debian 7 / Ubuntu 14.x and earlier)

      sudo /etc/init.d/openhab start
      sudo /etc/init.d/openhab status
2.  Init based on systemd (e.g. Debian 8 / Ubuntu 15.x and higher)

        sudo systemctl start openhab
  1. Start openHAB - at system startup

    1. Init based on sysVinit

      sudo update-rc.d openhab defaults
2.  Init based on systemd

        sudo systemctl daemon-reload
        sudo systemctl enable openhab
  1. Install the add-ons / bindings as you need them. To follow these guides install the addons below. Feel free to add any other you may need or want.

    sudo apt-get install openhab-addon-${addon-type}-${addon-name}
Install these addons:


    sudo apt-get install openhab-addon-binding-http
    sudo apt-get install openhab-addon-binding-ntp
    sudo apt-get install openhab-addon-binding-weather
    sudo apt-get install openhab-addon-binding-zwave
    sudo apt-get install openhab-addon-persistence-logging
    sudo apt-get install openhab-addon-persistence-rrd4j 
    sudo apt-get install openhab-addon-binding-mqtt
    sudo apt-get install openhab-addon-binding-exec 
    sudo apt-get install openhab-addon-binding-squeezebox 
    sudo apt-get install openhab-addon-binding-xbmc 


A list of all available packages can be retrieved with

    sudo apt-cache search openhab
  1. Configure your system as outlined here: configuration.

  2. If you wish to use a USB zwave stick or other USB/serial device you will need to add the “openhab” users to the “dialout” group:

    sudo usermod -a -G dialout openhab

and then reboot.
  1. Test it, point your browser to http://localhost:8080/openhab.app?sitemap=yourname and you should see your sitemap. Replace localhost with the IP of your Pi if you are running headless.

Setting up Mosquitto on your Pi as part of the home hub

To enable all your nodes to communicate we are using a protocol called MQTT, on the pi we are using Mosquitto as the broker to support this. The broker allows nodes to publish information or subscribe to get information when it is published. MQTT uses simple channels to dictate where messages go, here are some examples:

HOME/Garage/DoorOne/State
HOME/Garage/DoorTwo/State
HOME/Garage/Temperature

The structure of the channel is up to you, just keep it short and logical! In these articles I will have them set to how I like them, feel free to change them as you need. To install Mosquitto on your Raspberry Pi run the following commands.

sudo apt-get install mosquitto mosquitto-clients

Now you have it installed lets test it to ensure it is working. You can do this in a few ways but I’m going to use mqtt-spy. Head to the github site and download the latest version (0.3.0 at the time of writing). Once you have it open it up and ensure a default configuration is created. Now you can add in your nice new broker. In the connections menu select new connection. The Server URI is the IP address of your Pi running OpenHab. To get this if you do not have it run ifconfig in a SSH session. Click on Apply and the Open the Connection. If everything is good you will have a new green tab at the top of the window, this is the connection to your Mosquitto broker instance. Right click on the tab and select Show Broker Statistics to see the $SYS channel and data. This is a good indication of traffice going to and from the broker and you have a connection up and running from another machine. To test subscribing and publishing make a subscription to test/my/channel in the new subscription section and press enter. In the publish section enter test/my/channel as the topic and Hello World as the data (what else…). Press publish and you will see it turn up in the subscription you just made. mqtt-spy is a handy tool to have around so keep it in your home automation toolbox. You now have Mosquitto installed and running on your system. Next we need to configure OpenHab to work with MQTT to send and receive messages.

Setting up a Pi with a NRF24L01+ Radio

I’m using my PI as the central hub running OpenHAB, a MQTT broker and other services for home automation. On the Pi I am using a NRF24L01+pa+lna SMA Antenna Wireless Transceiver, this provide more range (1000m) from my main unit. All the nodes in the network will be running on Arduino chips and using a Mesh network so the house should have good coverage. First, wiring in the NRF24L01 to the Pi.Using Female-to-Female dupont cables use the following table to connect the units, the NRF24L01 is ~3-3.6V.

Raspberry PI 1 - B+ to NRF24L01 Mapping Table

Raspberry PI 1 - B+

NRF24L01+

Ground (20)

GND

3v3 (17)

V+

BCM 8 /CE0 (24)

CSN

BCM 22 (15)

CE

BCM 10 / MOSI (19)

MOSI

BCM 11 / SCLK (23)

SCK

IRQ

BCM 9 / MISO (21)

MISO

I recommend checking the connections twice. A good Pi Layout can be found here: Raspberry Pi GPIO Layout Worksheet Now we have the wiring in place time to get the pi working. This assume you have followed guides on this site or other site and you are running rasberian. As I am using the awesome work by TMRh20 we are installing the bits in his github repo. Connect to the pi using SSH and run the following commands.

wget http://tmrh20.github.io/RF24Installer/RPi/install.sh
chmod +x install.sh
./install.sh
for D in *; do echo “Building and Installing $D”; cd “$D”; sudo make install; cd ..; done

After you run the installer.sh file it will prompt you to install components. Go ahead and select yes for all of them. If you ever need to do a update of the libraries in the future you will need to delete all the folders under rf24libs. Now the pi is ready to go with the RF unit and needed libraries.

Loading message from the API: ...