![The resulting sensors in Home Assistant](https://i.imgur.com/1Yvx2Ea.png)
![The resulting sensors in Home Assistant](https://i.imgur.com/Kka8VOi.png)
## Installation
You can get the installer from [here](https://hassworkstationstorage.z6.web.core.windows.net/publish/setup.exe). When using the installer, the application checks for updates on startup.
You can get the installer from [here](https://hassworkstationstorage.z6.web.core.windows.net/publish/setup.exe). When using the installer, the application checks for updates on startup. This is the recommended way to install for most users.
Note: You'll get a Windows Smartscreen warning because the code was self signed. You can click "More info" and then "Run anyway" to proceed with installing.
If you don't want to use the installer, you can find releases on GitHub [here](https://github.com/sleevezipper/hass-workstation-service/releases). `hass-workstation-service.exe` is the background service and you can use `UserInterface.exe` to configure the service. If you don't use the installer autostart won't work.
### Standalone
You'll need [.NET 5 Runtime](https://dotnet.microsoft.com/download/dotnet/current/runtime) installed.
If you don't want to use the installer, you can find the standalone version releases on GitHub [here](https://github.com/sleevezipper/hass-workstation-service/releases). Unpack all files to a folder and run `hass-workstation-service.exe`. This is the background service and you can use `UserInterface.exe` to configure the service. There is no automatic (or prompted) updating in the standalone version.
### Updating
The app checks for updates on startup. If an update is available you will be prompted to install.
If you used the installer, the app checks for updates on startup. If an update is available you will be prompted to install. If you use the standalone, just delete all files from the previous install and unpack the zip to the same location as before.
## Sensors
The application provides several sensors. Sensors can be configured with a name and this name will be used in the MQTT topic like this: `homeassistant/sensor/{Name}/state`. Sensors will expose themselves through [MQTT discovery](https://www.home-assistant.io/docs/mqtt/discovery/) and will automatically appear in Home assistant or any other platform that supports this type of configuration.
The application provides several sensors. Sensors can be configured with a name and this name will be used in the MQTT topic like this: `homeassistant/sensor/{DeviceName}/{Name}/state`. Sensors will expose themselves through [MQTT discovery](https://www.home-assistant.io/docs/mqtt/discovery/) and will automatically appear in Home assistant or any other platform that supports this type of configuration.
Sensors publish their state on their own interval which you can configure and only publish when the state changes.
@ -54,6 +58,14 @@ This sensor watches the UserNotificationState. This is normally used in applicat
This sensor exposes the name of the currently focused window.
### WebcamActive
This sensor shows if the webcam is currently being used. It uses the Windows registry to check will work from Windows 10 version 1903 and higher.
### MicrophoneActive
This sensor shows if the microphone is currently being used. It uses the Windows registry to check and will work from Windows 10 version 1903 and higher.
### CPULoad
This sensor checks the current CPU load. It averages the load on all logical cores every second and rounds the output to two decimals.
@ -90,6 +102,25 @@ which results in `4008` for my PC.
You can use [WMI Explorer](https://github.com/vinaypamnani/wmie2/tree/v2.0.0.2) to find see what data is available.
### IdleTime
This sensor returns the amount of seconds the workstation has been idle for. It starts counting the moment you stop typing or moving your mouse.
### UpTime
This sensor returns theup time from Windows in seconds.
### SessionState
This sensor returns the current session state. It has the following possible states:
|State|Explanation|
|---|---|
|Locked|All user sessions are locked.|
|LoggedOff|No users are logged in.|
|InUse|A user is currently logged in.|
|Unknown|Something went wrong while getting the status.|
### Dummy
This sensor spits out a random number every second. Useful for testing, maybe you'll find some other use for it.
<TextBlock TextWrapping="Wrap" MaxWidth="300" FontStyle="Italic" IsVisible="{Binding ShowWindowNameInput}" Margin="0 0 0 10">This is case-insensitive and loosely matched. A window called "Spotify Premium" will match "spotify" or "premium".</TextBlock>
<TextBox IsVisible="{Binding ShowWindowNameInput}" Text="{Binding WindowName}" Watermark="Visual Studio Code" HorizontalAlignment="Left" MinWidth="300"/>
item.Description="This sensor watches the UserNotificationState. This is normally used in applications to determine if it is appropriate to send a notification but we can use it to expose this state. \n ";
item.Description="This sensor checks the current CPU load. It averages the load on all logical cores every second and rounds the output to two decimals.";
#pragma warning disable CA1416 // Validate platform compatibility. We ignore it here because this would never happen. A cleaner solution may be implemented later.
/// Enable or disable autostarting the background service. It does this by adding the application shortcut (appref-ms) to the registry run key for the current user
@ -4,10 +4,13 @@ using System.Collections.Generic;
usingSystem.Globalization;
usingSystem.Linq;
usingSystem.Management;
usingSystem.Runtime.Versioning;
usingSystem.Text;
namespacehass_workstation_service.Domain.Sensors
{
[SupportedOSPlatform("windows")]
publicclassCPULoadSensor:WMIQuerySensor
{
publicCPULoadSensor(MqttPublisherpublisher,int?updateInterval=null,stringname="CPULoadSensor",Guidid=default):base(publisher,"SELECT PercentProcessorTime FROM Win32_PerfFormattedData_PerfOS_Processor",updateInterval??10,name??"CPULoadSensor",id)
publicMemoryUsageSensor(MqttPublisherpublisher,int?updateInterval=null,stringname="WMIQuerySensor",Guidid=default):base(publisher,"SELECT FreePhysicalMemory,TotalVisibleMemorySize FROM Win32_OperatingSystem",updateInterval??10,name,id)
publicMemoryUsageSensor(MqttPublisherpublisher,int?updateInterval=null,stringname="MemoryUsage",Guidid=default):base(publisher,"SELECT FreePhysicalMemory,TotalVisibleMemorySize FROM Win32_OperatingSystem",updateInterval??10,name??"MemoryUsage",id)
varnumberOfUserDesktops=newManagementObjectSearcher(scope,newSelectQuery("select * from win32_Perfrawdata_TermService_TerminalServicesSession")).Get().Count-1;// don't count Service desktop