18 days ago
How to rewire Zigbee2MQTT Switches to Be Displayed as Lights in Home Assistant
If you're running Zigbee2MQTT (Z2M) version 2.0+ as a Home Assistant (HASS) addon and want to display your switches as lights in HASS, here's how I rewired my Aqara H1 light switches (no neutral, one single rocker, one double rocker) to achieve this.
Why Display Switches as Lights?
Displaying switches as lights in HASS makes them more intuitive to manage. For example, you can control them via light groups, use dimmer-style UI controls, or integrate them into "light" automations seamlessly.
My Setup
Devices
HASS Addon
Zigbee2MQTT running version 2.0+
Here’s the configuration I used to expose my switches as lights.
Single Rocker Configuration
The following configuration is for the Aqara H1 Single Rocker (Cinema Lightning Bolt Light):
devices:'0x04cf8cdf3c789bea':friendly_name: Cinema Lightning Bolt Lighthomeassistant:switch:type: lightschema: jsonstate_topic: zigbee2mqtt/Cinema Lightning Bolt Lightcommand_topic: zigbee2mqtt/Cinema Lightning Bolt Light/setvalue_template: '{{ value_json.state }}'command_template: '{ "state": "{{ value }}" }'payload_on: 'ON'payload_off: 'OFF'
Double Rocker Configuration
The following configuration is for the Aqara H1 Double Rocker (Office Light Switch):
devices:'0x54ef441000cf57e4':friendly_name: Office Light Switchhomeassistant:switch_left:type: lightschema: jsonstate_topic: zigbee2mqtt/Office Light Switch/left/setcommand_topic: zigbee2mqtt/Office Light Switch/left/setvalue_template: '{{ value_json.state }}'payload_on: 'ON'payload_off: 'OFF'switch_right:type: lightschema: jsonstate_topic: zigbee2mqtt/Office Light Switch/right/setcommand_topic: zigbee2mqtt/Office Light Switch/right/setvalue_template: '{{ value_json.state }}'payload_on: 'ON'payload_off: 'OFF'
Explanation
friendly_name
: This is the name of your device as it appears in Zigbee2MQTT and Home Assistant.
type: light
: Changes the entity type in Home Assistant from switch
to light
schema: json
: Defines the message payload format for Zigbee2MQTT.
Topics:
state_topic
specifies where the current state is published.
command_topic
specifies where to send commands to control the device.
Templates:
value_template
extracts the current state from the JSON payload.
command_template
formats commands sent to the device.
Payloads: payload_on
and payload_off
define the ON and OFF states.
Testing
Make sure to stop the Zigbee2MQTT addon before editing the configuration.yaml
When you save the config, you can start the addon again.
I made these scripts for quickly starting/stopping the addon:
Start
alias: Start Zigbee2MQTTsequence:- data:addon: 45df7312_zigbee2mqttaction: hassio.addon_startmode: singledescription: ""
Stop
alias: Stop Zigbee2MQTTsequence:- data:addon: 45df7312_zigbee2mqttaction: hassio.addon_stopmode: singledescription: ""
You can find the addon slug in the URL when you open the addon in home assistant.
Final Thoughts
With these configurations, my Aqara H1 switches now act like native light entities in Home Assistant. This makes automation smoother and more intuitive. If you're dealing with other Zigbee switches, this process can easily be adapted.
Happy automating!