This is my personal fork of dlsniper's clone of HeedfulCrayon's original script. This fork is not affiliated with or endorsed by the previous/original authors, but I thank them for their helpful foundations that have made my little version of this script possible.
- Original work and copyrighted by @HeedfulCrayon
- Virtual Camera support added by @dlsniper
- This fork by @gritting:
- New "model name" option for MQTT config, useful for identifying the machine running the script in Home Assistant.
- New script defaults: Updated to include changes like MQTT base topic and username settings.
- Minor bug fixes and improvements (see commit history for full details)
- Tested with: OBS Studio 30.2.1-1 and Home Assistant 2024.11.1
- Download the script
- Install
mqtt-wrapper
by runningpip install mqtt-wrapper
- Open OBS Studio:
- Add a script (Tools -> Scripts)
- Configure Parameters: The default base channel is
homeassistant
, and default sensor name isobs_state
. This will create a path likehomeassistant/sensor/obs_state
. Make sure you set all of your config options before setting the password to prevent unintentionally sending the wrong base topic/sensor name. - Click the script refresh button to load the script.
-
If you have enabled MQTT Autodiscovery in Home Assistant: you should see sensors for recording, streaming, virtual camera, and profile controls automatically appear under your MQTT integration.
-
You can check if the topic appears as expected in your broker with a tool like MQTT Explorer.
- **You must add manual configuration if MQTT Autodiscovery is not turned on, similar to below:
-
Sensor Configuration:
- platform: "mqtt" name: "OBS State" state_topic: "obs_state/state" icon: "mdi:video-wireless" force_update: true qos: 1 json_attributes_topic: "obs_state/attributes"
-
Switch for Controlling Recording:
- platform: "mqtt" name: OBS Record Switch state_topic: "homeassistant/switch/obs_state/record/state" command_topic: "homeassistant/switch/obs_state/record/set" available_topic: "homeassistant/switch/obs_state/record/available" payload_on: "ON" payload_off: "OFF" icon: mdi:record
-
Switch for Controlling Streaming:
- platform: "mqtt" name: OBS Stream Switch state_topic: "homeassistant/switch/obs_state/stream/state" command_topic: "homeassistant/switch/obs_state/stream/set" available_topic: "homeassistant/switch/obs_state/stream/available" payload_on: "ON" payload_off: "OFF" icon: mdi:broadcast
-
Switch for Controlling Virtual Camera
- platform: "mqtt" name: OBS Virtual Camera Switch state_topic: "homeassistant/switch/obs_state/virtual_camera/state" command_topic: "homeassistant/switch/obs_state/virtual_camera/set" available_topic: "homeassistant/switch/obs_state/virtual_camera/available" payload_on: "ON" payload_off: "OFF" icon: mdi:camera-wireless
-
Switch for Controlling Profiles (add one switch per profile):
- platform: "mqtt" name: OBS Test Profile state_topic: "homeassistant/switch/profile_name/state" command_topic: "homeassistant/switch/profile_name/profile/set" payload_on: "ON" payload_off: "OFF" icon: mdi:alpha-p-box
-
- Recording
- Streaming
- Streaming and Recording
- Virtual Camera
- Stopped (OBS Open)
- Off (OBS Closed)
If you update the script while autodiscovery is enabled, remove the following topics to avoid duplicates showing up in the Home Assistant MQTT integration. You can use a tool like MQTT Explorer to delete these topics from your broker easily.
homeassistant/sensor/obs_state/config
for sensor state.homeassistant/switch/obs_state_stream/config
for stream switch.homeassistant/switch/obs_state_record/config
for record switch.homeassistant/switch/obs_state_virtual_camera/config
for virtual