Skip to content

pilotak/MQTT-relay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MQTT relay

Yet another custom code to control Sonoff and other custom relay boards built around ESP8266 and ESP32.

The main goals are:

  • Universal for Sonoff and other custom maed relay boards with ESP8266 and ESP32
  • All setting is in one file so you have one file for each device but with completely different behaviour
  • Button reading is interrupt based debounce, so you really don't miss a click even with delay used somewhere in code
  • Button has a short press and long press
  • You can define how many relays it has, also what is ON state wheter LOW or HIGH
  • Different modes state LED indication
  • Remember last state during restart
  • Clearly MQTT controlled, ready to be controlled by Home Automation server, like HomeAssistant

In order to compile, you need to install following library

Below are examples of HomeAssistant configuration

Control relay

switch:
  - platform: mqtt
    name: "sonoff_switch"
    command_topic: "sonoff/relay0"
    state_topic: "sonoff/relay0/state"
    payload_on: 'ON'
    payload_off: 'OFF'
    optimistic: false
    qos: 1

Temperature with couple of DS18B20

sensor:
  - platform: mqtt
    state_topic: "sonoff/temp0"
    name: "Tepmerature 1"
    unit_of_measurement: "°C"
  - platform: mqtt
    state_topic: "sonoff/temp1"
    name: "Tepmerature 2"
    unit_of_measurement: "°C"

Temperature and humidity with DHT22/DHT11

sensor:
  - platform: mqtt
    state_topic: "sonoff/temp"
    name: "Tepmerature"
    unit_of_measurement: "°C"
  - platform: mqtt
    state_topic: "sonoff/humidity"
    name: "Humidity"
    unit_of_measurement: "%"