From 12f2d718e3dc593ab32eaeb02eb5ffb29169a196 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 9 Nov 2025 01:34:24 -0300 Subject: [PATCH] =?UTF-8?q?Agregando=20configuraci=C3=B3n=20de=20home=20as?= =?UTF-8?q?sistant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxmox/homeassistant/.gitignore | 50 ++++++++++ proxmox/homeassistant/.terraform.lock.hcl | 44 +++++++++ proxmox/homeassistant/README.md | 98 +++++++++++++++++++ proxmox/homeassistant/main.tf | 58 +++++++++++ .../homeassistant/terraform.tfvars.example | 7 ++ proxmox/homeassistant/variables.tf | 11 +++ stacks/traefik/dynamic/home-assistant.yml | 2 +- 7 files changed, 269 insertions(+), 1 deletion(-) create mode 100644 proxmox/homeassistant/.gitignore create mode 100644 proxmox/homeassistant/.terraform.lock.hcl create mode 100644 proxmox/homeassistant/README.md create mode 100644 proxmox/homeassistant/main.tf create mode 100644 proxmox/homeassistant/terraform.tfvars.example create mode 100644 proxmox/homeassistant/variables.tf diff --git a/proxmox/homeassistant/.gitignore b/proxmox/homeassistant/.gitignore new file mode 100644 index 0000000..011a52d --- /dev/null +++ b/proxmox/homeassistant/.gitignore @@ -0,0 +1,50 @@ +# Created by https://gitignore.org +# Terraform.gitignore + +# Local .terraform directories +.terraform/ + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Ignore transient lock info files created by terraform apply +.terraform.tfstate.lock.info + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc + +# Optional: ignore graph output files generated by `terraform graph` +# *.dot + +# Optional: ignore plan files saved before destroying Terraform configuration +# Uncomment the line below if you want to ignore planout files. +# planout + + +aircon.json diff --git a/proxmox/homeassistant/.terraform.lock.hcl b/proxmox/homeassistant/.terraform.lock.hcl new file mode 100644 index 0000000..c5bd52f --- /dev/null +++ b/proxmox/homeassistant/.terraform.lock.hcl @@ -0,0 +1,44 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/bpg/proxmox" { + version = "0.86.0" + constraints = "0.86.0" + hashes = [ + "h1:0OH908XIuDk42UTevFCfMMEnDdbsqNzSZBLGqjoj8S0=", + "zh:09b627b92a59848769fadfc3d8103eebf070a3800144bf03cb93f44472327f44", + "zh:0e19eb7f1047d541e50b97d7ac440ea73685d0c28ed2dbe64217cbe2f0b353e0", + "zh:20f1e70091ff3056876618c93afd79527c8995f955d153993e8fbb10fa42593b", + "zh:3920315be565976f5a9da0803f8f1a108221282f1bc9e21160669d793af4e0c8", + "zh:5133b2a2027428d3926eaa3bcdc0ab65a75305d54f6cbc7c54cce746dfddbc8e", + "zh:514c588b04738d55c9e6b1c5a4e3fb1ef4041dfb809d2268f14d29839ecfba59", + "zh:55916034025b4833bd6a93bb5948dfb7d00830a772ef74fa70898c6f7de0da0b", + "zh:58b485a4b0bde56ca7032fca0ac09cb4c6ff2579e06cf4f2a311bb695baa0df1", + "zh:75ebe44e6da4108af5fe02a9cd99ed0189985b486a2a56594952098d161ceb3d", + "zh:a8c870bfb5958a3d49d639db3c2761cfb453c6a6f95e5e241890922b11c8a4d8", + "zh:c2df2748b9be47a6c3e613667c64874d5cb1d3fbb5b985d6eb9c3af5af298454", + "zh:c3059668f4f81e450e555a47310e7042044b335f131643262fd51f9ba96f2214", + "zh:ddbbb23910666f70cf4a9587ba57b45f5f58c53a1f8d7cee1d6f90a3d3ef38ef", + "zh:e430138b897edcd3b64e4309db34ac872526187782626aa074d8d1647a0abfa8", + "zh:f26e0763dbe6a6b2195c94b44696f2110f7f55433dc142839be16b9697fa5597", + ] +} + +provider "registry.terraform.io/hashicorp/local" { + version = "2.5.3" + hashes = [ + "h1:1Nkh16jQJMp0EuDmvP/96f5Unnir0z12WyDuoR6HjMo=", + "zh:284d4b5b572eacd456e605e94372f740f6de27b71b4e1fd49b63745d8ecd4927", + "zh:40d9dfc9c549e406b5aab73c023aa485633c1b6b730c933d7bcc2fa67fd1ae6e", + "zh:6243509bb208656eb9dc17d3c525c89acdd27f08def427a0dce22d5db90a4c8b", + "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", + "zh:885d85869f927853b6fe330e235cd03c337ac3b933b0d9ae827ec32fa1fdcdbf", + "zh:bab66af51039bdfcccf85b25fe562cbba2f54f6b3812202f4873ade834ec201d", + "zh:c505ff1bf9442a889ac7dca3ac05a8ee6f852e0118dd9a61796a2f6ff4837f09", + "zh:d36c0b5770841ddb6eaf0499ba3de48e5d4fc99f4829b6ab66b0fab59b1aaf4f", + "zh:ddb6a407c7f3ec63efb4dad5f948b54f7f4434ee1a2607a49680d494b1776fe1", + "zh:e0dafdd4500bec23d3ff221e3a9b60621c5273e5df867bc59ef6b7e41f5c91f6", + "zh:ece8742fd2882a8fc9d6efd20e2590010d43db386b920b2a9c220cfecc18de47", + "zh:f4c6b3eb8f39105004cf720e202f04f57e3578441cfb76ca27611139bc116a82", + ] +} diff --git a/proxmox/homeassistant/README.md b/proxmox/homeassistant/README.md new file mode 100644 index 0000000..0d8b198 --- /dev/null +++ b/proxmox/homeassistant/README.md @@ -0,0 +1,98 @@ +# Home Assistant Installation + +These files allow you to deploy a Home Assistant OS virtual machine on Proxmox using Terraform. + +Terraform handles the creation of the VM based on the pre-built `.qcow2` image of Home Assistant OS. +All further configuration (such as the proxy settings) is done directly from the Home Assistant web interface. + +## Terraform Execution + +To create the VM with Terraform, the configuration must be defined in the `terraform.tfvars` file. +You can use `terraform.tfvars.example` as a base. + +Then run the following commands: + +1. Initialize Terraform: +```bash +terraform init +``` + +2. Review the plan: +```bash +terraform plan +``` + +3. Apply the plan: +```bash +terraform apply +``` + +The process will create a new VM on the configured Proxmox node using the uploaded `.qcow2` image. +Once created, Home Assistant OS will boot automatically and obtain an IP via DHCP. + +Access the web interface at: +[http://homeassistant.local:8123](http://homeassistant.local:8123) + +That should work given that Pi-hole is already runing on the network + +## Home Assistant Configuration + +After the initial setup (creating your user and restoring backups if applicable), +you must adjust the HTTP configuration to properly support a reverse proxy such as Traefik. + +To edit Home Assistant’s configuration file `configuration.yaml`, first install the File Editor add-on: + +1. Open the Home Assistant web interface. +2. Go to `Settings` -> `Add-ons` -> `Add-on Store`. +3. Search for File Editor and click Install. +4. Once installed, click Start and optionally enable Show in sidebar. + +Then use the File Editor to open `/config/configuration.yaml` + +Add the following section + +```yaml +http: + use_x_forwarded_for: true + trusted_proxies: + - "192.168.0.0/16" +``` + +Finally: + +1. Go to `Settings` -> `System` -> `Check configuration` to validate the file. +2. Restart Home Assistant Core via `Settings` -> `System` -> `Restart`. + +This ensures Home Assistant correctly interprets requests forwarded through your proxy, preserving real client IPs and maintaining secure access. + +## AC Integraion + +To control the air conditioner that uses the NetHome Plus app, install HACS (Home Assistant Community Store) and the Midea AC LAN integration. + +### Step 1 - Install HACS + +Follow the documentation at [HACS](https://hacs.xyz/docs/use/) + +### Step 2 — Install Midea AC LAN Integration + +Follow the documentation at [midea_ac_lan](https://github.com/wuwentao/midea_ac_lan/tree/master) + +> Important: recent Midea / NetHome Plus API changes limit how tokens can be obtained. +> Keep a backup file containing your current tokens — it will be necessary if API access becomes restricted in the future. +> Tokens can be found via SSH at: `/config/.storage/midea_ac_lan` + + +## Reinstallation + +If a full reinstall is needed, simply destroy and recreate the Terraform resources: + +```bash +terraform destroy +``` + +Then run: +```bash +terraform apply +``` + +to provision a clean instance again. diff --git a/proxmox/homeassistant/main.tf b/proxmox/homeassistant/main.tf new file mode 100644 index 0000000..d68ddd5 --- /dev/null +++ b/proxmox/homeassistant/main.tf @@ -0,0 +1,58 @@ +terraform { + required_providers { + proxmox = { + source = "bpg/proxmox" + version = "0.86.0" + } + } +} + +data "local_file" "proxmox_ssh_private_key" { + filename = var.proxmox_ssh_privkey_path +} + +provider "proxmox" { + endpoint = var.proxmox_endpoint + username = var.proxmox_user + password = var.proxmox_password + insecure = true + + ssh { + agent = true + username = var.proxmox_ssh_username + private_key = trimspace(data.local_file.proxmox_ssh_private_key.content) + } +} + +resource "proxmox_virtual_environment_vm" "homeassistant" { + name = "homeassistant" + node_name = var.proxmox_node + + stop_on_destroy = true + + bios = "ovmf" + + cpu { + cores = 2 + type = "host" + } + + memory { + dedicated = 8096 + } + + efi_disk { + datastore_id = var.vm_datastore + } + + disk { + datastore_id = var.vm_datastore + import_from = "${var.proxmox_datastore}:import/haos_ova-16.3.qcow2" + interface = "virtio0" + size = 100 + } + + network_device { + bridge = var.bridge + } +} diff --git a/proxmox/homeassistant/terraform.tfvars.example b/proxmox/homeassistant/terraform.tfvars.example new file mode 100644 index 0000000..24a595c --- /dev/null +++ b/proxmox/homeassistant/terraform.tfvars.example @@ -0,0 +1,7 @@ +proxmox_endpoint = "https://192.168.1.1:8006" +proxmox_user = "terraform@pam" +proxmox_password = "secret" +proxmox_node = "pve" + +proxmox_ssh_username = "terraform" +proxmox_ssh_privkey_path = "/home/user/.ssh/id_ed25519" diff --git a/proxmox/homeassistant/variables.tf b/proxmox/homeassistant/variables.tf new file mode 100644 index 0000000..bb442fe --- /dev/null +++ b/proxmox/homeassistant/variables.tf @@ -0,0 +1,11 @@ +variable "proxmox_endpoint" {} +variable "proxmox_user" {} +variable "proxmox_password" { sensitive = true } +variable "proxmox_node" { default = "pve" } + +variable "proxmox_ssh_username" {} +variable "proxmox_ssh_privkey_path" {} +variable "proxmox_datastore" { default = "local" } + +variable "bridge" { default = "vmbr0" } +variable "vm_datastore" { default = "local-vm" } diff --git a/stacks/traefik/dynamic/home-assistant.yml b/stacks/traefik/dynamic/home-assistant.yml index 2ba48ca..077424d 100644 --- a/stacks/traefik/dynamic/home-assistant.yml +++ b/stacks/traefik/dynamic/home-assistant.yml @@ -21,7 +21,7 @@ http: home-assistant-svc: loadBalancer: servers: - - url: "http://192.168.3.6:8123" + - url: "http://192.168.3.2:8123" noop: loadBalancer: servers: