ควบคุมอุปกรณ์ในบ้านด้วย home-assistant.io

1.ติดตั้ง (ที่มา : https://home-assistant.io/docs/installation/raspberry-pi/)
sudo apt-get install python3 python3-venv python3-pip
sudo useradd -rm homeassistant
$ cd /srv
$ sudo mkdir homeassistant
$ sudo chown homeassistant:homeassistant homeassistant
$ sudo su -s /bin/bash homeassistant
$ cd /srv/homeassistant
$ python3 -m venv .
$ source bin/activate
(homeassistant) homeassistant@raspberrypi:/srv/homeassistant $ pip3 install homeassistant
(homeassistant) $ hass
2.เข้าใช้งานที่ http://ipaddress:8123
3.ตั้งค่าให้ run เป็น service
$ sudo nano /etc/systemd/system/home-assistant@homeassistant.service
[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=%i
ExecStart=/srv/homeassistant/bin/hass -c "/home/homeassistant/.homeassistant"

[Install]
WantedBy=multi-user.target
$ sudo systemctl enable home-assistant@homeassistant
$ sudo systemctl start home-assistant@homeassistant
sudo journalctl -f -u home-assistant@homeassistant
4.ปรับแต่ง Configuration ซึ่งจะอยู่ที่ /home/homeassistant/.homeassistant/
4.1 ไฟล์ configuration.yaml จะเป็นไฟล์หลัก ดังตัวอย่าง
homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 13.75
  longitude: 100.4833
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 8
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Asia/Bangkok
  # Customization file
  customize: !include customize.yaml

# Show links to resources in log and frontend
#introduction:

# Enables the frontend
frontend:

รูปแบบก็คือ ชื่อ config ต่อด้วยเครื่องหมาย : แล้วเว้นวรรคทีนึง ตามด้วย ค่าของ config
เช่น name: Home
Config ส่วนไหนจะใช้ก็ปล่อยไว้ ถ้าไม่ใช้ก็ใส่เครื่องหมาย # ไว้ด้านหน้า

4.2 เพิ่มเติม Config ส่วนของ MQTT
mqtt:
  broker: 127.0.0.1

4.3 include config อื่น ๆ เช่น
light: !include light.yaml
fan: !include fan.yaml
switch: !include switch.yaml
camera: !include camera.yaml

ตัวอย่างไฟล์ light.yaml
  - platform: mqtt
    name: "Bedroom"
    command_topic: "cmnd/LightBedroom/Power"
    state_topic: "stat/LightBedroom/POWER"

ตัวอย่างไฟล์ camera.yaml
  - platform: mjpeg
    name: Camera TV
    still_image_url: http://192.168.x.x:xxx/image.jpg
    mjpeg_url: http://192.168.x.x:xxx/video/mjpg.cgi
    username: user
    password: xxxxxx


5.Upgrade : (https://home-assistant.io/docs/installation/virtualenv/)
  1. Stop Home Assistant
  2. $ sudo su -s /bin/bash homeassistant
    $ cd /srv/homeassistant
    $ source bin/activate
  3. $ python3 -m pip install --upgrade homeassistant
  4. Start Home Assistant

Comments

Popular posts from this blog

Artillery Hornet + OctoPrint + Klipper

ย้ายบ้าน

ใต้ร่มกาสาวพัตร