This custom integration allows you to manage PC devices in Home Assistant, treating them as first-class entities similar to lights or media players. It supports turning the PC on/off, setting volume, muting, locking, and integrates with Microsoft Family Safety for hard lockouts.
It creates a composite device from https://github.com/LAB02-Research/HASS.Agent sensors and buttons. Optionally it can also lockout using https://github.com/pantherale0/ha-familysafety instead of power on/off.
- Creates a
pcdomain with entities likepc.emmalaptopandpc.fredspc. - Supports standard services:
turn_on,turn_off. - Custom services:
pc.set_volume,pc.mute,pc.lock. - Exposes attributes:
volume_level,activewindow,sessionstate. - Optional integration with Microsoft Family Safety for hard lockouts instead of power off.
- Configurable via the Home Assistant Integrations page.
-
Ensure you have HACS installed in Home Assistant.
-
Click the button below to add the repository to HACS:
-
In HACS, search for "PC Device" and install the integration.
-
Restart Home Assistant.
- Copy the
pcfolder to your Home Assistantcustom_componentsdirectory - Restart Home Assistant.
This integration requires the following Home Assistant entities for Family Safety integration (if enabled):
switch.emma_block_windows: Switch to block Windows access.switch.emma_block_xbox: Switch to block Xbox access.sensor.emma_available_balance: (Optional) Sensor for available screen time balance.sensor.emma_used_screen_time: (Optional) Sensor for used screen time.
switch.fred_block_windows: Switch to block Windows access.switch.fred_block_xbox: Switch to block Xbox access.sensor.fred_available_balance: (Optional) Sensor for available screen time balance.sensor.fred_used_screen_time: (Optional) Sensor for used screen time.
These entities are typically provided by the Microsoft Family Safety integration. Ensure it is set up and the Family Safety names match the ones you configure in this integration.
- Go to Settings > Devices & Services > Integrations in Home Assistant.
- Click + Add Integration and search for "PC Device".
- Configure the PC device:
- Device Name: The name of the PC (e.g.,
emmaLaptop,FredPC). This will create an entity likepc.emmalaptop. - Family Safety Name: (Optional) The Family Safety name (e.g.,
emma,Neural). This is used to construct the Family Safety switch entity IDs (e.g.,switch.emma_block_windows). - Use Family Safety Lock: (Optional) If enabled, turning off the PC will activate the Family Safety block switches instead of a power-off action. Turning on will deactivate them.
- Submit the configuration.
- Repeat for additional PCs (e.g.,
emmaLaptopandFredPC).
- Entities: After setup, you’ll have entities like
pc.emmalaptopandpc.fredpc. - State: The entity state is
onoroff. - Attributes:
volume_level: The volume level (0.0 to 1.0).activewindow: The currently active window (e.g., "Notepad").sessionstate: The session state (e.g., "unlocked", "locked").
- Services:
pc.set_volume: Set the volume (e.g.,{"entity_id": "pc.emmalaptop", "volume_level": 0.5}).pc.mute: Mute or unmute the PC.pc.lock: Lock the PC.switch.turn_on/switch.turn_off: Turn the PC on or off.
The integration uses the following MQTT topics for communication:
- Set Command:
homeassistant/PC/PC.<DeviceName>/set(e.g.,homeassistant/PC/PC.emmaLaptop/set)- Payload:
ONorOFF
- Payload:
- Set Volume:
homeassistant/PC/PC.<DeviceName>/setvolume(e.g.,homeassistant/PC/PC.emmaLaptop/setvolume)- Payload: Volume level (0 to 100, scaled to 0.0-1.0 internally)
- Mute:
homeassistant/PC/PC.<DeviceName>/mute(e.g.,homeassistant/PC/PC.emmaLaptop/mute)- Payload: Any (triggers mute action)
- Lock:
homeassistant/PC/PC.<DeviceName>/lock(e.g.,homeassistant/PC/PC.emmaLaptop/lock)- Payload: Any (triggers lock action)
- State Update:
homeassistant/PC/PC.<DeviceName>/update(e.g.,homeassistant/PC/PC.emmaLaptop/update)- Payload: JSON with
entity_id,state,volume_level,activewindow,sessionstate
- Payload: JSON with
For emmaLaptop and FredPC:
- Add
emmaLaptop:
- Device Name:
emmaLaptop - Family Safety Name:
emma - Use Family Safety Lock:
True
- Add
FredPC:
- Device Name:
FredPC - Family Safety Name:
Neural - Use Family Safety Lock:
True
This will create pc.emmalaptop and pc.fredpc entities, and turning them off will activate the corresponding Family Safety block switches (e.g., switch.emma_block_windows, switch.fred_block_xbox).
This integration works seamlessly with Node-RED flows that use MQTT to control devices. Ensure your Node-RED flow:
- Subscribes to the
updatetopic to receive state updates. - Publishes to the
set,setvolume,mute, andlocktopics to control the PC. - Uses the
pcdomain for service calls (e.g.,pc.set_volume,pc.mute,pc.lock).
Feel free to submit issues or pull requests to improve this integration!
MIT License