Change entity domain?

Is it possible to change the domain on an entity? I have several light switches that show up as switch and I would prefer they be under the light domain.

I think this is typically done by creating a Template Light. You can then hide the switch entity.

light:
  - platform: template
    lights:
      my_light:
        value_template: "{{ states('switch.my_switch') }}"
        turn_on:
          service: switch.turn_on
          entity_id: switch.my_switch
        turn_off:
          service: switch.turn_off
          entity_id: switch.my_switch
5 Likes

That worked! Thanks!

1 Like

Sorry for hijacking this thread but I have a similar problem:
The entitiy_id is ‘switch.candles’
If I go to states in dev-tools I can enter ‘switch.candle’ in the entity and ‘on’ or ‘off’ in the state and the candles will turn on or off

If I set a ‘Entity button’ card in lovelace the light will toggle on then off when selected and not stay on.

I tried you code above and then tried a ‘Entities card’ and ‘Light’ card with a switch but the same results i.e. I turn the candles on and they immediately go off again

Sorted it, the candles were being controlled in a different automation platform via a virtual input switch, changed to a toggle switch and all’s well

FWIW, there is now a Light Switch platform you can use.

2 Likes

Thanks very much for pointing this out! Much cleaner yaml-wise to use than the template for converting switches to lights.

As an aside and wishful thinking - if only there was a “Fan_Light” platform to remap ceiling fans that are imported as dimmable lights to fans with multiple speeds. I have a fan template that solves this remapping now but it is a quite complex bit of yamlleese.

Hey,

Could you give me a hint on that fan template thing? I also have a dimmable zigbee controller added to my hue bridge which controls fan speed and i don’t want to show them up as “lights”.

Thank you in advance!

Hi @fighterii,

Here’s that fan template thing. As I said earlier, it’'s a bit complex, but gets the job done. It’s especially good for voice commands to refer to a fan as a fan, not a dang light. Note that the brightness to speed value settings here are appropriate for a GE/Jasco Zwave fan 3-speed fan switch.


fan:
  - platform: template
    fans:
      den_ceiling_fan:
        friendly_name: "Den Ceiling Fan"
        speeds:  ['low', 'medium', 'high']
        value_template: "{{ states('light.den_ceiling_fan') }}"
        speed_template: >
          {% if      (state_attr('light.den_ceiling_fan', 'brightness')|int <  85) %} {{ "low" }}  
          {% elif    (state_attr('light.den_ceiling_fan', 'brightness')|int > 170) %} {{ "high" }} 
          {% else %}    {{ "medium" }}   {% endif %}
        turn_on:
          service: light.turn_on
          entity_id: light.den_ceiling_fan
        turn_off:
          service: light.turn_off
          entity_id: light.den_ceiling_fan
        set_speed:
          service: light.turn_on
          entity_id: light.den_ceiling_fan
          data_template:
            brightness: >
              {% set speedlist = { 'low':25, 'medium':125, 'high':255 } %}
              {{ speedlist[speed] if speed in speedlist else 255 }}

      bedrooom_ceiling_fan:
         <snip>
1 Like

How can this Light Switch template be used for every switch? Or for a list of switches, do I have to re-configure every single switch all over again?

There is no need to change your switch configurations. Simply add the light switch template to create new light entities for them. You will still have the original switch entities, but I configure Google Assistant to ignore them, and don’t display them in lovelace.


light:   #  associate zwave power switches to lights... 
  - platform: switch
    name: "Porch Lights"
    entity_id: switch.porch_lights
  - platform: switch
    name: "Dining Room Lamp"
    entity_id: switch.dr_floor_lamp
  - platform: switch
    name: "Entry Lamp"
    entity_id: switch.entry_lamp

EDIT: oops, sorry for replying to an old post which I’m sure you’ve solved by now. I was directed here by a “like” and thought your question was a new post.

No worries. Your response here was helpful to me. Although, it would be nice if there was a way to do this from the UI if the current push is toward using the UI rather than yaml. Hopefully that’ll get added sooner rather than later.

I personally dislike duplicating entities even if they’re not terribly difficult to hide, so I really wish there was just a way to indicate a switch goes to a light and just make it work without jumping through hoops.

2 Likes

So I can’t get this to work. It will turn on, but won’t adjust the speed.


fan:
  - platform: template
    fans:
     living_room_fan:
        friendly_name: "Living Room Fan"
        value_template: "{{ states('light.living_room_fan_hallway') }}"
        speed_template: >
          {% set output = {0: "Off", 85: "Low", 170: "Medium", 255: "High"} %}
          {% set idx = state_attr('light.living_room_fan_hallway', 'brightness') %}
          {{ output[idx] }}
        turn_on:
          service: homeassistant.turn_on
          entity_id: light.living_room_fan_hallway
        turn_off:
          service: homeassistant.turn_off 
          entity_id: light.living_room_fan_hallway
        set_speed:
          service: homeassistant.turn_on
          entity_id: light.living_room_fan_hallway
          data_template:
            brightness: >
                {% set mapper = {'Off': 0, 'Low': 85, 'Medium': 170, 'High': 255} %}
                {{ mapper[speed] }}
        speeds:
          - 'Off'
          - 'Low'
          - 'Medium'
          - 'High'

What am I doing wrong? Lol

What Im I doin wrong?? I want to add those switches to light group


light:

  • platform: group
    name: 2krs valot
    entities:
    • light.2_krs_keittio_kaappi
    • light.2_krs_valokatto_oikea
    • light.2_krs_valokatto_vasen
    • light.din_rail_dimmer_23_01_50
    • light.din_rail_dimmer_23_00_61
    • switch.din_rail_on_off_23_08_db
    • light.din_rail_dimmer_23_01_cb
    • switch.din_rail_on_off_23_08_33
    • switch.din_rail_on_off_23_08_de
  • platform: switch
    name: “2 krs. Kuilu kruunu”
    entity_id: switch.din_rail_on_off_23_08_db
  • platform: switch
    name: “2 krs. ruokapöytĂ€â€
    entity_id: switch.din_rail_on_off_23_08_33
  • platform: switch
    name: “2 krs. Tauluvalot”
    entity_id: switch.din_rail_on_off_23_08_de

How would you go about converting a light to become a switch?

There’s a new way to do this via this integration - see: Switch as X - Home Assistant

I think you’re wrong about that. Switch as X - Home Assistant does exactly the opposite.

The OP here was how to convert switches that control lights to be referred to as lights in a more appropriate light domain. I see now that you are asking the opposite - how to turn a light into a switch. That’s a curious use case that I don’t have a quick answer for.

Thanks for taking the time to reply. This is a strange one, as it is quite normal to use switches - often in the form of “pills” to switch lights on/off. As such, the switch actually should correctly be identified as a light. So the OP’s request is answered by the ‘Switch as X’ integration.
But I have several “pills” from different manufacturers that do identify themselves as lights by default. Now since these “pills” can be used to switch almost anything on/off (not only lights), it is sometimes very convenient to define them as switches and not as lights.
I for one, have “pills” that controls my coffee machine, toaster, boiler, etc. When I ask Home Assistant to turn off all lights in the kitchen, it also switches off all of those other devices because the “pills” are defined as lights. I know there is a possibility to create a so called shadow entity using templating, but that gives you a new switch entity while the original light remains. So the problem also remains. :cry:
I wonder why the HA Dev team hasn’t recognized this as a much needed feature.

A simple solution to that is to place the original light in another area (or if you are talking about google home, exclude it from syncing to google).