Skip to content

Commit

Permalink
Merge pull request #29 from karlkar/master
Browse files Browse the repository at this point in the history
Decouple project
  • Loading branch information
deiger authored Oct 13, 2020
2 parents eba31d2 + 9e628ee commit 044375d
Show file tree
Hide file tree
Showing 17 changed files with 1,271 additions and 1,866 deletions.
103 changes: 103 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

.vscode/*

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ The module is installed in A/Cs and humidifiers that are either manufactured or

1. Air Conditioner with HiSense AEH-W4B1 or AEH-W4E1 installed.
1. Have Python 3.7 installed. If using Raspberry Pi, either upgrade to Raspbian Buster, or manually install it in Raspbian Stretch.
1. Install additional libraries:
1. Download and install aircon module:
```bash
pip3.7 install dataclasses_json paho-mqtt pycryptodome retry
python3.7 setup.py install
```
1. Configure the A/C with the dedicated app. Links to each app are available in the table below. Log into the app, associate the A/C and connect it to the network, as described in the app documentation.
1. Once everything has been configured, the A/C can be blocked from connecting to the internet, as it will no longer be needed. Set it a static IP address in the router, and write it down.
1. Download and run [query_cli.py](query_cli.py), to fetch the LAN keys that will allow connecting to the A/C. Pass it your login credentials, as well as the code for your app from the list below:
1. Run discovery command to fetch the LAN keys that will allow connecting to the A/C. Pass it your login credentials, as well as the code for your app from the list below:

| Code | App Name | App link
|------------|---------------------|---------|
Expand All @@ -43,17 +43,20 @@ The module is installed in A/Cs and humidifiers that are either manufactured or

For example:
```bash
./query_cli.py --user foo@example.com --passwd my_pass --app tornado-us --config config.json
python3.7 -m aircon discovery tornado-us foo@example.com my_pass
```
The CLI will generate a config file, that needs to be passed to the A/C control server below.
If you have more than one A/C that you would like to control, create a separate config file for each A/C, and run a separate control process. You can select the A/C that the config is generated for by setting the `--device` flag to the device name you configured in the app.

## Run the A/C control server

1. Download [hisense.py](hisense.py).
1. Download and install aircon module:
```bash
python3.7 setup.py install
```
1. Test out that you can run the server, e.g.:
```bash
./hisense.py --port 8888 --ip 10.0.0.40 --config config.json --mqtt_host localhost
python3.7 -m aircon run --port 8888 --ip 10.0.0.40 --config config.json --mqtt_host localhost
```
Parameters:
- `--port` or `-p` - Port for the web server.
Expand All @@ -77,13 +80,14 @@ The module is installed in A/Cs and humidifiers that are either manufactured or
curl -ik 'http://localhost:8888/hisense/command?property=t_power&value=ON'
```
## Run as a service
Assuming your username is "pi"

1. Create a dedicated directory for the script files, and move the files to it.
Pass the ownership to root. e.g.:
```bash
sudo mkdir /usr/lib/hisense
sudo mv hisense.py config.json /usr/lib/hisense
sudo chown root:root /usr/lib/hisense/*
sudo mv config.json /usr/lib/hisense
sudo chown pi:pi /usr/lib/hisense/*
```
1. Create a service configuration file (as root), e.g. `/lib/systemd/system/hisense.service`:
```INI
Expand All @@ -92,11 +96,12 @@ The module is installed in A/Cs and humidifiers that are either manufactured or
After=network.target

[Service]
ExecStart=/usr/bin/python3.7 -u hisense.py --port 8888 --ip 10.0.0.40 --config config.json --mqtt_host localhost
ExecStart=/usr/bin/python3.7 -m aircon run --port 8888 --ip 10.0.0.40 --config config.json --mqtt_host localhost
WorkingDirectory=/usr/lib/hisense
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target
Expand Down Expand Up @@ -166,13 +171,8 @@ Listed here are the properties available through the API:

## Multiple Air Conditioners

The server script supports a single Air Conditioner. In order to use with multiple Air Conditioners, a separate instance of the server needs to run for each Air Conditioner.

This includes:
- Create a separate config file for each A/C. Do mind that you select the correct device when running the CLI.
- Select a different `--port` for the HTTP server of each A/C.
- If using MQTT, select a different `--mqtt_topic` for each A/C.
- Create a different service file, that refers to the settings above.
In order to use with multiple Air Conditioners, simply add multiple --config and --type params.
MQTT topic will contain your topic defined by flag --mqtt_topic (hisense_ac by default) and device name.

* Note: _The smart home hub configuration should adjusted to refer to the right port or topics._

Expand Down
2 changes: 2 additions & 0 deletions aircon/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import *
__version__ = '0.0.1'
Loading

0 comments on commit 044375d

Please sign in to comment.