Are you running hassio on that raspberry pi? If so I recommend using a separate one, or perhaps a nodemcu or arduino to control the TV rotation separately. This might be easier in the long run, will allow you to keep your hassio machine away from the TV, and will make it easier to add new similar devices in the future.
I recommend using mqtt to communicate between the motor controller and hassio. You might be able to draw a lot of inspiration from motorized window blinds. Take a look at this thread and the ones linked to it: Esp8266 Window Blinds MQTT
If you decide to use my recommended approach of mqtt + arduino, the first tasks for you are probably to get an mqtt broker running (most people use mosquitto, look up bruh’s videos on YouTube), and figuring out how to control your motor with the arduino /nodemcu / whatever, before you start controlling it through mqtt / home assistant.
P. S. When I first read this thread, I thought you wanted to rotate your TV from landscape to portrait and thought you were crazy. 