IOT Link - Windows Management using MQTT

Well just unistall it from windows using the unistaller and manually remove all the entities from HA I’m guessing…

1 Like

I am trying to remove iot link completely from HA. I had connected 4-5 laptops. I have uninstalled iot link from windows control panel and I have removed the entities from HA. However when I still get the below message

What more should I do?

We control the brightness of the screen on the monitor using IO Link. Read more details here

To adjust the brightness, we use the following command

service: mqtt.publish
data:
  topic: iotlink/workgroup/livingroom/commands/run
  payload: >-
    { "command": "C:\\Windows\\System32\\cmd.exe", "args":"/k
    %LOCALAPPDATA%\\Microsoft\\WindowsApps\\Monitorian.exe /set 40", 
    "path": "C:\\Windows\\System32","user": "", "visible": false, "fallback":
    true }

We use a variable to adjust the brightness

service: mqtt.publish
data:
  topic: iotlink/workgroup/livingroom/commands/run
  payload: >-
    { "command": "C:\\Windows\\System32\\cmd.exe", "args":"/k
    %LOCALAPPDATA%\\Microsoft\\WindowsApps\\Monitorian.exe /set 
    {{states("input_number.pc_livingroom_monitor_brightness")|round(0)}}", 
    "path": "C:\\Windows\\System32","user": "", "visible": false, "fallback":
    true }
Текст на русском (Text in Russian)

Управляем яркостью экрана на мониторе с помощью IOTLink. Более подробно читаем здесь

Для регулировки яркости используем такую команду

service: mqtt.publish
data:
  topic: iotlink/workgroup/livingroom/commands/run
  payload: >-
    { "command": "C:\\Windows\\System32\\cmd.exe", "args":"/k
    %LOCALAPPDATA%\\Microsoft\\WindowsApps\\Monitorian.exe /set 40", 
    "path": "C:\\Windows\\System32","user": "", "visible": false, "fallback":
    true }

Используем переменную для регулировки яркости

service: mqtt.publish
data:
  topic: iotlink/workgroup/livingroom/commands/run
  payload: >-
    { "command": "C:\\Windows\\System32\\cmd.exe", "args":"/k
    %LOCALAPPDATA%\\Microsoft\\WindowsApps\\Monitorian.exe /set 
    {{states("input_number.pc_livingroom_monitor_brightness")|round(0)}}", 
    "path": "C:\\Windows\\System32","user": "", "visible": false, "fallback":
    true }

Hotlink sensors are sometimes unavailable. To fix this, I restart the IOTLink service and the sensors start working again. This happens quite often and I was thinking about automatically restarting the IOTLink service. The IOTLink service itself works and standard sensors do not fail. It is user sensors that fail, for example Process Monitor. I created a batnik and run it to restart the IOTLink service, but I ran into a problem. Elevated permissions are required to run the batnik.

In c:\ProgramData\IOTLink\Addons\ProcessMonitor\apps\Games.yaml I added the following

processes:
  - ACValhalla.exe
  - DOOMEternalx64vk.exe
  - HorizonZeroDawn.exe
  - HaloInfinite.exe
  - RAGE2.exe
  - GoW.exe
  - MetroExodus.exe
windows:
classnames:
configs:
  enabled: true
  discoverable: true
  advancedMode: false
  displayName: Games
  cacheable: true
  grouped: true
  compareType: 0
  interval: 10

I wrote a batnik that restarts the IOTLink service, but there is a problem, the batnik does not start, since elevated rights and UAC bypass are required. I found an option and wrote it like this, the option is below

This batnik cannot start because administrator rights are required

@echo off
net stop IOTLink
rem
net start IOTLink

This batnik runs with administrator rights via IOTLink, but does not bypass UAC, you have to turn off UAC.


@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params= %*
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"



@echo off
net stop IOTLink
rem
net start IOTLink

Tried using runas, also doesn’t help

runas /user:user "c:\scripts\iotlink_reboot.bat" 

Running the script via IOTLink looks like this

service: mqtt.publish
data:
  topic: iotlink/workgroup/livingroom/commands/run
  payload: >-
    { "command": "C:\\scripts\\iotlink_reboot.bat", "path": "C:\\scripts",
    "user": "", "visible": false, "fallback": true }

I just run iotlink as a Windows service and force it to restart every few hour with task scheduler.

The problem is that the IOTLink service does not hang and the rest of the sensors, except for custom ones, hang after restarting the Home Assistant or after some time. The task scheduler does not suit me for the reason that the sensor may freeze, and the scheduler will restart in a few hours, and at this time, for example, I started the game and Home Assistant does not launch this or that function. I have a very closely intertwined Home Assistant and computer. I need constant monitoring of sensors that show which game is running, which program is running, player or game. And now it also adjusts the brightness of my monitor, which I implemented today. Therefore, it is unacceptable for the Home Assistant to miss the moment that the IOTLink service does not work correctly.

Control of custom RGB backlight on the computer. We control the voice through Alice. IOTLink shows which game is running and its own effect is set for each game

Operation of the backlight on the monitor. IOTLink sees that the game is running and launches Hyperion and also monitors Hyperion. If Hyperion is not running, then run it

Automating Hyperion. Thanks to IOTLink, the Home Assistant understands that a game, a movie is running in the player or in the browser or youtube is running

As an option, I implemented such a scheme. Made automation that tracks IOTLink sensors. If the game sensor is not available, a script will run that will restart the service. While a window will pop up and ask you to allow the script to run. Maybe later there will be a solution how to bypass UAC

alias: 'System: IOTLink. Monitoring. Reboot'
description: >-
  We monitor IOTLink sensors. If the sensors are unavailable,
  a script will be run that will restart the IOTLink
trigger:
  - platform: state
    entity_id:
      - binary_sensor.livingroom_games
    to: unknown
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: time_pattern
    minutes: /5
condition:
  - condition: template
    value_template: '{{ is_state("switch.pc_livingroom", "on") }}'
  - condition: template
    value_template: '{{ is_state("binary_sensor.livingroom_games", "unknown") }}'
action:
  - service: script.livingroom_computer_iotlink_restart
    data: {}
mode: single

The script itself script.livingroom_computer_iotlink_restart

alias: 'Living room: Computer. Restart the Hotlink'
sequence:
  - service: mqtt.publish
    data:
      topic: iotlink/workgroup/livingroom/commands/run
      payload: >-
        { "command": "C:\\Scripts\\iotlink_reboot.bat", "path": "C:\\Scripts",
        "user": "", "visible": false, "fallback": true }
mode: single
icon: mdi:desktop-mac

Ah well if you require that kind of precision perhaps one of the programs will be better.
There are a couple around.

There is another one called eventghost
http://www.eventghost.net/

I haven’t used either as a restart of iotlink covers my needs

I’m just probing her today during the day :smiley:. While this program causes mixed feelings, I just got used to IOTLink and then, if I switch to HASS Agent, I will have to redo a lot. What I don’t like about HASS Agent is that I need to create several games with the same name Games so that the Games sensor is only on\off, and it’s more convenient in IOTLink in this regard, I added the name of the game to the config and that’s it. For now, IOTLink remains the best choice for me, and then we’ll see. While studying the possibilities of the program



Iotlink is without a developer for a long time. So there won’t be any improvements that will solve your sensor problems…

You write everything correctly and I fully share your view. I will smoothly move to Hass Agent. Yes, there is an inconvenience in terms of having to create multiple sensors for games, but it’s good that you can specify one name of the Game and also for media players, both software and in the browser

I have similar iotlink disconnects and just run a scheduled task every hour, doing the same net stop / start . Have you ever considered this and if yes…why did you choose the solution above

Restarting the IOTLink service via the task scheduler is not suitable for me, because I have a lot tied up on IOTLink and constant sensor work is required. If IOTLink stops working, automations dependent on IOTLink will not work.

IOTLink performs the following tasks for me:

  1. Adjusting the brightness of the monitor screen
  2. Monitoring of Hyperion, Led FX, MDP service
  3. Monitoring of running games
  4. Media Player monitoring
  5. Monitoring whether the PotPlayer media player is running, in which mode, minimized or fullscreen
  6. Monitoring whether youtube is running in the browser, in which mode, minimized or fullscreen

What are the automations that depend on IOTLink?

  1. If we are sitting at a PC and just working, then the brightness of the monitor screen is adjusted depending on the brightness level in the room. If you have started the game, the screen brightness will be higher, finished playing or minimized the game to the tray, the screen brightness will return to the one that was before the game was launched

  2. We track whether the game is running. When the game starts, the “rest mode” turns on, where the curtains close, the monitor’s background light turns on, and then Hyperion starts and, depending on the running game, a certain preset on WLED is started for coolers and if it’s hot, the air conditioner will turn on for cooling
    Watch the video: Control of custom RGB backlight on the computer. We control the voice through Alice. - YouTube

  3. We track the viewing of media content. If I run a movie in full-screen mode in sunny time, the curtains will also automatically close, the ambilight will turn on and the backlight on the computer will turn off and if it’s hot, the air conditioner will turn on for cooling
    Watch the video: Home Assistant. Automating Hyperion

  4. If LedFX and MPD are running and if the sensor is available, then the light-musical will work
    Watch the video: Home Assistant. Led FX. Music Visualization - YouTube

Thanks to IOTLink, HomeAssistant understands what is running, in which mode automation is triggered. If the user sensor is unavailable at this moment, then automation simply will not work. Restarting the IOTLink service through the task scheduler after a certain period of time, for example, every minute or every 2 hours, we lose sight of the fact that while the task scheduler restarts the IOTLink service, user sensors may be unavailable at the moment we need and automation will not work. That’s why I made it so that IOTLink restarts when the user sensor is unavailable and as soon as HomeAssistant sees it, it will run a script that will restart the service for me. It’s okay that a window appears with a warning that such and such a process is running yes or no, I click YES and the service restarts. After all, we are still sitting at the computer and IOTLink works with the computer turned on. Of course, you can turn off UAC, then it will work automatically and without a warning window.

How to restart the IOTLink service with administrator rights and bypass UAC

I found a working way to bypass UAC on Windows to run a batnik with elevated rights. I have Windows 11 and it works like you will, I do not know. I wrote above that I have a problem with user sensors and they become unavailable. Now the issue is resolved. Below I will describe the sequence of actions.

First, we create a text file and enter commands to turn off and start the IOTLink service

net stop IOTLink - stop the service
rem - waits for the service to be stopped, and then start the service
net start IOTLink - start the service

This is what the usual code for restarting the service looks like, but such a batnik will not start without elevated rights and you will need to run it with administrator rights and if UAC is enabled, you will need to confirm the launch.

@echo off
net stop IOTLink
rem
net start IOTLink

In order for the batnik to start with elevated rights, you just need to copy all this code into a text file and rename it, for example, to iotlink_reboot_service.bat. We try to run the batnik and if everything is done correctly, the batnik will start, but the UAC will ask you to confirm. That’s right, that’s how it should be. Now we need to bypass UAC, read below

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params= %*
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"


net stop IOTLink
rem
net start IOTLink

To run the iotlink_reboot_service batnik.bat bypassing UAC, we need to install the UAC Trust Shortcut program on Windows. Then, as soon as you install the UAC Trust Shortcut program, run the UAC Trust Shortcut and create a shortcut based on the iotlink_reboot_service.bat bat. I named the shortcut iotlink_reboot_service.lnk. If you look at the properties of the created shortcut, then the object will indicate

"C:\Program Files\ITknowledge24\ucmd.exe" -rC:\Scripts\iotlink_reboot_service.bat

and since IOTLink does not know how to launch a shortcut, we will create another batnik that will launch the iotlink_reboot_service.lnk shortcut, and that in turn will launch the iotlink_reboot_service.bat batnik.

Creating a batnik named launching_iotlink_reboot_service.bat and add the code to it

start explorer.exe c:\Scripts\iotlink_reboot_service.lnk

As a result, we should have 3 files

  1. iotlink_reboot_service.bat - restarting the IOTLink service with administrator rights
  2. iotlink_reboot_service.lnk - to bypass UAC
  3. launching_iotlink_reboot_service.bat - to launch the iotlink_reboot_service.lnk shortcut

Now in Home Assistant you can create a script to restart the IOTLink service

service: mqtt.publish
data:
  topic: iotlink/workgroup/livingroom/commands/run
  payload: >-
    { "command": "C:\\Scripts\\launching_iotlink_reboot_service.bat", "path": "C:\\Scripts",
    "user": "", "visible": false, "fallback": false }

Next, we create automation that will monitor the sensor and run a script to restart IOTLink. For me, as a user sensor, it becomes unavailable, then a script is run that restarts the IOTLink service

alias: 'System: IOTLink. Monitoring. Reboot'
description: >-
  We monitor IOTLink sensors. If the sensors are unavailable,
  a script will be run that will restart the IOTLink
trigger:
  - platform: state
    entity_id:
      - binary_sensor.livingroom_games
    to: unknown
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: time_pattern
    minutes: /5
condition:
  - condition: template
    value_template: '{{ is_state("switch.computer", "on") }}'
  - condition: template
    value_template: '{{ is_state("binary_sensor.livingroom_games", "unknown") }}'
action:
  - service: script.livingroom_computer_iotlink_restart
    data: {}
mode: single
Текст на русском(Text in Russian)

Как перезапустить службу IOTLink с правами администратора и обойти UAC

Нашел рабочий способ обхода UAC на Windows для запуска батника с повышенными правами. У меня стоит Windows 11 и это работает, как будет у вас, я не знаю. Выше я писал, что у меня наблюдается проблема с пользовательскими сенсорами и они становятся недоступными. Теперь вопрос решен. Ниже опишу последовательность действии.

Сперва создаем текстовый файлик и вписываем команды на выключение и запуск службы IOTLink

net stop IOTLink - остановить службу
rem - ждет, когда будет выполнена остановка службы, а после запустит службу
net start IOTLink - запустить службу

Так выглядит обычный код для перезапуска службы, но такой батник не запустится без повышенных прав и потребуется запускать его с правами администратора и если включен UAC, то нужно будет подтвердить запуск.

@echo off
net stop IOTLink
rem
net start IOTLink

Чтобы батник запустился с повышенными правами, нужно просто скопировать весь этот код в текстовый файлик и переименовать например в iotlink_reboot_service.bat. Пробуем запустить батник и если все сделано правильно, то батник запустится, но UAC попросит подтвердить. Это правильно, так и должно быть. Теперь нам нужно обойти UAC, читаем ниже

@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
    IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    set params= %*
    echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    pushd "%CD%"
    CD /D "%~dp0"


net stop IOTLink
rem
net start IOTLink

Чтобы запустить батник iotlink_reboot_service.bat в обход UAC нам нужно установить на Windows программу UAC Trust Shortcut. Потом, как установите программу UAC Trust Shortcut, запустите UAC Trust Shortcut и создайте ярлык на основе батника iotlink_reboot_service.bat. Я назвал ярлык iotlink_reboot_service.lnk. Если посмотреть свойство созданного ярлыка, то в объекте будет указано

"C:\Program Files\ITknowledge24\ucmd.exe" -rC:\Scripts\iotlink_reboot_service.bat

а так как IOTLink не умеет запускать ярлык, то мы создадим еще один батник, который запустит ярлык iotlink_reboot_service.lnk, а тот в свою очередь запустит батник iotlink_reboot_service.bat

Создаем батник с именем launching_iotlink_reboot_service.bat и добавляем в него код

start explorer.exe c:\Scripts\iotlink_reboot_service.lnk

В итоге у нас должно получиться 3 файлика

  1. iotlink_reboot_service.bat - перезапуск службы IOTLink с правами администратора
  2. iotlink_reboot_service.lnk - для обхода UAC
  3. launching_iotlink_reboot_service.bat - для запуска ярлыка iotlink_reboot_service.lnk

Теперь в Home Assistant можете создать скрипт для перезапуска службы IOTLink

service: mqtt.publish
data:
  topic: iotlink/workgroup/livingroom/commands/run
  payload: >-
    { "command": "C:\\Scripts\\launching_iotlink_reboot_service.bat", "path": "C:\\Scripts",
    "user": "", "visible": false, "fallback": false }

Далее, создаем автоматизацию, которая будет следить за сенсором и запускать скрипт на перезапуск IOTLink. У меня как пользовательский сенсор становится недоступным, то запускается скрипт, который перезапускает службу IOTLink

alias: 'Система: IOTLink. Мониторинг. Перезагрузка'
description: >-
  Мониторим сенсоры IOTLink. Если сенсоры будут недоступны, то будет запущен
  скрипт, который перезагрузит IOTLink
trigger:
  - platform: state
    entity_id:
      - binary_sensor.livingroom_games
    to: unknown
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: time_pattern
    minutes: /5
condition:
  - condition: template
    value_template: '{{ is_state("switch.computer", "on") }}'
  - condition: template
    value_template: '{{ is_state("binary_sensor.livingroom_games", "unknown") }}'
action:
  - service: script.livingroom_computer_iotlink_restart
    data: {}
mode: single
1 Like

It took me a while to find the installers, I downloaded the latest from here. When I try to install, I get a “This app can’t run on your pc” error. Any ideas?

I Installed It just fine on a windows 10 surface pro just fine about a week ago.

1 Like

Does anyone have an alternative to this that is actually reliable? IOTLink can’t seem to run reliably if you have a computer that goes in and out of deep sleep.

Check out Hass Agent

1 Like

Agree with not being stable and after a lot of searching/asking I decided to install a scheduled task that restarts the service each hour, not really a nice solution … but it works.
Hass agent I tried and worked OK as well, but I found it more cumbersome to setup for my simple requirements so never tested this in full.

I had the same problem, i’m restarting the service every time the pc wakes up.
In the task planner you have to set the trigger to:

protocol: system
source: microsoft-windows-kernel-power
event-id: 107

Now every time the pc wakes up the iot-link service is restartet. Works reliable for me

1 Like

I tried this too but for some off reason the service dies during the day… “sometimes” and I gave up trying to find the cause, hence the scheduled task

1 Like