Home Assistant Synology Setup#
Docker Method#
- Create a config folder. Default: /volume___/docker/home_assistant
- Download home assistant container
- Expose port 8123 to 8123
- Mount /volume___/docker/home_assistant to /config
- Enable websocket
VM Method#
See ZHA. Note, it is more difficult to access files and folders in HA running on VM. However, you get add-on access which is useful for adding community packages.
Configuration#
To enable remote access
homeassistant:
external_url: "https://homeassistant.syn.teojy.com"
internal_url: "http://192.168.1.xxx:8123" #IP of VM
http:
use_x_forwarded_for: true
trusted_proxies:
- 192.168.1.xxx #IP of synology
- 127.0.0.1 #Localhost
Understanding entities, devices, helpers, automation#
Tuya Integration#
Local Tuya#
Local Tuya skips the dependency on china server.
- Repo
- Get Mac address from smart life app, look for ip in router
- Get id and keys
Enable power monitoring for WiFi on local Tuya#
- Add multiple entities for all the available ids on the device.
- Check to see which entity values change. Those would likely correspond to the current, power and voltage readings. Apply the appropriate scaling and units.
Timer#
Enable telegram#
This guide will focus on sending data from home assistant to telegram (link). It will not include details on how to control home assistant using a telegram bot (link). * Guide 1 * Guide 2
homeassistant: # Combine with existing homeassistant section
- /config/videos
media_dirs:
media: /config/videos
# Example configuration.yaml entry for the Telegram Bot
telegram_bot:
- platform: polling
api_key: xxxxxxxxxxxxxxxxx
allowed_chat_ids:
- xxxxxxxxxxxxxxxxx
# Example configuration.yaml entry for the notifier
notify:
- platform: telegram
api_key: xxxxxxxxxxxxxxxxxx
name: HA2TLG
chat_id: xxxxxxxxxxxxxxxxxxx
folder_watcher:
- folder: /config/videos
To send a video via notify.ha2tlg service, create a script. Note that the video should be stored in a folder in config as HA (VM edition) cannot access videos in folders outside of /config
.
service: notify.ha2tlg
data:
message: Video created on {{ now().strftime("%Y%m%d-%H%M%S") }}.
data:
video:
- file: /config/videos/video_doorbell.mp4
caption: Video created on {{ now().strftime("%Y%m%d-%H%M%S") }}
Template coding#
TBD
Zigbee Home Assistant (ZHA)#
Setting up on Synology#
- DSM7 no longer recognizes zigbee dongles automatically. Requires loading the kernel manually
- On reboot, the /dev id of the dongle might change, breaking the connection between zha and the dongle.
- Try installing home assistant as a virtual machine instead of a docker. link
Install virtual machine#
- On DS418play+, download VMM online and install manually. Next, enable OVS, which is disabled by defauly on DS418.
- To enable OVS,
vi /ect/synoinfo.conf
and add/change the linesupport_ovs='yes'
. link
- To enable OVS,
- Enable usb2.0 or 3.0 in the VM. Mount 'silicon labs cp210x ...'
- Under HA > Configuration > Integration, add ZHA. It should fine the zigbee dongle under ttyUSB0
Adding New Devices#
- To go HA > Developer tools > Services and run
zha.permit
. It should find devices automatically. - The other method of adding devices as a children of an existing zigbee doesn't work. Maybe it works with non-router devices only...
Zigbee2MQTT#
Rationale#
Instead of placing all your eggs in one basket, it is prudent to split the zigbee network off from synology home assistant and use a standalone server made from raspberrypi. That way, if either fails, it won't affect the other. Think of it as using a dedicated zigbee hub but with the ability to link it to homeassistant easily (unlike propietary zigbee hubs or amazon echo) However, unlike ZHA, Zigbee2MQTT's setup is slightly more involved and not for the faint of heart.
(Update 04/2023) raspberrypi is too unstable. Use home server instead. Install mosquitto. Run zigbee2mqtt via docker.
Setup#
- Get Raspberry Pi and load raspbian (raspberry official debian-based sofware) on a 16gb microsd card.
- Connect a wifi dongle for wireless access or ethernet cable for lan access
- Connect Sonoff zigbee dongle flased with coordinator software. Locate the dongle using
sudo dmesg
, it should usually be/dev/ttyUSB0
. - Connect an additional microsd using a reader for backup purposes.
- Install mosquito. link
Linux Installation#
Once done, follow the instructions on the zigbee2MQTT site. 1. Install zigbee2MQTT (Linux version) * Alternatively, for docker installation, set up docker using this guide. Be sure to use the convenience scripts as normal docker installation won't work on rpi.
Docker Installation#
To enable the frontend, add the following lines to the configuration.yaml
file. The frontend page can then be accessed at xxx.xxx.x.x:8080 using the browser.
sudo docker run \
--name ZIGB2MQTT \
-itd \
--device=/dev/ttyUSB0 \
-v $HOME/zigbee2mqtt/config:/app/data \
-v /run/udev:/run/udev:ro \
-e TZ=Asia/Singapore \
-p 8080:8080 \
--restart unless-stopped \
koenkk/zigbee2mqtt
Frontend#
frontend:
# Optional, default 8080
port: 8080
# Optional, default 0.0.0.0
host: 0.0.0.0
# Optional, enables authentication, disabled by default
auth_token: your-secret-token
# Optional, url on which the frontend can be reached, currently only used for the Home Assistant device configuration page
url: 'https://zigbee2mqtt.myhouse.org'
Backup#
Set up a cronjob that rsyncs the /opt/zigbee2mqtt
folder to the additional microsd card.
Connect to home assistant#
- Enable home assistant config on zigbee2MQTT
configuration.yaml
. - Add MQTT integration on home assistant using the ip address of the raspberry pi. The devices and entities should be added automatically.
Sample configuration.yaml file#
homeassistant: true
advanced:
# Optional: Home Assistant discovery topic (default: shown below)
homeassistant_discovery_topic: 'homeassistant'
# Optional: Home Assistant status topic (default: shown below)
homeassistant_status_topic: 'homeassistant/status'
# Optional: Home Assistant legacy entity attributes, (default: shown below), when enabled:
# Zigbee2MQTT will send additional states as attributes with each entity. For example,
# A temperature & humidity sensor will have 2 entities for the temperature and
# humidity, with this setting enabled both entities will also have
# an temperature and humidity attribute.
# Note: Disabling this option, requires a Home Assistant restart
homeassistant_legacy_entity_attributes: true
# Optional: Home Assistant legacy triggers (default: shown below), when enabled:
# - Zigbee2mqt will send an empty 'action' or 'click' after one has been send
# - A 'sensor_action' and 'sensor_click' will be discoverd
homeassistant_legacy_triggers: true
permit_join: true
mqtt:
base_topic: zigbee2mqtt
server: mqtt://172.17.0.1
serial:
port: /dev/ttyUSB0
frontend:
port: 8080
host: 0.0.0.0
auth_token: your-secret-token
url: https://zigbee2mqtt.myhouse.org
advanced:
homeassistant_legacy_entity_attributes: false
legacy_api: false
device_options:
legacy: false
Setting Up Camera#
TP-Link C210#
https://www.tp-link.com/us/support/faq/2748/
Eufy Doorbell 2K#
# Unpack App
java -jar apktool_2.5.0.jar d 'Eufy_Security_v3.5.1_1159.apk' -o EufySecurity
# Package App
java -jar apktool_2.5.0.jar b EufySecurity --use-aapt2
# Sign App
java -jar uber-apk-signer-1.2.1.jar --apks EufySecurity/dist
Notes#
- Use apktool_2.5.0 for version v3.5.1 of EufySecurity app. Otherwise, it may cause a node.stack error. The easiest way to test if the apktool is of the correct version is to unpack and recompile the apk and check for errors.
- Use
grep -r "Lcom/eufy/security/doorbell/setting/ui/activity/BDBSettingActivity"
to find the file containing the code that needs to be changed. It might change from smali_classes2 to smali_classes3 etc. - Check links folder for the signed copy of the app. (Eufy_Security_v3.5.1_1159-aligned-debugSigned.apk)
Set up doorbell#
- Enable RTSP on the doorbell via the modified app. See notes.
- Add doorbell via the eufy security integration.
- Follow the instructions to add the homebase ip which will automatically add all other linked cameras.
- Add the video feed using generic camera. The ip should be something like 192.168.1.xxx/live0.
- To add local image, refer to the guide.
- Here's an example of the code in
configuration.yaml
.camera: - platform: generic name: Doorbell_RSTP still_image_url: http://127.0.0.1:8123/local/camera.jpg stream_source: rtsp://192.168.1.xxx/live0
- For automation, use state (instead of device) as a trigger. For example, trigger automation when binary_sensor.doorbell_motion_sensor change from
False
toTrue
.
Set Up Broadlink IR#
Basic set up#
- Add the default broadlink integration.
- Unlike other integrations, there are no entities and devices created. All commands are executed using services. For example, use
remote.learn_command
to learn IR commands sent from a remote andremote.send_command
to sent IR commands. - The commands learnt can be accessed from
.storage/
in the configuration folder. - To learn multiple commands, see guide.
Setup for A/C, TV#
Instead of learning all IR codes from scratch, use smart ir. It'll download .json files containing codes for various appliances. Below is an example of the code to be added to configuration.yaml
.
# Broadwell IR Setting
smartir:
media_player:
- platform: smartir
name: Living room TV
unique_id: living_room_tv
device_code: 1100
controller_data: remote.broadlink_rm4_pro_remote
power_sensor: binary_sensor.tv_power
climate:
- platform: smartir
name: Study AC
unique_id: study_ac
device_code: 1024
controller_data: remote.broadlink_rm4_pro_remote
temperature_sensor: sensor.zigb_ths01_temperature
humidity_sensor: sensor.zigb_ths01_humidity
This code will create new services like Climate : Turn on
and Media player: Turn on
.
Back Up HA#
link * For synology, i recommend creating a separate user with limited access for the purposes of the backup since the password is stored unencrypted in the configuration file... * Configuration file for samba_backup add-on.
host: 192.168.1.146
share: Jon_Files
target_dir: /HAVM_Backups
username: <your-username>
password: <your-password>
keep_local: 5
keep_remote: 20
trigger_time: '12:11'
trigger_days:
- Mon
- Tue
- Wed
- Thu
- Fri
- Sat
- Sun
exclude_addons:
- core_ssh
- core_duckdns
exclude_folders:
- ssl
backup_name: '{type} Backup {date}'