Automate Dyson Pure Cool Link with Home Assistant and Fibaro Motion Sensor

habridgefibaro26

Has been a while I’m automated my house and office. Recently I’ve bumped into Home-Assistant which blew my mind away!  There are thousands of components available for install. one of it is Dyson fan, which is running on MQTT protocol.

The result was cool, You can now automate it to function accordingly to your lifestyle. E.g. turned it on when you sit on your working desk or turned it off the next minute after you walk away from your desk and etc.

How far can it go? is it limit by your imagination.

Let’s build one!

The components I used as below

  1.  Home Assistant installed, preferably with the latest firmware. In my case, I install on Raspberry Pi 3 (Getting started with Home Assistant on Raspberry Pi 3)
  2.  Dyson Pure Cool Link
  3.  Apache Server running on the same box as Home Assistant but on port 8088
  4.  Fibaro Home Center 2 (Optional, you can use another brand of the gateway)
  5.  Fibaro Motion Sensor (Optional, you can use another brand of the motion sensor)

Setting up the Home Assistant

  1. We start by retrieving the IP of the fan using nmap from the raspberry pi. In my case, the IP is 192.168.1.113 and 192.168.1.115
    nmap -p 1883 192.168.1.0/24 --open

    habridgefibaro8

  2. To enable the component in Home Assistant
    sudo nano /home/homeassistant/.homeassistant/configuration.yaml
    
    # Add the following line in configuration.yaml
    dyson:
     username: your@email.com
     password: password4DysonLogin
     language: GB
     devices:
     - device_id: NM5-XX-HHHHHHHH
     device_ip: 192.168.1.113
     - device_id: NM5-ZZ-HHHHHHHH
     device_ip: 192.168.1.119
  3. Save the configuration.yaml and restart Home Assistant.
     sudo systemctl restart home-assistant@homeassistant && sudo journalctl -f -u home-assistant@homeassistant
  4. Access your Home Assistant http://home-asistant-ip:8123. You should be able to see the following group after successfully restart (Please check your username and password if device not show). In my case, I have 2 fans.
    habridgefibaro9One of the cool things is, now you can see the following details of your fan without the need to login to Dyson application
    habridgefibaro10.png
  5. Group all Dyson fan together. As you can see, the dashboard is quite messy. I would prefer to move all Dyson Fan related details to a new group.habridgefibaro11First, click the state icon, and scroll down to locate for all sensor.purifier.* entities.
    habridgefibaro12.pngEdit groups.yaml file

    nano /home/homeassistant/.homeassistant/groups.yaml

    Insert the entities into the file and restart Home Assistant service
    habridgefibaro13

    sudo systemctl restart home-assistant@homeassistant && sudo journalctl -f -u home-assistant@homeassistant

    Cleaner view and better information display
    habridgefibaro14

    You also can locate the history of your room information base on the timeline, I find it quite cool!
    habridgefibaro25

Test the system

Great! the show is just about to begin, you might be curious how to toggle other function e.g. speed and oscillation.

habridgefibaro15

To set the fan speed you can either do it from Home Assistant’s States menu
habridgefibaro16.png
or by using curl,
Note: you need to replace all purifier_living_room to your own fan name which can be found from the Home Assistant’s States tab.

curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room","speed":8}' http://localhost:8123/api/services/fan/set_speed

Set oscillation
Set oscillation true

curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room","oscillating":true}' http://localhost:8123/api/services/fan/oscillate

Set oscillation false

curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room","oscillating":false}' http://localhost:8123/api/services/fan/oscillate

Turn on/off the fan
Turn on

curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room"}' http://localhost:8123/api/services/fan/turn_on

Turn off

curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room"}' http://localhost:8123/api/services/fan/turn_off

Setup Apache server

The architecture of the whole setup is to allow any other services which can do HTTP call to have access to the fan (locally only, I don’t open this to the internet).

You also can create a scene e.g. turn on the fan, set speed and set the oscillation in one HTTP call. I will share how I achieve this in later part.

habridgefibaro18

  1. To setup Apache server in Raspberry Pi, you can refer to this tutorial by Ste Wright.
  2. Change default apache port from 80 to 8080, the reason is that I installed HA Bridge in the same box and it occupied port 80.
    sudo nano /etc/apache2/ports.conf 
    
    

    change the Listen from 80 to 8080
    habridgefibaro19

    Next, we need to edit 000-default.conf

     nano  /etc/apache2/sites-enabled/000-default.conf

    change port 80 to 8080, then save and exit.
    habridgefibaro20

    Reload apache service

     sudo /etc/init.d/apache2 reload
  3. Create an actions.php file to allow HTTP call.
    sudo nano /var/www/html/actions.php

    Copy and paste the content line by line the into actions.php file.

     /dev/null 2>/dev/nul$
     echo "Action triggered $message Done"
    ?-->
    
  4.  Create a script actions.sh
    sudo mkdir /var/scripts/
    sudo nano /var/scripts/actions.sh
  5. Copy and paste line by line from below script into actions.sh
    Note: you need to replace all purifier_living_room to your own fan name which can be found from the Home Assistant’s States tab.

     /dev/null 2>/dev/nul$
    echo "Action triggered $message Done"
    ?-->
    
    if [ "$1" == "lfanon" ]
     then
     
     echo "Turning living room fan on, set speed 8 and oscillate = true"
     
     curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room"}' http://localhost:8123/api/services/fan/turn_on
     
     sleep 0.5
    
    curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room","speed":8}' http://localhost:8123/api/services/fan/set_speed
    
    sleep 0.5
    
    curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room","oscillating":true}' http://localhost:8123/api/services/fan/oscillate
    
    elif [ $1 == "lfanoff" ]
     
     echo "Turning living room fan off"
     curl -X POST -H "x-ha-access: " -H "Content-Type: application/json" -d '{"entity_id": "fan.purifier_living_room"}' http://localhost:8123/api/services/fan/turn_off
    
    fi
  6. You need to give executable permission to actions.sh. Because I run this on my local only so I give the following permissions. Please give the script better restriction according to your environment.
     chmod 777 /var/scripts/actions.sh
  7. Test the web call from any web browser within the same network.
    The “lfanon” value will trigger the following actions.
    a. Turn on the fan
    b. Set speed 8
    c. Set oscillate = true

    http://home-assistant-ip:8080/actions.php?message=lfanon
    or 
    http://home-assistant-ip:8080/actions.php?message=lfanoff

Integration with Fibaro Home Center 2

Here comes the exciting part, I will show you how to create a virtual device and a scene to turn on the fan when motion detected and a scene to stop the fan after 2 minutes ( you can adjust according to your preference) after no more motion.

  1. Create a virtual device show as below
    habridgefibaro21.png
  2. Insert below script for the 2 buttons, IP = IP address of your Home Assistant
    habridgefibaro22.png
  3. Turn on fan scene
    habridgefibaro23
  4. Turn of fan scene
    habridgefibaro24.pngThat it! Let’s see the end result at below video.

 

4 thoughts on “Automate Dyson Pure Cool Link with Home Assistant and Fibaro Motion Sensor

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s