Artificial intelligence created this guide! Will it work if I have both a light and a switch?
Guide: Modifying ha-artnet-led for Switches
Overview
This guide will help you modify the custom ha-artnet-led integration to create switch entities instead of light entities for your DH4 DALI/DMX board.
Step 1: Locate Integration Files
The integration is located in:
/config/custom_components/artnet_led/
Important files:
__init__.py - integration initialization
light.py - light platform (where we’ll make the main modifications)
manifest.json - integration information
Step 2: Create switch.py File
2.1 Copy light.py to switch.py
You can do this through File Editor or SSH:
cd /config/custom_components/artnet_led/
cp light.py switch.py
2.2 Modify switch.py
Open switch.py and make the following changes:
A) Change imports at the beginning:
Find:
from homeassistant.components.light import (
LightEntity,
ATTR_BRIGHTNESS,
# other imports...
)
Replace with:
from homeassistant.components.switch import SwitchEntity
from homeassistant.const import STATE_ON, STATE_OFF
B) Change base class:
Find:
class ArtNetLight(LightEntity):
Replace with:
class ArtNetSwitch(SwitchEntity):
C) Simplify methods:
Delete all methods related to brightness, color, effects, etc. and keep only:
@property
def is_on(self):
"""Return true if switch is on."""
return self._state
@property
def name(self):
"""Return the name of the switch."""
return self._name
async def async_turn_on(self, **kwargs):
"""Turn the switch on."""
await self._channel.set_fade(255, 0) # DMX value 255 = ON
self._state = True
self.async_write_ha_state()
async def async_turn_off(self, **kwargs):
"""Turn the switch off."""
await self._channel.set_fade(0, 0) # DMX value 0 = OFF
self._state = False
self.async_write_ha_state()
D) Modify async_setup_platform function:
Find:
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
Inside the function, find where entities are created and modify:
Find:
lights.append(ArtNetLight(...))
Replace with:
switches.append(ArtNetSwitch(...))
And change:
async_add_entities(lights)
To:
async_add_entities(switches)
Step 3: Modify __init__.py
Open __init__.py and add the switch platform.
Find:
PLATFORMS = ["light"]
Replace with:
PLATFORMS = ["light", "switch"]
Or if you want only switches (no lights):
PLATFORMS = ["switch"]
Step 4: Configure configuration.yaml
Option A: Switches Only
switch:
- platform: artnet_led
host: 192.168.1.XXX # DH4 board IP
max_fps: 25
universes:
0:
devices:
- channel: 1
name: "Relay 1"
type: binary
- channel: 2
name: "Relay 2"
type: binary
- channel: 3
name: "Relay 3"
type: binary
- channel: 4
name: "Relay 4"
type: binary
Option B: Both Light and Switch
Keep the existing light configuration and add:
switch:
- platform: artnet_led
host: 192.168.1.XXX
# ... similar config as above
Step 5: Restart and Testing
- Save all changes
- Restart Home Assistant: Settings → System → Restart
- Check Developer Tools → States for new entities
switch.relay_1, switch.relay_2, etc.
- Test each switch to verify that the relays activate correctly