IOT Link - Windows Management using MQTT

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