New Project: Home Automation

The topic “Home Automation” keep popping into my head for years now. I always questioned if it would be worth the investment. Both, financially and from a time effort perspective.

But I decided to give it a try. Mainly because it is the safest way to judge if it is worth it, once and for all. And there should be plenty possibilities for learning and trying out new things on the way.

So my first “goal” so to say is:

  • Home Automation software running
  • Some sensors for temperature/humidity
  • A dashboard for all rooms

Once I achieved that, I will check how to go on…

Default parameters in bash

Often you want to use default values in a bash script. Mostly when you want to make use of optional arguments. You can easily achieve that with parameter substitution.

unset VAR
echo $VAR        # VAR is "default"

VAR=${VAR-another default}
echo $VAR        # VAR is still "default"

There are more parameter substitutions which you can checkout at

How to access a specific array element using jq?

Let’s assume we have following JSON document

$cat > data.json <<EOF
→ { "data" : [
→   { "key": "a", "value": 1 },
→   { "key": "b", "value": 2 }
→ ]}

Now, we want to access the value where the key is “b”. In this specific case, we can of course do so with

$ cat data.json  | jq '.data[1].value'

But this relies on the order in the array and the data itself. A more generic and stable way would be

$ cat data.json  | jq '.data[]  | select(.key == "b") | .value'

For more details on jq, you can read

How to access the name of a pod?

Sometimes you need the name of a pod within a script (e.g. with kubectl exec). But since you normally want to use a deployment or replica set to manage your pod, the name of the pod might change and cannot be predicted.

There is an easy way to access the name of the pod via ‘kubectl’ with the help of labels. In this example we access the name of the pod described by the label label=value.

$kubectl get pod -l label=value -o jsonpath='{.items[0]}'

For details on the jsonpath parameter can be found at

How to create an example kubernetes deployment?

Here is a simple example of how to create a kubernetes deployment out of a yaml file.

cat << EOF > client.yaml
apiVersion: apps/v1
kind: Deployment
  name: client
    app: client
  replicas: 1
      app: client
        app: client
      - name: client
        image: ubuntu:18.04
        command: ["sleep"]
        args: ["3600"]
      restartPolicy: Always

The file can then be applied with kubectl apply -f client.yaml.

To verify the pod being started, just run kubectl get pod -l app=client.

Accessing a port on a pod

With kubectl, you can just forward a specific port of some pod to your local machine. So you can test the pod. A simple example:

# Start a grafana pod
kubectl run grafana --image=grafana/grafana
POD=$(kubectl get pod -l run= grafana \ 
    -o jsonpath="{.items[0]}")

# Forward port 3000
kubectl port-forward $POD 3000:3000 &

# Access port
curl -s http://localhost:3000/login | grep title