Guide: Change Light Entity to Switch

Just wanted to share a simple configuration for how I did this, as it was not immediately obvious to me, and there were not any other posts covering this that I found.

I have a Zigbee relay which when paired, erroneously showed the main relay switch as a light. This would be fine except certain things like thermostats expect a switch, not a light. There is a helper which allows changing a switch to a light, or another entity type, but not the other way around. However, this process is still trivial with a template helper.

  1. Create a template helper, and select the switch template type


  2. Name it the same as your current light entity. When it is done, you will have two entities:

light.your_entity
switch.your_entity
  1. Have the value template simply point to your light’s state:

{{ states.light.your_entity.state }}

{{ states('light.your_entity') }}
  1. Set the turn on and off actions to simply turn the light on and off:
action: light.turn_on
metadata: {}
data: {}
target:
  entity_id: light.your_entity
action: light.turn_off
metadata: {}
data: {}
target:
  entity_id: light.your_entity
  1. Point the device of the template to the device that the light is associated with.

  2. In the device, hide the light entity (optional, but this is how the change device type helper works, so this mirrors that function).

  3. That’s it! When you change the state of either the light or the switch, the other will match its state, so you can now use this new switch entity in a thermostat or similar.

This could also very easily be done in YAML, but I like how fast this is to setup through the UI as well :slight_smile:

10 Likes

I just signed up to say thank you for posting this with the detail. It solves a problem I have with zigbee relay devices and USB switches too. Would be helpful to be able to edit the entity type in the interface but this is a good workaround.

Thanks from me as well - in my case I have a zigbee 4 way relay, and each relay appears as a light rather than a switch. I am using it to control a projector screen - eg one relay triggers the screen to go down, one relay triggers it to go up. I wanted to use voice commands on it, but had to say things like “hey google, turn projector screen on”. Now I can say more natural things like “hey google, lower projector screen”. Small victories. :wink:

Thanks form here as well. HA did a lousy job explaining the new template UI.

For future reference: https://www.home-assistant.io/integrations/zha/#modifying-the-device-type.

2 Likes

I know that I’m late to this topic but I can’t seem to get my Tuya Water Valve Controller that ZHA has identified as a light to be either a switch or a valve using this suggestion. I fairly sure that I have the correct IEEE id, I’ve restarted HA, and still no joy. I thinking that it could either be that I need to fully restart my HAOS system, put this zha: entry into another yaml file or move ahead with a template. Any suggestions would be appreciated - attached are screenshots of my configuration.yaml, the Tuya Zigbee details, and the ‘Manage Zigbee Device’ window.

I feel like it won’t (or shouldn’t) make a difference but try making all the letters in the IEEE lowercase in your configuration.yaml.

Thank you! This saved me. I had both a HUE light strip that I couldn’t add to the count of switches in a room, and the same with a Leviton Decora. Not only can I see the correct count of lights + switches in those rooms, but I can also turn them on and off with a general button for each room, which before was impossible.

It was not following the light state. Had it changed to this, and now it works!

{{ is_state('light.your_entity, 'on') }}

I’m glad you brought this up, because the way I had it written is actually not recommended.
See the warning here.

Warning

Avoid using states.sensor.temperature.state, instead use states('sensor.temperature'). It is strongly advised to use the states(), is_state(), state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (such as during Home Assistant startup).

I had switched my template some time ago, but forgot about this post. I updated the guide with the proper template.