So, some Samsung TVs offer a control API over WebSocket. This is unfortunately not well documented (as far as I’ve been able to find). This is a quick and dirty dump of what I’ve been able to learn so far.
samsungctl
is a library and a command line tool for remote controlling Samsung televisions via a TCP/IP connection. It currently supports both pre-2016 TVs as well most of the modern Tizen-OS TVs with Ethernet or Wi-Fi connectivity
https://github.com/Ape/samsungctl
samsungctl --host <ip_of_tv> --name <name_of_controller> --port 8001 --method websocket KEY_MENU
https://github.com/vrachieru/samsung-tv-api
sudo npm i wscat -g
wscat -n -c wss://<ip_of_tv>:8002/api/v2/channels/samsung.remote.control?token=13675568
{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_VOLDOWN","Option":"false","TypeOfRemote":"SendRemoteKey"}}
{"method":"ms.channel.emit","params":{"event": "ed.installedApp.get", "to":"host"}}
https://npm.io/package/samsung-tizen
https://www.reddit.com/r/homeassistant/comments/fxddeh/controlling_a_samsung_tv/
https://github.com/avsokolov/tizen-remote
https://review.tizen.org/git/?p=platform/core/convergence/app-comm-svc.git;a=blob;f=MSF-Node/org.tizen.multiscreen/server/plugins/plugin-api-v2/channels/index.js;h=8d548dcdda4e9fd12a9d280e7ee4cc3199e8e967;hb=refs/heads/tizen_3.0
https://dzznzz70yhbz.cloudfront.net/index.html
https://github.com/jaruba/ha-samsungtv-tizen/blob/a644f2db4ba74865ac9b8a12425825aa8a3c3efd/Key_codes.md