EDIT: There is a custom_component linked toward the end of this thread that works better than the original solution I posted below.
I installed one of these in my house and integrated it into HASS. I’ll tell you about the HASS integration part. The installation part is a handyman thing so I’ll skip that.
The first issue was to determine how the electronics in the fan worked so I could determine how I’d control it. The fan has 4 wires. Hot/Neutral and two more hots (one for high and one for low). In order for the fan to turn on 3 (and only 3) of the 4 wires have to be energized, power and a high/low.
Figuring the wiring out now created a problem because most home-automated switches aren’t SPDT. They are SPST and in order to control the high/low, a SPDT switch would be the simplest solution. (Note: Standard house 3 way switches are SPDT). I considered using two SPST switches and an SPDT relay but decided against it. Researching my options and costs and how much time… Sonoff + relays would be the cheapest but if someone wanted to change the fan if I moved out, they probably wouldn’t understand. I looked at the manufacture’s Wifi controller which was the most expensive but the easiest to wire and seemed to be more future-proof for other people. So, I ordered the QuietCool Wifi controller because I found someone figured out the CoAP protocol it uses and had some code published. (There isn’t a supported API which sucks).
I took the code here: https://github.com/stabbylambda/quietcool
I couldn’t figure out what to do with the node/javascript stuff so I contacted David. He was a major help and put some code snips together that I turned into a usable script. The script has the UID if the fan and the controller IP. I’m not sure how I figured out the UID. I just added some log statements to his quietcool-cli and stumbled on it.
I then added some configs to HASS and a quick appdaemon script and I had a fan I could control from HASS!
The last step is to automate it based on temperature and what doors and windows are open but that’s the easy part.
node script (quietcool.js):
// Call this like: node /opt/scripts/quietcool.js off
const fan = require('/usr/lib/node_modules/quietcool');
//const fan = require('quietcool');
const util = require('util')
const fanId = { uid: '<fan UID here>', ip: 'x.x.x.x' }
var myparam = process.argv[2].toUpperCase()
console.log(myparam);
if (myparam == "HIGH" ) {
fan.setCurrentSpeed(fanId, "3")
.flatMap(x => fan.turnFanOn(fanId))
.subscribe(x => console.log(x));
}
if (myparam == "LOW" ) {
fan.setCurrentSpeed(fanId, "1")
.flatMap(x => fan.turnFanOn(fanId))
.subscribe(x => console.log(x));
}
if (myparam == "OFF" ) {
fan.turnFanOff(fanId).subscribe(x => console.log(x));
}
HASS Config:
input_select:
house_fan:
options:
- "OFF"
- "HIGH"
- "LOW"
icon: mdi:fan
AppDaemon script:
import appdaemon.plugins.hass.hassapi as hass
import subprocess
class QuietCool(hass.Hass):
def initialize(self):
self.log("QuietCool")
self.listen_state(self.select_change, "input_select.house_fan")
def select_change(self, entity, attribute, old, new, kwargs):
self.log("select_change")
self.log(new.upper())
cmd = ['node','/opt/scripts/quietcool.js',new.upper()]
returncode = subprocess.call(cmd)