Help Template Light with Switch

I would like to create a light device.

My bulb (light.dimmable_light_7_2) is behind a switch (switch.double_relay_switch_2x1_5kw_current_value).

So I have two devices and I would like to have only one.

I don’t know how to do it, do you have an example?


Generally, the best thing to do is to just not use relay-based smart switches with smart bulbs… it only leads to headaches and frustration.

You can’t do it in YAML (or via the UI). Only integrations can create devices, from what I understand.

Would you care to explain why you’d like to do this?

I have some smart bulbs that I bought as part of my initial setup a few years ago. Only realised the downsides as a n00b after I got them, but they were expensive and I didn’t want to get rid of them. So then I got some Shelly buttons and now I can more naturally control them. All this is just to say: I didn’t feel a need to make it look like one device, and that’s why I want to understand your reasoning better.


my probleme is when I turn off my switch the buld is not available (normal).
I want only one “device” to controle the switch and dimming buld.

I have try to do with template but I think is not complete I need set level and color.


  • platform: template
    friendly_name: “Salon Combo”
    level_template: “{{ state_attr(‘light.extended_color_light_10’, ‘brightness’)|int }}”
    value_template: “{{ is_state(‘switch.double_relay_switch_2x1_5kw_current_value’, ‘on’) and is_state(‘light.extended_color_light_10’, ‘on’)}}”
    color_template: “{{ state_attr(‘light.extended_color_light_10’, ‘hs_color’) | float}}”
    service: homeassistant.turn_on
    entity_id: switch.double_relay_switch_2x1_5kw_current_value
    service: homeassistant.turn_off
    entity_id: switch.double_relay_switch_2x1_5kw_current_value

Right, you’re dealing with light templates – this still gives you an entity (not a device; a device is something very specific to HA).

Also, please format your code.

It shouldn’t make a difference, but also want to point out that to turn on a switch, just call the switch.turn_on service directly (don’t need to use the more generic homeassistant.turn_on).

Now, given your config, what is going wrong? Describe the symptoms/show logs. Can you confirm that manually (from within HA) you can turn switch.double_relay_switch_2x1_5kw_current_value on and off and that it behaves as expected?

Start simple: template lights only require turn_on and turn_off to be defined (as per the docs). Only do that and confirm that it works. Everything else is optional.

The switch’s state isn’t really important for the overall value of your template light, but it is important that “off” encompasses both when the bulb is “unavailable” as well as “off”. You will likely need to use a script for the turn on because you will have to include a delay between turning on the switch and turning on the bulb. However, whether this is necessary or not depends on the bulb’s programmed initial state.

platform: template
    friendly_name: "Salon Combo"
    level_template: "{{ state_attr('light.extended_color_light_10', 'brightness')|int }}"
    value_template: >-
      {% if state('light.extended_color_light_10', 'on') %}
      {% else %}
      {% endif %}
      service: script.salon_combo_on
      service: switch.turn_off
        entity_id: switch.double_relay_switch_2x1_5kw_current_value
1 Like

thx I try with this and script