IOT Link - Windows Management using MQTT

Pretty sure the volume stuff got silently deprecated. @alexslx ?

Anyway I’ve come up with two autohotkey scripts. One which mutes the volume (but records what the volume was set to) and the other which restores it back to its former volume. Shout if interested in these.

I’ve made a autohotkey script that not only logs the state of the service but also restarts it if it falls over.

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}
#SingleInstance, force
SendMode Input  
SetWorkingDir %A_ScriptDir%  

iTC_imgName = IOTLinkService.exe

loop {
	
	Process, Exist, %iTC_imgName% ; check to see if IOTLink is running
	If (ErrorLevel = 0) ; If it is not running
	   {
		 Run %A_WinDir%\system32\net.exe start "IOTLink",, Hide
		 FormatTime, TimeString
		 FileAppend, %TimeString% Restarting .`n, C:\iotlinkrestartlog.txt
	   }
	Else 
	   {
		 FormatTime, TimeString
		 FileAppend, %TimeString% all OK .`n, C:\iotlinkrestartlog.txt
		 sleep 5
	   }
		 sleep 60000
}
1 Like

I wrote a MS Teams Addon for IoTLink if anyone is interested.
You can find it here: GitHub - ledhed-jgh/IoTLink-Addons: Addons for IoTLink

@alexslx Thanks for all the hard work you’ve put into IoTLink.

Tell me, I have Hyperion Server OS on Windows and I run Hyperion with this command.

It works successfully

service: mqtt.publish
data:
  topic: iotlink/workgroup/home/commands/run
  payload: >-
    { "command": "C:\\Program Files\\Hyperion\\bin\\hyperiond.exe",  "path":    
    "C:\\Program Files\\Hyperion", "user": "", "visible": true, "fallback": true
    }

And how do I close the Hyperion program? If I see taskkill /f /im through the console hyperiond.exe , then the Hyperion program will be closed, and through IoT I will not understand how I can close the hyperiond program. How can this be done?

I try this way and it doesn’t work

service: mqtt.publish
data:
  topic: iotlink/workgroup/home/commands/run
  payload: >-
    { "command": "‪C:\\Windows\\System32\\taskkill.exe", "args": "/f
    /IM hyperiond.exe", "path": "C:\\Windows\\system32\\", "user": "",
    "visible": true, "fallback": true }
service: mqtt.publish
data:
  topic: iotlink/workgroup/home/commands/run
  payload: >-
    { "command": "‪C:\\Windows\\System32\\taskkill.exe /f /im hyperiond.exe",
    "args": "", "path": "", "user": "", "visible": true, "fallback": true } }


For reference, maybe it will be useful to someone. Created the file Hyperion.yaml in folder C:\ProgramData\IOTLink\Addons\ProcessMonitor\apps and you can get the status of the Hyperion program

# Hyperion
processes:
  - hyperiond
windows:
classnames:
configs:
  enabled: true
  discoverable: true
  advancedMode: false
  displayName: Hyperion
  cacheable: true
  grouped: true
  compareType: 0
  interval: 10

image
image

Текст на русском (Text in Russian)

Скажите, на Windows у меня стоит Hyperion Server OS и я запускаю Hyperion вот такой командой.

Это работает успешно

service: mqtt.publish
data:
  topic: iotlink/workgroup/home/commands/run
  payload: >-
    { "command": "C:\\Program Files\\Hyperion\\bin\\hyperiond.exe",  "path":    
    "C:\\Program Files\\Hyperion", "user": "", "visible": true, "fallback": true
    }

А как мне закрыть программу Hyperion? Если я через консоль введу taskkill /f /im hyperiond.exe, то программа Hyperion будет закрыта, а через IoT я не пойму как мне закрыть программу hyperiond. Как это можно сделать?

Я пробую вот таким способом и это не работает

service: mqtt.publish
data:
  topic: iotlink/workgroup/home/commands/run
  payload: >-
    { "command": "‪C:\\Windows\\System32\\taskkill.exe", "args": "/f
    /IM hyperiond.exe", "path": "C:\\Windows\\system32\\", "user": "",
    "visible": true, "fallback": true }
service: mqtt.publish
data:
  topic: iotlink/workgroup/home/commands/run
  payload: >-
    { "command": "‪C:\\Windows\\System32\\taskkill.exe /f /im hyperiond.exe",
    "args": "", "path": "", "user": "", "visible": true, "fallback": true } }


Для справки, может кому то будет полезным. Создал файлик Hyperion.yaml в папке C:\ProgramData\IOTLink\Addons\ProcessMonitor\apps и можно получать статус программы Hyperion

# Hyperion
processes:
  - hyperiond
windows:
classnames:
configs:
  enabled: true
  discoverable: true
  advancedMode: false
  displayName: Hyperion
  cacheable: true
  grouped: true
  compareType: 0
  interval: 10

image
image

I have found a solution and I will answer my own question, but I will be grateful if you show me other options on how to close the program.

I resorted to nircmd. You can download nircmd-x64 for Windows 10 x64 here. Unpacked to an arbitrary folder, in my example, this is the Distributiv folder and specified the path to nircmd

service: mqtt.publish
data:
  topic: iotlink/workgroup/home/commands/run
  payload: >-
    { "command": "c:\\Distributiv\\nircmd\\nircmd.exe", "args": "nircmd
    killprocess hyperiond.exe", "path": "c:\\Distributiv\\nircmd\\", "user": "",
    "visible": true, "fallback": true }

Created an MQTT switch

switch:
  - platform: mqtt
    unique_id: switch livingroom wled monitor hyperion
    name: "WLED Monitor. Hyperion"
    command_topic: "iotlink/workgroup/home/commands/run"
    state_topic: "iotlink/workgroup/home/process-monitor/processes/hyperion/state"
    payload_on: '{ "command": "C:\\Program Files\\Hyperion\\bin\\hyperiond.exe", "path": "C:\\Program Files\\Hyperion", "user": "", "visible": true, "fallback": true }'
    payload_off: '{ "command": "C:\\Distributiv\\nircmd\\nircmd.exe", "args": "nircmd killprocess hyperiond.exe", "path": "C:\\Distributiv\\nircmd\\", "user": "", "visible": true, "fallback": true }'
    state_on: 'ON'
    state_off: 'OFF'
    optimistic: false
    qos: 0
    retain: true
    icon: mdi:television-ambient-light
Текст на русском (Text in Russian)

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

Я прибегнул к nircmd. Скачать nircmd-x64 для Windows 10 x64 можно здесь. Распаковал в произвольную папку, в моем примере, это папка Distributiv и указал путь к nircmd

service: mqtt.publish
data:
  topic: iotlink/workgroup/home/commands/run
  payload: >-
    { "command": "c:\\Distributiv\\nircmd\\nircmd.exe", "args": "nircmd
    killprocess hyperiond.exe", "path": "c:\\Distributiv\\nircmd\\", "user": "",
    "visible": true, "fallback": true }

Создал MQTT выключатель

switch:
  - platform: mqtt
    unique_id: switch livingroom wled monitor hyperion
    name: "WLED Монитор. Hyperion"
    command_topic: "iotlink/workgroup/home/commands/run"
    state_topic: "iotlink/workgroup/home/process-monitor/processes/hyperion/state"
    payload_on: '{ "command": "C:\\Program Files\\Hyperion\\bin\\hyperiond.exe", "path": "C:\\Program Files\\Hyperion", "user": "", "visible": true, "fallback": true }'
    payload_off: '{ "command": "C:\\Distributiv\\nircmd\\nircmd.exe", "args": "nircmd killprocess hyperiond.exe", "path": "C:\\Distributiv\\nircmd\\", "user": "", "visible": true, "fallback": true }'
    state_on: 'ON'
    state_off: 'OFF'
    optimistic: false
    qos: 0
    retain: true
    icon: mdi:television-ambient-light

Creating a sensor that opens YouTube in the browser

How I automated Hyperion using IO Link

I will share an option on how to create a sensor of what we are watching on a YouTube computer. Why is this necessary? There is such an integration, called Hyperion, it allows you to capture an image and transfer colors to address LEDs. I have made Hyperion automatically turn on/off when launching games or when enabling fullscreen mode in the browser. But there is one thing, but if I turn on fullscreen mode in the browser, then Hyperion will turn on, and I don’t need it, since I need it to turn on if I watch YouTube in fullscreen mode. So, by creating such a sensor, we exclude Hyperion auto-switching when enabling fullscreen mode in another contribution, only when watching YouTube

If you look at json in qt, we see the following and we are interested in the string “MainWindowTitle”, which we will use in the sensor. The line “MainWindowTitle” displays information about which page we have opened in the browser and can pull out keywords, in our case it is YouTube

Data in MQTT Explorer
{
  "Id": "12852",
  "SessionId": "6",
  "ProcessName": "opera",
  "StartDateTime": "2021-12-09 18:29:45",
  "Uptime": "00:03:05:19",
  "MemoryUsed": "735",
  "ProcessorUsage": "1,34",
  "MainWindowTitle": "More Real 12K HDR 60FPS Dolby Vision - YouTube - Opera",
  "FullScreen": "False",
  "Status": "Running",
  "Windows": [
    "More Real 12K HDR 60FPS Dolby Vision - YouTube - Opera",
    "Chrome Legacy Window",
    "Chrome Legacy Window"
  ],
  "ClassNames": [
    "Chrome_WidgetWin_1",
    "Chrome_RenderWidgetHostHWND",
    "Chrome_RenderWidgetHostHWND"
  ]
}

Creating such a sensor

Screenshots

A tab is open in the browser IIOT Link - Windows Management using MQTT


image

A tab is open in the browser YouTube


image

Sensor Code

#Browser. We are tracking the MainWindowTitle lines, from where we will pull out the word YouTube
  - platform: mqtt
    name: "IOT Link. PC Home. Browsers. MainWindowTitle"
    state_topic: "iotlink/workgroup/home/process-monitor/processes/browsers/sensor"
    value_template: "{{ value_json.MainWindowTitle }}"
    qos: 0

#Video player. Pulling out the status of the fullscreen mode
  - platform: mqtt
    name: "IOT Link. PC Home. Potplayer. FullScreen"
    state_topic: "iotlink/workgroup/home/process-monitor/processes/potplayer/sensor"
    value_template: "{{ value_json.FullScreen }}"
    qos: 0

#Игры. Pulling out the status of the fullscreen mode
  - platform: mqtt
    name: "IOT Link. PC Home. Games. FullScreen"
    state_topic: "iotlink/workgroup/home/process-monitor/processes/games/sensor"
    value_template: "{{ value_json.FullScreen }}"
    qos: 0

#Sensor. Pulls the YouTube word from the MainWindowTitle. Multiple title variants are used to catch the YouTube word
  - platform: template
    sensors:
      iotlink_pc_home_browser_opera_channel:
        friendly_name: "PC. Browsers. YouTube"
        icon_template: mdi:youtube
        value_template: >
            {% if "YouTube" in states("sensor.iot_link_pc_home_browsers_mainwindowtitle") %} YouTube
            {% else %} off
            {% endif %}

#Full-screen mode sensor for Potplayer
  - platform: template
    sensors:
      potplayer_fullscreen_mode:
        friendly_name: "PorPlayer. Full-screen mode"
        icon_template: mdi:theater
        value_template: >
            {% set potplayer = states("binary_sensor.home_potplayer") %}
            {% set potplayer_fullscreen = states("sensor.iot_link_pc_home_potplayer_fullscreen")%}
            {% if potplayer == 'on' and potplayer_fullscreen == 'True' %} on
            {% else %} off
            {% endif %}

#Fullscreen mode sensor for YouTube
  - platform: template
    sensors:
      youtube_fullscreen_mode:
        friendly_name: "YouTube. Full-screen mode"
        icon_template: mdi:youtube
        value_template: >
            {% set youtube = states("sensor.iotlink_pc_home_browser_opera_channel") %}
            {% set browsers_fullscreen = states("binary_sensor.home_browsers_fullscreen") %}
            {% if youtube == 'YouTube' and browsers_fullscreen == 'on' %} on
            {% else %} off
            {% endif %}


#Full-screen mode sensor for games
  - platform: template
    sensors:
      game_fullscreen_mode:
        friendly_name: "Game. Full-screen mode"
        icon_template: mdi:google-controller
        value_template: >
            {% set game = states("binary_sensor.home_games") %}
            {% set game_fullscreen = states("sensor.iot_link_pc_home_games_fullscreen") %}
            {% if game == 'on' and game_fullscreen == 'True' %} on
            {% else %} off
            {% endif %}



Текст на русском (Text in Russian)

Создаем сенсор, что в браузере открыт YouTube

Как я автоматизировал Hyperion с помощью IOT Link

Поделюсь вариантом как можно создать сенсор того, что мы смотрим на компьютере YouTube. Зачем это нужно? Есть такая интеграция, называется Hyperion, она позволяет захватывать изображение и передавать цвета на адресные светодиоды. Я сделал автоматическое включение\выключение Hyperion при запуске игр или при включении полноэкранного режима в браузере. Но есть одно но, если я включаю в браузере полноэкранные режим, то Hyperion включится, а мне это не нужно, так как мне нужно, чтобы он включался, если я смотрю YouTube в полноэкранном режиме. Так вот, создав такой сенсор, мы исключаем авто включение Hyperion при включении полноэкранного режима в другой вкладе, только при просмотре YouTube

Если посмотреть json в mqtt, то мы видим следующее и нас интересует строка “MainWindowTitle”, которую будем использовать в сенсоре. Строка “MainWindowTitle” выводит информацию, какую страницу мы открыли в браузере и можем выдергивать ключевые слова, в нашем случае это YouTube

Данные в MQTT Explorer
{
  "Id": "12852",
  "SessionId": "6",
  "ProcessName": "opera",
  "StartDateTime": "2021-12-09 18:29:45",
  "Uptime": "00:03:05:19",
  "MemoryUsed": "735",
  "ProcessorUsage": "1,34",
  "MainWindowTitle": "More Real 12K HDR 60FPS Dolby Vision - YouTube - Opera",
  "FullScreen": "False",
  "Status": "Running",
  "Windows": [
    "More Real 12K HDR 60FPS Dolby Vision - YouTube - Opera",
    "Chrome Legacy Window",
    "Chrome Legacy Window"
  ],
  "ClassNames": [
    "Chrome_WidgetWin_1",
    "Chrome_RenderWidgetHostHWND",
    "Chrome_RenderWidgetHostHWND"
  ]
}

Создаем такой сенсор

Скриншоты

В браузере открыта вкладка IIOT Link - Windows Management using MQTT


image

В браузере открыта вкладка YouTube


image

Код сенсора
sensor:
#Браузер. Отслеживаем строки MainWindowTitle, откуда будем выдергивать слово YouTube
  - platform: mqtt
    name: "IOT Link. PC Home. Browsers. MainWindowTitle"
    state_topic: "iotlink/workgroup/home/process-monitor/processes/browsers/sensor"
    value_template: "{{ value_json.MainWindowTitle }}"
    qos: 0


#Видеоплеер. Выдергиваем статус полноэкранного режима
  - platform: mqtt
    name: "IOT Link. PC Home. Potplayer. FullScreen"
    state_topic: "iotlink/workgroup/home/process-monitor/processes/potplayer/sensor"
    value_template: "{{ value_json.FullScreen }}"
    qos: 0

#Игры. Выдергиваем статус полноэкранного режима
  - platform: mqtt
    name: "IOT Link. PC Home. Games. FullScreen"
    state_topic: "iotlink/workgroup/home/process-monitor/processes/games/sensor"
    value_template: "{{ value_json.FullScreen }}"
    qos: 0

#Сенсор. Выдергивает из MainWindowTitle слово YouTube. Используется несколько вариантов title, чтобы поймать слово YouTube
  - platform: template
    sensors:
      iotlink_pc_home_browser_opera_channel:
        friendly_name: "ПК. Браузер Опера. YouTube"
        icon_template: mdi:youtube
        value_template: >
            {% if "YouTube" in states("sensor.iot_link_pc_home_browsers_mainwindowtitle") %} YouTube
            {% else %} off
            {% endif %}

#Сенсор полноэкранного режима для PorPlayer
  - platform: template
    sensors:
      potplayer_fullscreen_mode:
        friendly_name: "PorPlayer. Полноэкранный режим"
        icon_template: mdi:theater
        value_template: >
            {% set potplayer = states("binary_sensor.home_potplayer") %}
            {% set potplayer_fullscreen = states("sensor.iot_link_pc_home_potplayer_fullscreen")%}
            {% if potplayer == 'on' and potplayer_fullscreen == 'True' %} on
            {% else %} off
            {% endif %}

#Сенсор полноэкранного режима для YouTube
  - platform: template
    sensors:
      youtube_fullscreen_mode:
        friendly_name: "YouTube. Полноэкранный режим"
        icon_template: mdi:youtube
        value_template: >
            {% set youtube = states("sensor.iotlink_pc_home_browser_opera_channel") %}
            {% set browsers_fullscreen = states("binary_sensor.home_browsers_fullscreen") %}
            {% if youtube == 'YouTube' and browsers_fullscreen == 'on' %} on
            {% else %} off
            {% endif %}


#Сенсор полноэкранного режима для игр
  - platform: template
    sensors:
      game_fullscreen_mode:
        friendly_name: "Игра. Полноэкранный режим"
        icon_template: mdi:google-controller
        value_template: >
            {% set game = states("binary_sensor.home_games") %}
            {% set game_fullscreen = states("sensor.iot_link_pc_home_games_fullscreen") %}
            {% if game == 'on' and game_fullscreen == 'True' %} on
            {% else %} off
            {% endif %}
1 Like

Hi is it Possible to open an windows Shortcut with the Run Command?

I use an vbs Script to change the pc colors or copy some files. At the moment i use Assistant Computer Control where i can open Shortcuts , but this works over dropbox with an delay.

So i try to open a file called “green.lnk” but it dont work, it only works with .exe or .bat files.

Someone knows how i could fix that?

Thx in advance

Now i have also installed iotlink, it works great on Windows 11.on my PC i would also show my dashboard,monitor turn Off Skript work, now i will automated this with a Hue Motion Sensor, they should trigger display on when Motion, and after 10 Min turn Off and so on. How i can do that? Thanks for Help and Merry Christmas

Hi, I’m a bit stuck and I can’t find what’s not working.

  • My mqtt broker works and I’m using it for various automations
  • Software installed (in admin), all seems to work
  • MQTT explorer shows lots of messages from my PC
  • But Home Assistant fails to get anything working

In Home Assistant:
image

One example of how I am calling it from HA:

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

Any suggestions?

Can’t see anything wrong here. But I do have a few questions.

  1. Why not just use MQTT Discovery?
  2. There is no need to have value_template on this example, because without a template the state is a string of whatever is published to that topic.
1 Like

Thanks. I went down the rabit hole of checking everything and I realized that my mosquito broker in integration in home assistant was… wrong. I used Nodered as a standard so I never thought about checking there. It works now. Thanks!
image

1 Like

Hello. I am still looking a way to open chrome in incognito. I have tried creating a shortcut and editing the shortcut properties, but does not work.

Hi!
Is it possible to unlock the computer from the lock state?
I got the lock command working but I would love to unlock it aswell.

Thanks

Hi, I haven’t found a software solution but this will work: ESPHome Ducky - USB Keystroke-Injection

Can you please share the 2 scripts ? Thanks in advance !

I see a lot of comments about sensors going ‘Unavailable’ and I don’t know for certain whether this resolves it but I don’t seem to have any issues anymore since I changed the cleanSession: true option to false in the configuration file of the iotlink service. I’m curious if others find positive results with this.

Also I should mention that I have my pc set to hibernate automatically when I fall asleep as well as a task to restart the service every time that happens, so the running time of this being successful has never been tested to more than ~18h. To have it restart after hibernation one would need a batch script with

SC stop iotlink
Timeout 5 /nobreak
SC start iotlink

And have the script run with task scheduler as explained here

IOT Link - v2.2.2
Windows 10 Pro 20H2 19042.1466

Tell me how to take out the Windows volume level sensor? In IOTLink I don’t see this volume level sensor, where is it? I specified different media options in the config, but there is no volume level in the topics.

It mentions the Media sensor, where is it? Where should I point it?

Here I specified Media, but I don’t see the media topic in the topics
image

image

Audio monitoring was removed in 2.2.0 due to a memory leak in the library used. See the release notes on v2.2.0 · IOT Link / IOT Link Service · GitLab
You’d have to use the version before that and use some scripts to restart the service to deal with the memory leak - which is a hack and a half.
It would make more sense to switch over to hass workstation service. It has various volume sensors, full media control, and can detect if webcam and mic are in use and by which process: GitHub - sleevezipper/hass-workstation-service: Provide useful sensors and services from your workstation to Home Assistant.
It also has an example on how to set up a media player entity to control your pc: hass-workstation-service/Commands.md at 7fd20a4fc5718fcd5960e318ab81186b073af82d · sleevezipper/hass-workstation-service · GitHub

3 Likes

+1 on the Hass workstation service. I switched over to it during the holidays and have been very happy. There is also a custom component that builds upon sleevezipper’s great work. I don’t need the notifications, etc so I use the original but the component looks fantastic and the developer is very active…even has a discord channel for support and testing.

3 Likes

Nice! Had not seen the hass agent yet but looks good. Know what I’ll be doing this weekend :slight_smile: