LAB02-Research / HASS.Agent

Windows-based client for Home Assistant. Provides notifications, quick actions, commands, sensors and more.
https://hassagent.lab02-research.org
MIT License
1.54k stars 67 forks source link

Bug: mediaplaypause not working #229

Open broyuken opened 1 year ago

broyuken commented 1 year ago

Please make sure your bug isn't already listed on HASS.Agent's issue tracker:

https://lab02research.youtrack.cloud/

There's a list of open bugs & features on the right. On the left you can see what's being worked on, what's planned and what's ready for the next release.

If you're not sure, don't worry, just go ahead and we'll discuss :)


Describe the bug A clear and concise description of what the bug is. I have mediaplaypause set as a command, but when I click it through the HA interface I hear the MS Teams ringtone instead of my youtube or spotify being paused.

To Reproduce Steps to reproduce the behavior:

  1. create a command using the mediaplaypause type
  2. either click on it from within HA or set it as a quick action
  3. play a youtube video or spotify
  4. click the button
  5. media doesn't pause

Expected behavior A clear and concise description of what you expected to happen. media pauses Screenshots If applicable, add screenshots to help explain your problem.

Misc info (please complete the following information):

Please check what's applicable (multiple answers possible):

Additional context Add any other context about the problem here.

Logs If possible, please provide the logs of HASS.Agent and - if applicable - the Satellite Service. You can find HASS.Agent's logs by going to the main window, then Configuration -> Logging -> open logs folder. The Satellite Service's logs are in the same window, but the Satellite Service tab -> open service logs folder. If you want, you can mail them to lab02research@outlook.com

2022-12-09 15:05:52.776 -05:00 [INF] [MAIN] HASS.Agent version: 2022.14.0
2022-12-09 15:05:52.784 -05:00 [INF] [SETTINGS] Config storage path: D:\Users\broy\AppData\Roaming\LAB02 Research\HASS.Agent\config
2022-12-09 15:05:53.078 -05:00 [INF] [SETTINGS] Configuration loaded
2022-12-09 15:05:53.082 -05:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2022-12-09 15:05:53.792 -05:00 [INF] [SETTINGS_QUICKACTIONS] Loaded 1 entities
2022-12-09 15:05:53.824 -05:00 [INF] [SETTINGS_COMMANDS] Loaded 3 entities
2022-12-09 15:05:53.859 -05:00 [INF] [SETTINGS_SENSORS] Loaded 3 entities
2022-12-09 15:05:53.867 -05:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2022-12-09 15:05:53.970 -05:00 [INF] [MQTT] Identifying as device: LINK
2022-12-09 15:05:54.084 -05:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2022-12-09 15:05:54.685 -05:00 [INF] [LOCALAPI] Disabled
2022-12-09 15:05:54.688 -05:00 [INF] [MQTT] Connecting ..
2022-12-09 15:05:54.851 -05:00 [INF] [MQTT] Connected
2022-12-09 15:05:55.061 -05:00 [INF] [HASS_API] Home Assistant version: 2022.12.1
2022-12-09 15:05:55.180 -05:00 [INF] [MEDIA] Ready
2022-12-09 15:05:55.216 -05:00 [INF] [NOTIFIER] Ready
2022-12-09 15:05:55.847 -05:00 [INF] [HASS_API] System connected with https://ha.broyuken.com
2022-12-09 15:05:56.712 -05:00 [INF] [MQTT] Initial registration completed
2022-12-09 15:07:42.524 -05:00 [INF] [SETTINGS] Configuration stored
2022-12-09 15:07:44.659 -05:00 [INF] [SYSTEM] Application shutting down
2022-12-09 15:07:44.664 -05:00 [INF] [MQTT] Disconnected
2022-12-09 15:07:44.768 -05:00 [INF] [SYSTEM] Application shutdown complete
2022-12-09 15:07:46.880 -05:00 [INF] [MAIN] HASS.Agent version: 2022.14.0
2022-12-09 15:07:46.888 -05:00 [INF] [SETTINGS] Config storage path: D:\Users\broy\AppData\Roaming\LAB02 Research\HASS.Agent\config
2022-12-09 15:07:47.028 -05:00 [INF] [SETTINGS] Configuration loaded
2022-12-09 15:07:47.032 -05:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2022-12-09 15:07:47.311 -05:00 [INF] [SETTINGS_QUICKACTIONS] Loaded 1 entities
2022-12-09 15:07:47.326 -05:00 [INF] [SETTINGS_COMMANDS] Loaded 3 entities
2022-12-09 15:07:47.338 -05:00 [INF] [SETTINGS_SENSORS] Loaded 3 entities
2022-12-09 15:07:47.343 -05:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2022-12-09 15:07:47.344 -05:00 [INF] [MQTT] Identifying as device: LINK
2022-12-09 15:07:47.344 -05:00 [INF] [LOCALAPI] Disabled
2022-12-09 15:07:47.352 -05:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2022-12-09 15:07:47.359 -05:00 [INF] [MQTT] Connecting ..
2022-12-09 15:07:47.430 -05:00 [INF] [MQTT] Connected
2022-12-09 15:07:47.523 -05:00 [INF] [HASS_API] Home Assistant version: 2022.12.1
2022-12-09 15:07:47.545 -05:00 [INF] [MEDIA] Ready
2022-12-09 15:07:47.624 -05:00 [INF] [NOTIFIER] Ready
2022-12-09 15:07:48.173 -05:00 [INF] [HASS_API] System connected with https://ha.broyuken.com
2022-12-09 15:07:49.366 -05:00 [INF] [MQTT] Initial registration completed
2022-12-09 15:26:30.760 -05:00 [INF] [SETTINGS] Configuration stored
2022-12-09 15:26:33.383 -05:00 [INF] [SYSTEM] Application shutting down
2022-12-09 15:26:33.391 -05:00 [INF] [MQTT] Disconnected
2022-12-09 15:26:33.429 -05:00 [INF] [SYSTEM] Application shutdown complete
2022-12-09 15:26:35.646 -05:00 [INF] [MAIN] HASS.Agent version: 2022.14.0
2022-12-09 15:26:35.650 -05:00 [INF] [MAIN] Extended logging enabled
2022-12-09 15:26:35.655 -05:00 [INF] [SETTINGS] Config storage path: D:\Users\broy\AppData\Roaming\LAB02 Research\HASS.Agent\config
2022-12-09 15:26:35.802 -05:00 [INF] [SETTINGS] Configuration loaded
2022-12-09 15:26:35.806 -05:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2022-12-09 15:26:36.137 -05:00 [INF] [SETTINGS_QUICKACTIONS] Loaded 1 entities
2022-12-09 15:26:36.152 -05:00 [INF] [SETTINGS_COMMANDS] Loaded 3 entities
2022-12-09 15:26:36.165 -05:00 [INF] [SETTINGS_SENSORS] Loaded 3 entities
2022-12-09 15:26:36.170 -05:00 [INF] [MQTT] Identifying as device: LINK
2022-12-09 15:26:36.170 -05:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2022-12-09 15:26:36.171 -05:00 [INF] [LOCALAPI] Disabled
2022-12-09 15:26:36.175 -05:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2022-12-09 15:26:36.183 -05:00 [INF] [MQTT] Connecting ..
2022-12-09 15:26:36.370 -05:00 [INF] [HASS_API] Home Assistant version: 2022.12.1
2022-12-09 15:26:36.394 -05:00 [INF] [MEDIA] Ready
2022-12-09 15:26:36.441 -05:00 [INF] [MQTT] Connected
2022-12-09 15:26:36.446 -05:00 [INF] [MEDIA] Now playing: dutchavelli - Black
2022-12-09 15:26:36.527 -05:00 [INF] [NOTIFIER] Ready
2022-12-09 15:26:36.531 -05:00 [INF] [MEDIA] New state: Paused
2022-12-09 15:26:37.109 -05:00 [INF] [HASS_API] System connected with https://ha.broyuken.com
2022-12-09 15:26:38.200 -05:00 [INF] [MQTT] Initial registration completed
broyuken commented 1 year ago

Hello, checking in to see if anyone can take a look at this.

LAB02-Admin commented 1 year ago

Hi @broyuken, sorry for the late reply - been really busy with work lately.

What it does is simply emulate a mediakey press, eg. the same buttons you find on (most) keyboards. So there's a problem with those key bindings, it seems like Teams has somehow binded to them.

You can make these commands for easy testing (they use the same code):

image

If they don't work either, could you check whether the keyboard keys work? Do you use a tool like AutoHotKey?

broyuken commented 1 year ago

Hi, I did some testing and the media next and previous commands do not work either. The physical keyboard buttons do work however.

The odd thing is, if I close teams I still am not able to play/pause. But when I have spotify up and I hit play/pause I can see the play button kind of pulse like its being clicked, but the state doesn't change. It stays paused.

I'm not sure if there were some changes in Win11 that make the behavior different as I just started using your tool. Previously I was using a script I made which recently stopped working which would pause media and hit Ctrl + F12. The Ctrl + F12 portion still works, but the media keys no longer do. I wonder if the keyboard shortcut changed with a recent Win11 update or something.

My script:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys (chr(&hB3))
WshShell.SendKeys "^{F12}"
broyuken commented 1 year ago

Not sure what changed, but it works through HA now but doesn't work through quick actions.

broyuken commented 1 year ago

and now today its not working again

broyuken commented 1 year ago

After more testing, teams must be doing something because I close teams and it works again. Then I can open teams again and it continues to work. Must be some sort of race condition where it steals the media keys.

brentk7 commented 1 year ago

I'm seeing a similar issue to this - play/pause does not work but other media commands do (previous, next, volume, etc.). When pressing Play or Pause in HA media player media does not play or pause - HA logbook shows state change, but then immediately changes to previous state. HASS.Agent logs show the Play / pause commands.

I tried creating a command button as suggested above and this also does not work. HA Logbook and HASS.Agent logs show nothing when pressing the created button, but "MQTT explorer" shows when the button is pressed.

Keyboard Play/Pause button works as expected. Testing with Spotify desktop

luke-barnett commented 1 year ago

I'm not getting any luck in this space either.

Currently playing media is showing up fine, but the controls to play/pause, next etc. are not working from both the media player as well as when I create them as actions.

Of note, the volume control is working as expected.

broyuken commented 1 year ago

If you run teams, or something else for conferences try quitting it and see if it works.

brentk7 commented 1 year ago

I do have Teams installed - but did make sure it was closed when trying as per the suggestions above.

Turtlepaw commented 1 year ago

I closed Teams too, it receives commands but doesn't play/pause the media, I tested with both YouTube and Tidal:

2023-04-22 12:51:17.457 -04:00 [INF] [SERVICE] Local install path: C:\Program Files (x86)\LAB02 Research\HASS.Agent Satellite Service\
2023-04-22 12:51:17.458 -04:00 [INF] [MQTT] Identifying as device: PC
2023-04-22 12:51:17.460 -04:00 [INF] [HASS_API] Connecting using automatic client certificate selection
2023-04-22 12:51:17.461 -04:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2023-04-22 12:51:17.466 -04:00 [INF] [MQTT] Connecting ..
2023-04-22 12:51:17.516 -04:00 [INF] [MQTT] Connected
2023-04-22 12:51:17.596 -04:00 [INF] [MEDIA] Ready
2023-04-22 12:51:17.614 -04:00 [INF] [NOTIFIER] Ready
2023-04-22 12:51:17.632 -04:00 [INF] [MEDIA] Now playing: Calvin Harris - How Deep Is Your Love
2023-04-22 12:51:17.668 -04:00 [INF] [MEDIA] New state: Playing
2023-04-22 12:51:17.785 -04:00 [INF] [LOCALAPI] listening on port 5115
2023-04-22 12:51:19.501 -04:00 [INF] [MQTT] Initial registration completed
2023-04-22 12:51:20.293 -04:00 [INF] [HASS_API] Home Assistant version: 2023.4.4
2023-04-22 12:51:20.529 -04:00 [INF] [HASS_API] System connected with http://homeassistant.local:8123
2023-04-22 12:51:29.797 -04:00 [INF] [MEDIA] Command received: Pause
2023-04-22 12:51:30.753 -04:00 [INF] [MEDIA] Command received: Next
2023-04-22 12:51:31.817 -04:00 [INF] [MEDIA] Command received: Previous
2023-04-22 12:51:57.975 -04:00 [INF] [MEDIA] Now playing: Alok - Typical (feat. Lars Martin)
2023-04-22 12:52:11.302 -04:00 [INF] [MEDIA] Command received: Next
2023-04-22 12:52:14.737 -04:00 [INF] [MEDIA] Command received: Pause
2023-04-22 12:52:19.771 -04:00 [INF] [MEDIA] Command received: Pause
2023-04-22 12:52:20.424 -04:00 [INF] [MEDIA] Command received: Next
2023-04-22 12:52:20.946 -04:00 [INF] [MEDIA] Command received: Previous
2023-04-22 12:52:38.344 -04:00 [INF] [MEDIA] Now playing: Now, Now - MJ
2023-04-22 12:53:10.185 -04:00 [INF] [MEDIA] Command received: Pause