HomeAssistant can't handle Unicode characters in state

I was writing an AutoHotKey script that uses mosquitto_pub to publish the current active window title on my desktop to HA. Everything works great until I pull up a window that has a Unicode character in the name. An excellent example of this is the “Overview – Home Assistant” title on the dashboard of HA (the dash is “EN DASH” U+2013). When one of these titles is published, I see the proper values in the broker using MQTT Explorer, however the state never updates in HA. Non-unicode-containing titles work fine.

Is this a known issue or am I misconfiguring the sensor somehow?

Update: I did find this in the debug logs for MQTT:
2023-01-25 08:43:08.504 WARNING (MainThread) [homeassistant.components.mqtt.client] Can't decode payload b'Overview \x96 Home Assistant - Brave' on mosquitto/<redacted>/<redacted>/activewindow with encoding utf-8 (for <Job HassJobType.Callback <function MqttSensor._prepare_subscribe_topics.<locals>.message_received at 0x7fa3c5905d80>>)

So at least that’s a confirmation that it doesn’t like the UTF-8 character. Still not sure how to resolve this though.

Nevermind! Figured it out. I had to change the character encoding within the AHK code. Here’s the relevant snippet:

...
	WinGetActiveTitle, MyWinTitle
	ActiveWindow := MyWinTitle
	vSize := StrPut(MyWinTitle, "UTF-8")
	VarSetCapacity(vUtf8, vSize)
	vSize := StrPut(MyWinTitle, &vUtf8, vSize, "UTF-8")
	MyWinTitleUTF8 := % StrGet(&vUtf8, "CP0")
	RunWait, %ComSpec% /c ""C:\Program Files\mosquitto\mosquitto_pub.exe" -h <redacted> -u <redacted> -P <redacted>-t mosquitto/<redacted>/<redacted>/activewindow -m "%MyWinTitleUTF8%"" ,,Hide
...

Follow-up to this for any Googlers out there that happen upon this… Here’s the final product: GitHub - muchtall/ActiveWindowMQTT: Report the active window to a HomeAssistant MQTT Broker as a sensor