0 Comments

Power Apps is a great no-code/low-code platform for home automation.

Home Automation powered by Power Apps

Remote Sauna project

Last weekend I added a new functionality into my home automation. Now the sauna can be turned on and off remotely.

This project had been in my todo list for a long time. I used to be able to turn the sauna on by phone. Just calling my son and asking him to turn it on and voilà, when I got home, it would be ready. Unfortunately, the automation stopped working once he went to high school.

DIY – Do It Yourself

I bought a long drill to drill the hole from sauna to technical room. Huhh. Finally. That was the first and most important step.

Drill the hole

The rest of the work are simple DIY - “Do It Yourself” tasks.

#1 Installing the one wire digital temperature sensor DS18B20.

digital temperature sensor DS18B20

#2 Installing the reed switch sensor + magnet for sauna door.

reed switch sensor + magnet for sauna door

#3 Installing a big ABB relay OKYM 0R40 into my home electrical panel that I found in my garage by luck.

ABB relay OKYM 0R40

#4 Already having a small reserve relay module to control the big relay.

relay module

#5 Already having the I2C to One Wire (DS2482-100) bridge device connected.

The One Wire system is a very nice solution as it can handle great amount of temperature sensors connected into it.

I2C to One Wire (DS2482-100)

#6 Eliminating the mechanical sauna heater timer.

After studying the schema I figured out that only one cable has to be reconnected.

Eliminating the sauna heater timer

#7 Connecting cables into Raspberry PI.

It used to look quite nice when I first started the project. From time to time, I decide to add to its functionalities, increasing the amount of cables by one or two.

20201206_073119808_iOS

#8 Connecting the sauna cables into the big relay.

ABB relay OKYM 0R40


Logic and programming

Every sauna automation has at least three important rules.

1. If sauna door is open then sauna can’t be turned on.

2. If sauna has been turned on already more than 3 hours then it turns off automatically.

3. If sauna temperature is extremely high (more than 110C) then it just turns off.

Implementation: the sauna button is disabled as the sauna door is open. Closing sauna door will enable the button immediately.

Home automation sauna control

Raspberry PI

Raspberry PI is the central hub of home automation. The base OS is Linux and on top of that is Azure IoT Edge, docker platform and containers. The code is inside the containers.

Visual Studio 2019 is the programming IDE. Code deployment and continuous delivery is fully automated by Azure DevOps and a self-hosted Arm32 deployment agent based on Raspberry PI.

A lot of Raspberry pin’s are already used but I have still some availability.

Raspberry PI pins

Power Apps as a user Interface

Home automation user interface is built on Power Apps. There are many reasons of choosing Power Apps over custom made web app.

#1 Power Apps is a no-code/low-code platform. Ready made components to just drag and drop them into place.

#2 Authentication is already done and it’s based on Office 365 security.

#3 Secure database connection to Azure CosmosDB is implemented by Azure Functions.

#4 Two-way communication between the app and Raspberry is secured by Azure IoT Edge.

0 Comments

You may wonder why this question even raised? Why we have to do something such a weird thing as to add Raspberry PI as an Azure DevOps agent?

Azure DevOps have plenty of agents for different OS-s to build and deploy solutions for Windows, Linux and mac-s.

Azure DevOps pipelines

Can I set up CI/CD pipeline for Raspberry?

No by default!

By default Azure DevOps doesn’t have an option to build a solution for Raspberry.

I couldn’t find complete instructions to do this so I created one.

To set up build pipeline for Raspberry we have to build Raspberry as a self-hosted agent for Azure DevOps.

After completing all the steps below you can create a fully automated CI/CD pipeline for your IoT Edge device based on Raspberry PI.

ARM32 hosted agent based on Raspberry PI

This is all SUPERCOOL !

Please be patient and follow all the steps below. It takes more than 1 hour of your time.

Ok, let’s rock with the Raspberry.

Step 1. Install Raspbian-strech /10min

This step is explained in another article so I am not going to repeat the story here. Please follow the instruction here.

#1 Installing Linux(Rasbian-stretch) on Raspberry PI

Step 2. Install prerequisites /4min

If you are smarter than me then you probably know why all this stuff needed.

sudo apt-get install python3-setuptools python3-dev build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y && sudo easy_install3 pip

Step 3. Install Python 3.7  /13min

1. Download and install Python. More information: https://gist.github.com/SeppPenner/6a5a30ebc8f79936fa136c524417761d

wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tar.xz && tar xf Python-3.7.4.tar.xz && cd Python-3.7.4 && ./configure && make -j 4 && sudo make altinstall && cd ..

2. Make Python 3.7 as default python version. More information: https://raspberry-valley.azurewebsites.net/Python-Default-Version/ 

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 && sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.7 2

Step 4. Install Azure CLI tools /18min

More information: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux 

Just push enter when the script asks for the default installation directories (twice in the beginning of the script) and paths (twice in the end of script).

curl -L https://aka.ms/InstallAzureCli | bash && exec -l $SHELL

Step 5. Install the IoT Edge runtime /2sec

More information: https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux

curl https://packages.microsoft.com/config/debian/stretch/multiarch/prod.list > ./microsoft-prod.list && sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/ && curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg && sudo cp ./microsoft.gpg /etc/apt/trusted.gpg.d/

Step 6. Install the Moby container runtime /4min

More information: https://docs.microsoft.com/en-us/azure/iot-edge/how-to-install-iot-edge-linux

Just push enter when the script ask for the default installation directory.

sudo apt-get update && sudo apt-get install moby-engine && sudo apt-get install moby-cli

Step 7. Install IotEdgeDev tool /15min

More information: https://github.com/Azure/iotedgedev/wiki/manual-dev-machine-setup

sudo pip3 install -U iotedgedev

Step 8. Create an agent pool /2min

Now it is time to switch into Azure DevOps portal and make some configurations here. Go to your https://dev.azure.com portal and open organization.

1. Open organization settings

Azure DevOps organization settings

2. Add new agent pool

Azure DevOps add new agent pool

3. Name it ARM

Azure DevOps add new agent pool

Step 9. Create Personal Access Token (PAT)

1. Click on your name in right corner and open Security.

Azure DevOps create personal access token (PAT)

2. Fill out the PAT form

Enter the name for the token. Put some meaningful name for it to remember later the reason you created it.

For the scope select Agent Pools (read, manage) and make sure all the other boxes are cleared. If you don’t see it just click below the link “Show more scopes”.

Azure DevOps configure personal access token (PAT)

3. Copy the PAT

Warning - Make sure you copy the above token now. You will not be able to see it again.

Azure DevOps personal access token (PAT)

v3xv75txw54cevpkriuafeawojmhqsibp4anxamtgyfr4zqt2ygq


Step 10. Configure Raspberry as an agent /3min

This script will download ARM template and configure Raspberry as an Azure DevOps hosted agent.

This script asks some questions during agent configuration.

wget https://vstsagentpackage.azureedge.net/agent/2.158.0/vsts-agent-linux-arm-2.158.0.tar.gz && mkdir myagent && cd myagent && tar zxvf ../vsts-agent-linux-arm-2.158.0.tar.gz && ./config.sh && sudo ./svc.sh install root && sudo ./svc.sh start && cd ..
  • Accept license terms: y + enter (do not just push enter as this equals No)
  • Server URL: https://dev.azure.com/testarm32 (your organization URL)
  • Your copied PAT: v3xv75txw54cevpkriuafeawojmhqsibp4anxamtgyfr4zqt2ygq
  • Agent pool: ARM
  • Agent name: just push enter

Configure Raspberry PI as an Azure DevOps self-hosted agent

Optional: You may want to change the command if there are never ARM-template available. On that case just update all the version numbers in the command.

To check never version of ARM template then open the agent pool in DevOps portal.

  • Click New Agent
  • Select Linux
  • Select ARM
  • Copy the download link (do not download this file into your PC, you don’t need it).

Finally you are done after 1h 10min!

You have now Raspberry PI configured as a self-hosted agent in Azure DevOps. For next step you can create a fully automated CI/CD pipeline for your Raspberry PI projects.

This is explained very well here by Microsoft: https://docs.microsoft.com/en-us/azure/iot-edge/how-to-ci-cd 

Check the new agent in the Azure DevOps portal.

Azure DevOps self-hosted agent