Lazy Man Joe's Ramblings


July 2018

GardenPi – a garden watering solution built on Raspberry Pi, MQTT and [Part 1/4]

We currently have an off-the-shelf garden watering solution [Hunter], but I’d like to have more control of when, etc. the irrigation is switched on.

I used the following items in my solution:


  • Raspberry Pi 2 B+ [using a 16GB SD card]
  • Raspberry Pi Wifi Dongle
  • 8 Port Relay board




I first started prepping my Raspberry Pi and because I’ll be running it as a headless solution, I used the latest Rasbian Lite OS [download here] (Raspbian Stretch) which doesn’t have the UI and you configure all via the command-line

  1. Using Etcher, I wrote the image onto the 16GB SD card
  2. Take your SD card and boot up the Raspberry Pi
    1. Although I am going headless, I used a keyboard and screen to configure the base OS – I need a way to configure the Wifi and the easiest is when you use raspi-config.
  3. I configured the following once the 1st boot-up was done:
    1.  sudo raspi-config 
    2. Configure your locale, timezone and keyboard layout [I use the en_ZA.UTF-8 locale settings and US keyboard layout]
    3. Also configure your Wifi settings (SSID & Password, Wifi Country)
    4. Change the network name of your Raspberry Pi (mine’s called GardenPi)
    5. I also updated the password for the default pi user (default password is “raspberry” & it’s a good idea to change it 🙂 )
    6. I then forced an update in the locale file (I’ve had some issues in the past and found if you force it, things work better)
      1.  sudo nano /etc/default/locale 
      2. Add the following:
        1. LANG=en_ZA.UTF-8
    7. I also enabled SSH as I will be using SSH to manage the RaspberryPi in future.
  4. Reboot your Raspberry Pi, log in using the pi user and the new password you configured.
  5. Check your ip address
    1.  ifconfig 
    2. My result showed my wlan0 adapter on IP
  6. You can now make this IP address ( static on your router to ensure you can easily “find” your raspberry pi when you want to manage it using ssh
  7. I tested my ssh configuration from my Macbook
    1.  ssh pi@ 
  8. As a last step, I always check whether the latest updates are installed on my raspberrypi
    1. sudo apt-get update
      sudo apt-get upgrade

Now you can move on to the software installation !



OK, we 1st need python installed

sudo apt install python-pip 


Once python is installed, you can install PI-MQTT-GPIO (it will install MQTT as part of the setup] (more details here)

pip install pi-mqtt-gpio 

As I already have MQTT running as part of the rest of my setup, I will now only have to configure pi-mqtt-gpio to publish/subscribe to the MQTT messages.

Update your config.yml file with the necessary info, my info below (with some passwords hidden 🙂 )

NOTE – I’m only showing Zone 1 & Zone 2 settings (output & input)

host: mqtt-host-ip-address
port: 1883
user: "*******"
password: "*****"
topic_prefix: lazyhome/garden

- name: raspberrypi
module: raspberrypi

digital_outputs:     #used to send commands to the GPIO pins
- name: zone1
module: raspberrypi
pin: 5       #GPIO pin number - not the board pin, but the GPIO pin
on_payload: "ON"
off_payload: "OFF"
initial: low # This optional value controls the initial state of the pin
retain: yes # This option value controls if the message is retained.

- name: zone2
module: raspberrypi
pin: 6
on_payload: "ON"
off_payload: "OFF"
initial: low

digital_inputs:     #used to read status from GPIO pins
- name: zone1
module: raspberrypi
pin: 5
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone2
module: raspberrypi
pin: 6
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

The GPIO pins are referenced as per the following layout:


So to test PI-MQTT-GPIO, you can run it in console mode (running it from the /home/pi folder):

 python -m pi_mqtt_gpio.server config.yml 

It should show you connecting to the MQTT server, and then subscribing to the messages, etc.

Quick checklist:

  • Raspberry Pi running Rasbian Stretch Lite, with wifi dongle
  • PI-MQTT-GPIO installed (using python & pip)

In PART 2 we’ll bring is all together in Home Assistant.


Advertisements – Grouping your entities / switches in a logical fashion

While adding more & more switches into my Home Assistant setup, I’ve needed to group the items together in a logical manner.

I have switches controlling our geysers, general “playground” switches and I’m also implementing a solution to control our garden irrigation [details to follow soon].

I first split out the switch configuration into their own switches.yaml file:

- platform: mqtt
name: "Bedroom Geyser"
command_topic: "cmnd/Sonoff1/power1"
state_topic: "stat/Sonoff1/POWER1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Upstairs Geyser"
command_topic: "cmnd/Sonoff1/power2"
state_topic: "stat/Sonoff1/POWER2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Switch3"
command_topic: "cmnd/Sonoff2/power1"
state_topic: "stat/Sonoff2/POWER1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Switch4"
command_topic: "cmnd/Sonoff2/power2"
state_topic: "stat/Sonoff2/POWER2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 1"
command_topic: "lazyhome/garden/output/zone1/set"
state_topic: "lazyhome/garden/input/zone1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 2"
command_topic: "lazyhome/garden/output/zone2/set"
state_topic: "lazyhome/garden/input/zone2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 3"
command_topic: "lazyhome/garden/output/zone3/set"
state_topic: "lazyhome/garden/input/zone3"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 4"
command_topic: "lazyhome/garden/output/zone4/set"
state_topic: "lazyhome/garden/input/zone4"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true

I then created a groups.yaml file with the following:


name: Geysers
- switch.bedroom_geyser
- switch.upstairs_geyser

name: Garden
- switch.Garden_Zone_1
- switch.Garden_Zone_2
- switch.Garden_Zone_3
- switch.Garden_Zone_4

Finally I added the following to my configuration.yaml file:

# Add switch config in separate file
switch: !include switches.yaml
# Add group config in separate file
group: !include groups.yaml

The end result looks great !


More info on the GROUP option here –

Node-RED flow for Geyser management using Sonoff switches and Home Assistant

We have 2 geysers (for other parts in the world it’s called water heaters :-)) in our house and to save some energy (& money), we want to manage when these geysers are switched on.

Typically a geyser will run 24/7 and keep the water heated, even when nobody is home.

So the idea is to put the geysers on a time-schedule for when we’re normally at home, so we only heat the water when we’re going to use it.

To put this in motion, there are a couple of things we need to do:

  1. Connect the Sonoff switch to the geysers [using a Sonoff Dual, so 1 Sonoff & 2 relays]
  2. Configure the Switches in Home Assistant
  3. Configure a flow to ensure the geysers are on at specific times during the week & weekend

Connecting the Sonoff Switch to the Geysers

Geysers tend to draw a lot of power when the element is on and the Sonoff Dual switch is only rated for 16A/10A – which is fine for normal use, but won’t cut it for geyser use.

We need to implement another solution:
– the solution is using a 230V/30Amp relay.


This will allow us to use the Sonoff switch, but the main load will pass through the relay instead of the  Sonoff switch.

Now we have to connect the geysers in the distribution box to the Sonoff switch [some rewiring required here]


That’s it !

[P.S. I already configured the Sonoff on the network, so this wiring was all I needed to do]

Connecting the Sonoff Switch to Home Assistant

To make Home Assistant aware of the switch, we need to add some configuration info into the configuration.yaml file.

I added the following lines: (I moved all the switch configs to a separate switches.yaml file)

Configuration.yaml (add these line)
# Put switch config in separate file
switch: !include switches.yaml

Now in the switches.yaml add the config info for the geyser switches:
– platform: mqtt
name: “Bedroom Geyser”
command_topic: “cmnd/Sonoff1/power1”
state_topic: “stat/Sonoff1/POWER1”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: true
– platform: mqtt
name: “Upstairs Geyser”
command_topic: “cmnd/Sonoff1/power2”
state_topic: “stat/Sonoff1/POWER2”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: true

As you can see, it uses mqtt (Mosquitto Broker) to communicate with the switches (command_topic & state_topic)

So now these switches will show up in Home Assistant (after a restart of HASS)


OK now we move to the FUN stuff !

Configure the Node-RED Flow in Home Assistant

We decided that for our purposes the following schedule makes sense:
– Weekdays the geysers need to be on in the morning & the evening
– Weekends we will run the geysers most of the day (as we may shower at any time & tend to be around more)

The flow looks like this:


I split the flows into 2 separate ones for possible future changes where the geysers will be on different schedules.

Also, the basic flow is my 1st attempt [put it in place today] – so we may tweak it over time 🙂


Sometimes we may actually select to switch the geysers on when we want – which we can always do from the Home Assistant front-end.

I’m also thinking of adding a flag to state when we have guests staying over, and then disabling the schedule, etc. [future project :-)]

Another thing I also need to do is have a physical over-ride button connected to the Sonoff switch (there are pins available for this) – this will allow me to manually switch the geysers on in the event the Sonoff loses connectivity to the wifi.

Well, this was an eventful couple of days !

Now deciding on to the next bit of automation ! 🙂


Have fun !

Sonoff Wifi Switches – Flashing it with Tasmota Over-The-Air (OTA)

A friend of mine recently introduced me to the Sonoff switches – affordable, easy to use AND RE-programmable ! [Thanks Cliff ;-)]

I got the Sonoff Dual switch, which allows you to switch 2 separate appliances/devices from 1 Wifi switch.


Anyways, to get going I decided to flash it with the Sonoff-Tasmota firmware (as I wanted to be able to pull it into my Home Assistant setup easily)

The instructions on the Tasmota-Sonoff Wiki is fairly easy to follow and although they suggest you use a wired 3.3V FTDI USB-to-Serial Converter/Programmer (or a Raspberry Pi) – I also noticed you can use Wifi to update the firmware Over-The-Air !

The tool for that is called SonOTA. [Please note not all Sonoff switches may support this – so make sure you have a supported Sonoff Firmware version BEFORE you try to flash with SonOTA)

There are a couple of ways to get SonOTA working:

  1. Using the Windows pre-built .EXE (you can find it here)
    1. I used this as a 1st pass for the 1st Sonoff Dual switch I flashed with the firmware
    2. This is a quick & dirty way – but it CAN work & there’s nothing wrong with this 🙂
  2. Installing the SonOTA software on your machine & customising it as you need (this involves installing Python 3, etc. on your local machine)
    1. Here you can customise some of the setting beforehand
    2. I left all vanilla & it still worked fine 🙂

Once you have SonOTA on your machine, you can run it and follow the instructions on-screen.

The process involves:

  1. Running SonOTA (./
  2. Confirming the configuration of you local machine to ensure you have all the required bits in place
  3. Putting your Sonoff in Access Point (AP) mode [holding the button in for more than 7 seconds] and then connecting to the ITEAD-* wifi network
  4. Installing a small base firmware uploader
  5. The Sonoff will then connect to you local machine to get the actual firmware installed
  6. Just be patient and things will happen 🙂
  7. Once installed, you will go into “FinalStage” mode
    1. Here you connect to the Sonoff [wifi now called FinalStage] and configure it to be able to connect to your wifi network
    2. Once configured, it will reboot and join your wifi
  8. Then you have to check your router /DHCP server to make sure your Sonoff’s IP address gets reserved (to make sure it doesn’t change on power loss / reboot)

Upgrading your Sonoff to the latest Tasmota Firmware

The SonOTA tool flashes a version of Tasmota which may be outdated (you CAN update the config manually, but why worry ? :-))

So once you have your Sonoff on your wifi network, you can connect directly to it and select the “Firmware Upgrade” option


Get the latest Sonoff-Tasmota firmware release here [select the .bin version which is applicable to you, normally just sonoff.bin]

Upload it and wait for the Sonoff to reboot with the latest version.

Great – Now you’re SET !

Next steps:

  1. Connect your Sonoff to the device / devices you want to control & get going !
  2. Integrate into Home Assitant

Have fun ! and Hassio – The best and easiest Home Automation tools to get going !

I’ve played with some home automation stuff on my Raspberry Pi in the past, but setting up the stuff was always a bit involved and I would loose interest somewhere down the line. This meant I’ve always had good intentions, but never really implemented anything (all the work was “proof-of-concept” stuff :-))

Well that has changed in the last couple of days ! 🙂

HomeAssistant-Dashboard,, Sonoff switches (running Tasmota Firmware) and Node-Red changed ALL of that !

What do you need:

  1. Somewhere to run Home Assistant (I used a Raspberry Pi 3)
  2. Install Home Assistant
    1. They have an easy to follow install guide
  3. Once you have Home Assistance installed, you configure to help you manage additions, etc. on Home Assistant
    1. A couple of add-ons I use:
    2. Hassio-Dashboard
      1. Configurator (makes it easy to edit Home Assistant configuration yaml files)
      2. Samba share (to connect to the Raspberry Pi and be able to edit files if the front-end breaks)
      3. SSH Server (if you’re more used to using ssh to connect to your Pi)
      4. TasmoAdmin (used because I make use of Sonoff switches running Tasmota firmware)
      5. Mosquitto Broker (used to communicate with your switches)
      6. Node-Red (Visual Environment for putting “flows” together)
  4. You install all of these add-ons via the Add-On Store
  5. THEN you need some switches
    1. I’m using the Sonoff switches as they’re easy to use and not too expensive
    2. I installed the Tasmota Firmware on them
  6. Adding your Sonoffs to Home Assistant involves some configuration editing (will cover that in a separate post), but once you have it working – it works like a charm !

Have fun !


How to get telnet onto MacOS High Sierra

Sometimes you just want to drop into a terminal window and test some “stuff”.

If you are running MacOS High Sierra (10.13), you may notice that telnet is not available as part of a standard install anymore 😦

Well, the Homebrew guys have come to the rescue and provide an option to install the “missing packages on macOS”.

Head over to for more info.

Basically you have to install Homebrew and then after that you can install other packages.

In terminal, paste the following:

/usr/bin/ruby -e "$(curl -fsSL"

wait for the install to finish (it will download and install the Xcode command-line tools, as well as configure homebrew.)

Once you’ve done this you can install packages like telnet, etc.

For telnet use this command:

brew install telnet

Have fun !

Adding Porn, Fake News and Gambling blocking to PiHole

I’ve been using the RaspberryPi PiHole ad-blocking installation (see my post) quite successfully in our home environment and am very happy with it.

Lately I’ve also looked at adding additional content blocking to the solution to block other content like:

  • Porn
  • Gambling
  • Fake News

I found the following resources for hosts which you can add to your Block Lists in PiHole.

Steven Black’s Lists (multiple – select which one makes sense for you)

Chad Mayfields’ List (post) and actual list

To configure:

  1. Open your PiHole Dashboard and login
  2. Go to Settings -> Block Lists
  3. Add the following to your current lists (PiHole already has ad-blocking lists)
  4. Save and Update

The PiHole installation will pull all the hosts into its configuration and ensure the sites are blocked on a DNS level.

Sample screen of my current configuration


You may find however that some sites are classified as “porn” (i.e., etc.) but this is probably due to some potential content on there which is deemed “close” to porn 🙂

A small price to pay for better piece of mind – although the lists will not block all content (new sites pop up every day), it will help with the majority of the content.

You always have the option to add your own Blacklist sites and I recommend you review the PiHole DNS queries on a regular basis to see any potential additional items to add.

Have fun !

Create a free website or blog at

Up ↑