ayatec logo
Home Store Blog Contact
unicontrol user guide by ayatec
Home Store Blog Contact

Topics

  1. Welcome
  2. Getting started
    1. What is unicontrol
    2. How it works
    3. Connectivity
    4. Integration options
    5. Default hardware
    6. Hardware extensions
    7. Special sensors
    8. RGB driver
    9. Audio driver
    10. Network API - HTTP
    11. Network API - MQTT
    12. Network security
    13. Downloads
  3. Web Interface
    1. Processes
      1. Process
      2. Name
      3. Main state
      4. Initial state
      5. Display
      6. Constraints
        1. Process timer
        2. Variable contraints
        3. Force output
      7. Input
        1. Input source
        2. Channel
        3. Control period
        4. Value
        5. Publish
        6. Frequency
        7. Subtopic
      8. Events
        1. On/Off event
        2. Condition
        3. Idle/running time
        4. Delay on/off
        5. Fade in/out
        6. High/low input
        7. Mid point/Tolerance
        8. Out on when
      9. Output
        1. Primary output
        2. Action
        3. Type
        4. Invert
        5. Duty cycle
        6. Mem value
        7. High/low output
        8. Folder/Track
        9. RGB mode
        10. RGB color
        11. RGB brightness
        12. RGB speed
        13. Publish
        14. Subtopic
        15. Secondary outputs
      10. Cycle
        1. Cycles
        2. High/Low phase
      11. On/Off button
    2. Peripheral
      1. Hardware
      2. Type
      3. Calibration
      4. Mapping (edit)
      5. IR remote (edit)
      6. Impulse_counter (edit)
      7. RGB driver (edit)
      8. DS18B20 (edit)
    3. Device
    4. Network
    5. System
    6. License
  4. Tutorials
    1. First boot
    2. First process
    3. Connect to MQTT
    4. Process sequencing

    5. DIY Project: Bath Fan

In this article

  • Introduction
advert
unicontrol > Tutorials > DIY Project: Bath Fan

DIY Project: Bath Fan

Bathroom ceiling fan
Original bathroom fan

The first problem in home automation that I'll address in this DIY series is my bathroom vent fan, which has been irritating me for some time. So far, it has had a traditional setup (at least traditional in my region), where the fan operation is directly bound to the ceiling light switch, with the 230V power supply to the ceiling light serving as the raw signal for the fan to turn on or off. This is often done to overcome a lack of the separate fan switch, but it comes at the cost of very little flexibility. Of course, the user may choose if it should run while the lights are on or turn on once they are turned off together with the run-time, but once the choice is made, the behavior is strictly given. This implies that regardless of the choice, the fan would often run unnecessarily, consuming power and bothering the inhabitants for no good reason. On the other hand, it would often not run when needed, thus failing to do its only job.

Luckilly, this is an easy problem to solve with unicontrol. With its help, I can set the fan permanently to its most basic run mode (run when the signal power is on and vice versa) and fully control it with a remotely operated relay.

Design

Now that the problem has been identified and the necessary tools selected, it's time to design a solution. Although the unicontrol can operate the fan through MQTT and HTTP commands sent from a smartphone, it's not the most convenient option. I have an IR remote for the ceiling light lying around in the bathroom that can be used to control the fan (thanks to the built-in IR remote support), making it a more practical solution. Additionally, since the ESP8266 will already be in place to enhance the fan's capabilities, why not take it a step further? By adding a cheap DHT11 sensor, the fan can automatically run when the temperature or humidity exceeds a set threshold for a specific amount of time. With this, we'll have much greater control over the fan's functions. All of the above-mentioned features can be achieved with the following scheme:

Modification scheme
Scheme of planed modifications
Please be aware that this tutorial involves working with 230V AC electricity. Ensure that you follow all relevant safety precautions, or consider having a professional handle the critical steps.

Components

All the components required for the project, according to the scheme above, can be obtained from third-party vendors or printed at home (unicase). Here's an overview of the required components and their price estimates:

Components
Components overview
Item Pcs Unit price (€)
ayatec unicontrol mini18.40
ayatec unicase mini1
ESP8266 WeMos D1 mini12 - 5
5V 1A Power Supply14 - 6
D1 mini Relay Shield12 - 5
DHT11 11 - 3
1838 Universal IR Receiver 10.50 - 1
Prototype Circuit Board 7x5 cm10.20 - 0.5
PCB Terminal Block Connector - 3 pins20.50 - 1
PCB Terminal Block Connector - 2 pins20.50 - 1
10K Ohm Resistor1< 0.10
100 Ohm Resistor1< 0.10
Tactile Push Button1< 0.10
Heat-Shrink Tubing1< 0.10
Scrap Wires/Cables

The total estimated cost of the components ranges from €25 to €30. However, purchasing the items in smaller bulks instead of single pieces can reduce the total cost to below €25.

Device assembly

The initial populating of components, as per the provided scheme, is shown in the following photos (the Relay shield and WeMos D1 mini are not included at this stage). Please pay attention to the highlighted sections for a complete understanding of the wiring.

Wiring done Highlighted back-side solder Bottom view Bottom view highlighted
Initial assembly and wiring.

Once the Relay shield and WeMos D1 mini are added, the board assembly will be complete and can be directly fitted into the unicase:

PCB is now complete PCB is now complete Device is now assembled and peripherals connected Device is now assembled and peripherals connected Fan is dismantled and unicontrol ready to be installed unicontrol ready for tests
Completed assembly and installation

Set-up

After connecting all sensors (the relay is already hardwired) and performing the initial installation and First boot, it's time to set up the unicontrol itself. The first step is to ensure that the connected Hardware is properly defined. To do this, navigate to the Peripherals menu and select the following in line with the scheme:

  • IN - DHT11 for D2
  • OUT - General for D5
  • IN - 1838 IR for D7
Peripherals menu
Web interface - Peripherals

After making these selections, clicking Save will immediately take effect. The temperature and humidity readings will appear next to the D2 section and the Edit button will appear in the D7 section. Clicking this button will navigate to the IR remote (edit) where the step will take place. Using this editor, I am going to teach the program which remote code will be used to operate the relay. In my case, I will only use a single Auxiliary button on my remote, so I will undergo the learning procedure with Aux as the Name and the Channel left at 0. After the procedure is complete, the newly learned code will appear in the table as shown below:

IR Remote edit menu
Web interface - IR edit

With the hardware fully set up, the next step is to configure the processes. The first two processes will only take care of publishing the DHT11 readings to the MQTT broker, so no outputs, events, or constraints are applicable.

Process 1:
  • Name: Temperature
  • Main state: Auto
  • Input source: D2
  • Channel: 0
  • Publish (input): Allowed
  • Frequency: 5 minutes
  • Subtopic (input): Use Name
Process 2:

Same as Process 1 except:

  • Name: Humidity
  • Channel: 1
Process 1 Process 2
Web interface - Process 1 & 2

The next two processes will operate the fan so that it can be turned OFF either manually (using the same remote or via MQTT or HTTP command) or after a predefined period of time. Process 3 will switch the relay on the D5 pin ON and OFF on each IR remote Aux button press. When turning on, it will also trigger the timer on Process 4. Each state change will be published to the MQTT broker.

Process 3:
  • Name: Vent
  • Main state: Auto
  • Input source: D7
  • Channel: 0
  • On event: Rising edge
  • Off event: Rising edge
  • Output: D5
  • Publish (output): Allowed
  • Subtopic (output): Use Name
  • Secondary output 1: (Process) 4: Vent_timer / On -> On

Process 4, after being triggered by Process 3, will measure the time for which the relay assigned to the Process 3 is ON and will automatically turn it OFF when the predefined period ends.

Process 4:
  • Name: Vent_timer
  • Main state: Auto
  • Off event: Timeout
  • Running time: 10 Min
  • Secondary output 1: (Process) 3: Vent / Off -> Off
Process 3 Process 4
Web interface - Process 3 & 4

The last thing to address is MQTT set-up. Although it is not necessary for the intended IR remote control, it enhances the capabilities with little-to-no effort. For test purposes, I will now modify the MQTT settings as follows:

  • Connection: Enabled
  • IPv4: 3.228.54.173
  • Topic Level 1: johndoe5896
  • Topic Level 2: home
  • Topic Level 3: bathvent
MQTT settings
Web interface - MQTT settings

After making these changes and performing a precautionary reset, the device should now be fully up and running.

Testing

Never forget to test both the hardware and software thoroughly before putting everything back together. Especially the cheaper DHT11 sensors are not really known for their reliability so I am typically letting them run for a week or two before installing them permanently, especially if it would be time-consuming to replace a faulty one.

This time the DHT11 turned out fine, but I was forced to replace my cheap 5V power supply for a more stable one as it was interfering with the 1838 signal. With the new one in place the received signals became clean and reliable.

Simulating all possible scenarios and checking that the process set-up is working as intended is also good practice. Similarly, it can be helpful to monitor the serial port during testing as it makes debugging much easier. For example, pressing the Aux button on the remote will result in the following series of events visible on the PuTTY console below:

  1. The Aux signal was received.
  2. Process 3 recorded a Rising edge.
  3. The Rising edge on Process 3 was immediately acknowledged thanks to the 0 in the Control period, and wrote HIGH to D5 (fan).
  4. At the same time, it turned ON the Secondary output 1 (Process 4), starting its 10-minute Timeout.
  5. After 10 minutes, the Timeout on Process 4 elapsed and turned ON the D5 (fan).
Serial port console screenshot
Serial port after pressing the correct remote button

After passing all the tests, the fan could be finally assembled. I chose a neat location for the DHT11 right next to the fan's original side ventilation opening. The 1838 sensor found its place right above the indicator light bulb's "visor".

It took some playing and fidgeting to position the 1838 sensor properly within the fan's lid (courtesy of a really tiny visor), but I ended up with reliable feedback from almost all possible angles.
Fan installed with addition of DHT11 and 1838 IR sensors
Testing and installation finalized

MQTT Dashboard

To complete my small ecosystem, I will also create an MQTT dashboard that will allow me to monitor the technical status of the device, readings, and turn the fan ON or OFF if needed while I am away. In total, I have defined the following panels:

Fan control in the MQTT dashboard
Control dashboard on a smartphone
  • Temperature: subscribed to johndoe5896/home/bathvent/​​​​​pub/Temperature/input
  • Humidity: subscribed to johndoe5896/home/bathvent/​​​​​pub/Humidity/input
  • Local IP: subscribed to johndoe5896/home/bathvent/​​​​​pub/ip
  • Online indicator: subscribed to johndoe5896/home/bathvent/​​​​​pub/conn
  • ON: publish 1 to johndoe5896/home/bathvent/​​​​​sub/Vent/outset
  • OFF: publish 0 to johndoe5896/home/bathvent/​​​​​sub/Vent/outset
  • RESET: publish 1 to johndoe5896/home/bathvent/​​​​​sub/reboot

Recording telemetry on the same MQTT topics for Temperature and Humidity using Node-RED will then look like this:

Telemetry chart
Telemetry chart

Further improvements

Furthermore, there are plenty of options to further enhance the current set-up by defining additional processes in order to:

  • Bypass the timer so that the fan runs until turned OFF by the user.
  • Run the fan for different time periods based on which button was pressed.
  • Turn ON the fan automatically if the humidity or temperature is above the user-defined threshold for a certain period of time.
  • Run the fan automatically in certain times of the day.
  • Automatically reset the device on a regular basis to improve stability.
Please note that adding more processes will require a unicontrol option higher than mini.
© 2024 ayatec.eu • Found a mistake?  Let us know!