Continued from PART 2

With all the puzzle pieces in place, now we can make Home-Assistant aware of the Garden Zone “switches”, so we can program and use the in automations.

In the switches.yaml file (remember I split the configuration for switches out into their own file), under the platform: mqtt section I added the Garden Zones / Switches:

[code]
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

[/code]

You can name the switch anything you want, as this will be the user-friendly name in the Home-Assistant homepage.
The important bits are the command_topic and state_topic sections – these need to align to the configuration you have on your Raspberry Pi with it’s mqtt listener.

I also created some “Groups” (groups.yaml) for Home Assistant to group my different switches into logical sections:

[code]
Geysers:
name: Geysers
entities:
– switch.bedroom_geyser
– switch.upstairs_geyser
Garden:
name: Garden
entities:
– switch.Garden_Zone_1
– switch.Garden_Zone_2
– switch.Garden_Zone_3
– switch.Garden_Zone_4

[/code]

Please note that the switches have “_” to replace the spaces in the names

After updating the configuration, restart HASS and your switches should show up in it’s own group 🙂

GardenPI_Zones

And that’s it !

Home Assistant is now aware of the switches AND you can switch them using the on-screen toggles (which kicks off some mqtt messages in the background, which the Raspberry Pi picks up, switching the relevant GPIO pin, which in turn switches the relay !)

Phew !

😀