Home-Assistant-4-Channel-Relay-With-Physical-Button-Using-Arduino-and-MQTT
Home-Assistant-4-Channel-Relay-With-Physical-Button-Using-Arduino-and-MQTT copied to clipboard
4 channel relay with physical button control, implemented using Arduino, NodeMCU, MQTT and Home Assistant
Home-Assistant-4-Channel-Relay-With-Physical-Button-Using-Arduino-and-MQTT
4 channel relay with physical button control, implemented using Arduino, NodeMCU, MQTT and Home Assistant.
What it Does?
- 4 Channel Relay control with Home Assistant app/desktop
- If you perform ON/OFF with Physical/Push button switch, the status gets updated on Home Assistant app/desktop
- If Internet is not available, you can still operate Relay with offline physical switch
Requirements
Installation
- Open
secret.hand change Wifi settings, server settings and few other parameters as per your project requirement. - Open
settings.h- Usually you don't need to change any values here, but if you need any customization feel free play with it.
Hardware Connection
NodeMCU to 4 Channel Relay Module Connection
D0 or 16 to IN1 D1 or 5 to IN2 D2 or 4 to IN3 D3 or 0 to IN4 VV to VCC GND to GND
NodeMCU Connection for Switch Actions (NodeMCU to NodeMCU)
D4 or 2 to GND (in NodeMCU) D5 or 14 to GND (in NodeMCU) D6 or 12 to GND (in NodeMCU) D7 or 13 to GND (in NodeMCU)
Home Assistant Configuration
Add in configuration.yaml
homeassistant:
customize:
switch.bed_light:
icon: mdi:ceiling-light
assumed_state: false
switch.backside_light:
icon: mdi:lightbulb
assumed_state: false
switch.front_light:
icon: mdi:lightbulb-outline
assumed_state: false
switch.fan:
icon: mdi:fan
assumed_state: false
switch.room_firmware_update:
assumed_state: false
switch 1:
- platform: mqtt
name: "Bed Light"
state_topic: "/house/room/confirmbedlight/"
command_topic: "/house/room/bedlight/"
payload_on: "1"
payload_off: "0"
optimistic: true
qos: 0
switch 2:
- platform: mqtt
name: "Backside Light"
state_topic: "/house/room/confirmbacksidelight/"
command_topic: "/house/room/backsidelight/"
payload_on: "1"
payload_off: "0"
optimistic: true
qos: 0
switch 3:
- platform: mqtt
name: "Fan"
state_topic: "/house/room/confirmfan/"
command_topic: "/house/room/fan/"
payload_on: "1"
payload_off: "0"
optimistic: true
qos: 0
switch 4:
- platform: mqtt
name: "Front Light"
state_topic: "/house/room/confirmfrontlight/"
command_topic: "/house/room/frontlight/"
payload_on: "1"
payload_off: "0"
optimistic: true
qos: 0
- platform: mqtt
name: "Room Firmware Update"
state_topic: "/house/room/confirmfirmware/"
command_topic: "/house/room/firmware/"
payload_on: "1"
payload_off: "0"
optimistic: true
qos: 0
Add in sensors.yaml
- platform: mqtt
name: "Room Build Number"
state_topic: "/house/room/firmware/confirmbuildnumber/"
value_template: '{{ value_json.buildNumber }}'
Add in groups.yaml
sensors_mqtt_group:
name: Build Number
entities:
- sensor.build_number
Add in automations.yaml
#Add this if you want to use automation #Example code is shown for only 1 switch
- id: TurnOn
alias: Turn On Switch
trigger:
- at: '21:50:00'
platform: time
action:
- entity_id: switch.mqtt_switch_1
service: switch.toggle
Software Setup
- Download and install the Home Assistant App for iOS or Android.
- Download this repo and copy the files in to your sketches directory. Open the sketch in Arduino IDE.
- Go to the
settings.htab. This is where all the customisable settings are. You should be able to change almost everything from there before compiling. - Go to the
secret.htab. Here you change Wifi settings, server settings and few other parameters as per your project requirement.
Screenshot
