Search

Lazy Man Joe's Ramblings

Category

Tasmota

GardenPi โ€“ a garden watering solution built on Raspberry Pi, MQTT and Home-Assistant.io [Part 2/4]

So in GardenPi – PART 1 I covered the hardware & software configs to get going, but that’s not all yet ๐Ÿ™‚

We now have a Raspberry Pi running MQTT and we can switch the GPIO pins by sending messages on the queue.

Next steps:

Connect the pins from GPIO to the relay board

This was fairly easy as the 8 port relay board I used had small pins I could connect directly via small cables from the GPIO pins
As the board also make use of 5V, I used the PWR connector (PIN 2 [5V] and PIN 6 [GND] on the Raspberry Pi) to power the relay board.
I would only be using 1 of the relays at a time, so the power usage will be minimal to draw power directly from the Raspberry Pi.

gardenpi-test-before-boxing.jpg

Make sure MQTT starts at power-on of the Raspberry Pi

To make sure we have a consistent experience, we need to make sure MQTT is started on power-on / reboot of the Raspberry Pi.
I used Supervisor for this as it makes it much easier to set up items which need to start when the Raspberry Pi is restarted.
They cover the configuration of Supervisor in the Pi-MQTT-GPIO setup instructions and I followed it – except I DID NOT set up a virtual environment, as my Raspberry Pi will be dedicated to it’s job.
Basically you install Supervisor;
Then create aย /etc/supervisor/conf.d/pi-mqtt-gpio.conf file with your config information for pi-mqtt-gpio [/home/pi/config.yml].
My pi-mqtt-gpio.conf looks like this:

[program:pi_mqtt_gpio]
command = /usr/bin/python -m pi_mqtt_gpio.server /home/pi/config.yml
directory = /home/pi
redirect_stderr = true
stdout_logfile = /var/log/pi-mqtt-gpio.log

and my config.yml file looks like this:

mqtt:
host: 192.168.xxx.xxx
port: 1883
user: โ€œxxxโ€
password: โ€œxxxโ€
topic_prefix: lazyhome/garden

gpio_modules:
- name: raspberrypi
module: raspberrypi

digital_outputs:
- name: zone1
module: raspberrypi
pin: 5
on_payload: "ON"
off_payload: "OFF"
initial: low

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

- name: zone3
module: raspberrypi
pin: 13
on_payload: "ON"
off_payload: "OFF"
initial: low

- name: zone4
module: raspberrypi
pin: 19
on_payload: "ON"
off_payload: "OFF"
initial: low

digital_inputs:
- 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

- name: zone3
module: raspberrypi
pin: 13
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone4
module: raspberrypi
pin: 19
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

4 Zones, each with settings for digital_output and digital_input.

OK – so now hardware connected and Raspberry Pi will start the PI-MQTT-GPIO listener on power-up / reboot.

Connecting the sprinklers

As I was basically replacing the controller for the sprinklers I already had in the garden, all I did was connect each of the Zones’ solenoids/valves to the relay board.
It’s fairly straightforward as you just have to remember the relay is a switch and you need to see whether you’re going to use the “Normally Open” [NO] or “Normally Closed” [NC] side of the relay. (Normally Open would mean that the switch is NOT switched on by default and when you trigger the relay, it will close the circuit; i.e. switch things ON – for Normally Closed it’s the other way round ๐Ÿ™‚ )
I used “Normally Open” side of the relay as I wanted the Raspberry Pi to actually switch the solenoid on, which will open the valve and let the water through.
The solenoids make use of 24V AC and I already had a transformer to power them – so re-used that.

rainbird_hv

End result was enclosing the Raspberry Pi and relay board in a small housing, connected to the sprinklers in the garden.

GardenPi-Endresult

Next part we go to Home-Assistant to set up & config.

Advertisements

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.

30A-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]

DB-board

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)

HA-Switches

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:

GeyserFlow

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 ๐Ÿ™‚

Over-ride:

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.

dual2

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 (./sonota.py)
  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

Tasmota-Upgrade

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 !

Home-Assistant.io 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

Home-Assistant.io, Hass.io, 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 Hass.io 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 Hass.io 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 !

 

Create a free website or blog at WordPress.com.

Up ↑