Hoy os vamos a enseñar cómo integrar, conectar y controlar un equipo remoto que tenga instalado Windows 10 desde Home Assistant.

Para realizar esta integración, necesitaremos tener activo un servidor MQTT e instalar un pequeño servicio en Windows que se encargará de enviarle los comandos a nuestro Home Assistant.

Con este tutorial podremos:

  • Apagar / Encender el ordenador
  • Enviar notificaciones
  • Bloquear el equipo
  • Apagar / Encender los monitores
  • Ver el escritorio
  • Subir / Bajar el volumen
  • Abrir una página web
  • E infinidad de opciones ya que también se pueden añadir scripts personalizados

Integrar Windows 10 con Home Assistant

Para realizar la integración nos vamos a apoyar de la herramienta IoT link desarrollada por Alexandre Leites.

Primero descargaremos la aplicación desde su sitio web y la instalaremos. Importante instalarla con derechos de administrador (botón derecho > ejecutar como administrador). Esto es requerido porque necesitamos instalar un servicio en Windows y la aplicación debe poder acceder a comprobar el estado de la CPU, RAM etc..

Una vez instalada nos habrá creado en el menú de inicio una carpeta llamada IOT Link. Aquí deberemos ejecutar la aplicación » Open configuration file» para que nos abra el archivo de cofiguración.

Se nos abrirá un archivo con el block de notas que deberemos editar con nuestros datos de acceso a nuestro servidor MQTT. Los datos que habría que cambiar son los siguientes:

  • username: (aquí pondremos el usuario de MQTT)
  • password: (aquí pondremos el password de MQTT)
  • hostname (la dirección IP de nuestro servidor MQTT)
  • port: (en principio si es el puerto por defecto no deberemos tocarlo)

Una vez finalizada la configuración guardamos el archivo y ejecutamos «Install Windows Service» (ejecutarlo como administrador) y posteriormente «Start Windows Service» (ejecutarlo también como administrador).

Ahora si todo ha ido bien, ya tendremos nuestro servicio enviando los datos de nuestro equipo al servidor MQTT. Se puede consultar el estado de la aplicación desde su archivo de logs ubicado en «C:\ProgramData\IOTLink\Logs».

Lo siguiente que deberemos hacer es configurar nuestro Home Assistant para que lea los distintos valores. Para realizar esto simplemente hay que ir dando de alta los sensores, aquí os dejo un ejemplo de configuración de todos los sensores y scripts disponibles.

Importante: hay que sustituir la ruta «iotlink/workgroup/my-computer/lwt» por nuestro equipo siguiendo la directriz de grupo de trabajo o dominio / nombre equipo. Ejemplo de mi caso: iotlink/workgroup/equipo-casa/lwt. Mas información aquí.

binary_sensor:
  - platform: mqtt
    name: "My Computer - Connected"
    state_topic: "iotlink/workgroup/my-computer/lwt"
    value_template: "{{ value }}"
    payload_on: "ON"
    payload_off: "OFF"
    device_class: "connectivity"
    qos: 1

  - platform: mqtt
    name: "My Computer - Charging"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/power/status"
    value_template: "{{ value }}"
    payload_on: "Online"
    payload_off: "Offline"
    device_class: "plug"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Battery Status"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/battery/status"
    value_template: "{{ value }}"
    payload_on: "Online"
    payload_off: "Offline"
    device_class: "plug"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

sensor:

  - platform: mqtt
    name: "My Computer - Current User"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/current-user"
    unit_of_measurement: ''
    icon: mdi:account
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Idle Time"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/idle-time"
    unit_of_measurement: 'seconds'
    icon: mdi:timer
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - CPU Usage"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/cpu"
    unit_of_measurement: '%'
    icon: mdi:speedometer
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - RAM Usage"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/memory/usage"
    unit_of_measurement: '%'
    icon: mdi:memory
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - RAM Available"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/memory/available"
    unit_of_measurement: 'MB'
    icon: mdi:memory
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - RAM Used"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/memory/used"
    unit_of_measurement: 'MB'
    icon: mdi:memory
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - RAM Total"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/memory/total"
    unit_of_measurement: 'MB'
    icon: mdi:memory
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Remaining Battery"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/battery/remaining-percent"
    unit_of_measurement: '%'
    device_class: battery
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Remaining Battery Time"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/battery/remaining-time"
    unit_of_measurement: 'minutes'
    icon: mdi:timer
    value_template: "{{ ( value | float / 60 ) | int }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Predicted Lifetime"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/battery/full-lifetime"
    unit_of_measurement: 'minutes'
    icon: mdi:timer
    value_template: "{{ ( value | float / 60 ) | int }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - HDD Usage (C)"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/hard-drive/c/drive-usage"
    unit_of_measurement: '%'
    icon: mdi:chart-donut
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - HDD Total Size (C)"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/hard-drive/c/total-size"
    unit_of_measurement: 'GB'
    icon: mdi:harddisk
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - HDD Total Free Space (C)"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/hard-drive/c/total-free-space"
    unit_of_measurement: 'GB'
    icon: mdi:harddisk
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - HDD Free Space (C)"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/hard-drive/c/available-free-space"
    unit_of_measurement: 'GB'
    icon: mdi:harddisk
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - HDD Used Space (C)"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/hard-drive/c/used-space"
    unit_of_measurement: 'GB'
    icon: mdi:harddisk
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - HDD Format (C)"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/hard-drive/c/drive-format"
    unit_of_measurement: ''
    icon: mdi:harddisk
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - HDD Label (C)"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/hard-drive/c/volume-label"
    unit_of_measurement: ''
    icon: mdi:harddisk
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Network IPv4"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/network/0/ipv4"
    unit_of_measurement: ''
    icon: mdi:lan
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Network IPv6"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/network/0/ipv6"
    unit_of_measurement: ''
    icon: mdi:lan
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Network Speed"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/network/0/speed"
    unit_of_measurement: 'Mbps'
    icon: mdi:speedometer
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

  - platform: mqtt
    name: "My Computer - Network Wired"
    state_topic: "iotlink/workgroup/my-computer/windows-monitor/stats/network/0/wired"
    unit_of_measurement: ''
    icon: mdi:ethernet
    value_template: "{{ value }}"
    availability_topic: "iotlink/workgroup/my-computer/lwt"
    payload_available: "ON"
    payload_not_available: "OFF"
    qos: 1

camera:
  - platform: mqtt
    name: "My Computer - Screen 0"
    topic: "iotlink/workgroup/my-computer/windows-monitor/stats/display/0/screen"

switch:
  - platform: template
    switches:
      my_computer:
        friendly_name: "My Computer"
        value_template: "{{ is_state('binary_sensor.my_computer_connected', 'on') }}"
        turn_on:
          service: script.my_computer_wake
        turn_off:
          service: script.my_computer_shutdown
        icon_template: mdi:laptop

script:
  my_computer_wake:
    alias: "My Computer - Wake"
    sequence:
      - service: wake_on_lan.send_magic_packet
        data:
          mac: "70:85:C2:63:9F:11"

  my_computer_shutdown:
    alias: "My Computer - Shutdown"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/shutdown"
          payload: ""

  my_computer_suspend:
    alias: "My Computer - Suspend"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/suspend"
          payload: ""

  my_computer_hibernate:
    alias: "My Computer - Hibernate"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/hibernate"
          payload: ""

  my_computer_reboot:
    alias: "My Computer - Reboot"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/reboot"
          payload: ""

  my_computer_lock:
    alias: "My Computer - Lock"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/lock"
          payload: ""

  my_computer_logoff:
    alias: "My Computer - Logoff"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/logoff"
          payload: ""

  my_computer_vol_mute:
    alias: "My Computer - Toggle Mute"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/volume/mute"
          payload: ""

  my_computer_vol_max:
    alias: "My Computer - Vol Max"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/volume/set"
          payload: "100"

  my_computer_displays_on:
    alias: "My Computer - Displays ON"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/displays/on"
          payload: ""

  my_computer_displays_off:
    alias: "My Computer - Displays OFF"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/displays/off"
          payload: ""

  my_computer_refresh:
    alias: "My Computer - Refresh"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/refresh"
          payload: ""

  my_computer_notify:
    alias: "My Computer - Notify"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/notify"
          payload: '{ "title": "My Notification Title", "message": "This is an example of notification using IOT Link", "launchParams": "toast://open/https://iotlink.gitlab.io" }'

  my_computer_run_chrome:
    alias: "My Computer - Run Chrome"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/run"
          payload: '{ "command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe", "args": "https://iotlink.gitlab.io", "path": "C:\\Program Files (x86)\\Google\\Chrome\\Application", "user": "", "visible": true, "fallback": true }'

  my_computer_run_ccleaner:
    alias: "My Computer - Run CCleaner"
    sequence:
      - service: mqtt.publish
        data:
          topic: "iotlink/workgroup/my-computer/commands/run"
          payload: '{ "command": "C:\\Program Files\\CCleaner\\CCleaner64.exe", "args": "/AUTO"
 "path": "C:\\Program Files\\CCleaner\\", "user": "", "visible": true, "fallback": true }'

Una vez registrado cada componente en nuestro Home Assistant ya deberíamos de poder ver toda la información acerca de nuestro equipo y nuestro escritorio.

A partir de aquí ya todo lo que podremos hacer será pura magia, cualquier cosa que se nos ocurra con nuestro equipo es posible.

Podéis dejar una captura de vuestra interfaz en los comentarios, nos gustaría ver lo bien que luce vuestra integración con Windows 😉