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.56k stars 68 forks source link

Feature: ability to know if a display is off in a multimonitor setup #342

Open Shiroe93 opened 1 year ago

Shiroe93 commented 1 year ago

it would be possible to have a monior power state per display? i use multimonitor tool to turn on/off the display with scripts trigger from home assistant but without knowning if the display is on or of i can't create a switch because i don't have a value template so i'm searching a way to relay this info to home assistant

Shiroe93 commented 1 year ago

I think I've found a possible solution but I'm not sure how to implement it Using a power shell sensor that output a 0 every time the executable to turn off the monitor is run end a 1 every time the script to turn it on is run the problem is that I don't know how to write this sensor I've searched the docs but I wasn't able to find a template of the format I should be using Any help?

amadeo-alex commented 1 year ago

I'm not sure if there is a reliable way to tell when monitor in powered on or not. There are some WMI queries from what I've been able to find but they sometimes do work and sometimes don't. If you want to go with the powershell sensor to both do the action and then report "did it" you might as well set the state of some helper bool when it's executed.

Shiroe93 commented 1 year ago

I'm not sure if there is a reliable way to tell when monitor in powered on or not. There are some WMI queries from what I've been able to find but they sometimes do work and sometimes don't. If you want to go with the powershell sensor to both do the action and then report "did it" you might as well set the state of some helper bool when it's executed.

How can I do this? At the moment I created two executable one to turn on the monitor named "accendi monitor 2.exe" and one named "spegni monitor 2.exe"that turn it off but I've no idea on how to create a powershell sensor that changes every time one or the other is executed If you know can you please give me an example?

amadeo-alex commented 1 year ago

I don't think that is possible. Powershell sensor executes a command or script and returns its return value.