Hey i require help with how to implement a python code that require a win32com library installed into home assistant

hey i wrote this code that can tell me what display im using and i want that when i use certain display the lights will go on and when i use the other one lights will go off my problem is that i cant install the library to the add on and im having trouble to understand how to connect visual studio code on my desktop to home assistant and i tried to find solutions in google but didnt find any im kinda newbie in programming and home assistant

this is the code:

import win32api
monitors = win32api.EnumDisplayMonitors()
win32api.GetMonitorInfo(monitors[0][0])
info = win32api.GetMonitorInfo(monitors[0][0])


if info == {'Monitor': (0, 0, 1707, 960),
'Work': (0, 0, 1707,960),
'Flags': 1,
'Device': '\\\\.\\DISPLAY1'}:
    print("DISPLAY 1 on")
else:
    print("DISPLAY 4 on")

thanks in advance.

I doubt this can work the way you imagine. The code you have runs locally on your computer. There the win32api is able to detect the displays. But I assume HA is running on a different machine. So even if you manage to import the library (which probably isn’t possible - it doesn’t sound like you’re running HA on Windows), it wouldn’t detect the displays since they’re obviously connected to a different machine.
Of course I might just have missed some details about your setup. But at first glance I don’t think your plans can work this way.

Instead you’d need some kind of service running on your Windows-machine, which HA can query periodically, or which sends out such information via MQTT so HA can react on it.

1 Like

oh i see my home assistant is installed on raspberry pi so i didnt think of that thanks for the reply ill try to figure this out

Use:
How to import from package not installed on hassio