Blueprint Template for Switch Entity with selectors?

Hello,

I’m dipping my toes into blueprints and my first good use case is to avoid config duplication of reoccurring template switches I have in my home.

Background/Goal
For each area/room I group all lights into one Light group, then I make scenes and a script to set lights after conditions. Sometimes very simple, sometimes more complex conditions but it’s nice to have that logic all wrapped in a script when lights are turned on.

Then this script is called from automations, smart buttons, motion detection etc.

To simplify it in the GUI and for physical switches/buttons (a toggle is available!) I make a switch entity that also calls this script. If it’s turned off I just turn off the light group.

Issue
I tried to recreate the base of these switches with a Blueprint Template (domain). Including Entity Selector and Action Selector but fell short.

I have simplified it to just use the Light Group Entity but even that throws error about variable definitions.

Recreating the issue

Version: 2025.05.3
Requirements: A light entity called light.light_group_demo

Working Demo without variable definition using a static entity defined:

File: blueprint_demo_light_to_switch_1_no_variable.yaml (path: /config/blueprints/template/switchdemo)

# Demo to show how to create a Blueprint Template for a switch
blueprint:
  name: Light to Switch No Variable
  description: Creates a switch from a light entity (No Variable version)
  domain: template
  homeassistant: 
    min_version: "2025.5.0"
  input:
    e_light_group:
      name: Light Group Entity
      description: The entity for the Light Group
      selector:
        entity:
switch:
  availability: "{{ states('light.light_group_demo') not in ('unknown', 'unavailable') }}"
  state: "{{ is_state('light.light_group_demo','on') }}"
  turn_on:
    action: light.turn_on
    target:
      entity_id: light.light_group_demo
  turn_off:
    action: light.turn_off
    target:
      entity_id: light.light_group_demo

Using the blueprint creating the template switch from package include file definition:

template:
  - use_blueprint:
      path: switchdemo/blueprint_demo_light_to_switch_1_no_variable.yaml # relative to config/blueprints/template/
      input:
        e_light_group: light.light_group_demo
    name: "Light to Switch Demo No Variable"
    unique_id: "light_to_switch_blueprint_demo_no_variable"

:white_check_mark: Result: This creates a switch entity that works

Broken Demo with variable definition:

File: blueprint_demo_light_to_switch_2_with_variable.yaml (path: /config/blueprints/template/switchdemo)

# Demo to show how to create a Blueprint Template for a switch
blueprint:
  name: Light to Switch
  description: Creates a switch from a light entity
  domain: template
  homeassistant: 
    min_version: "2025.5.0"
  input:
    e_light_group:
      name: Light Group Entity
      description: The entity for the Light Group
      selector:
        entity:
variables:
  e_light_group: !input e_light_group
switch:
  availability: "{{ states(e_light_group) not in ('unknown', 'unavailable') }}"
  state: "{{ is_state(e_light_group,'on') }}"
  turn_on:
    action: light.turn_on
    target:
      entity_id: "{{ e_light_group }}"
  turn_off:
    action: light.turn_off
    target:
      entity_id: "{{ e_light_group }}"

Using the blueprint creating the template switch from package include file definition:

template:
  - use_blueprint:
      path: switchdemo/blueprint_demo_light_to_switch_2_with_variable.yaml # relative to config/blueprints/template/
      input:
        e_light_group: light.light_group_demo
    name: "Light to Switch Demo With Variable"
    unique_id: "light_to_switch_blueprint_demo_with_variable"

:x: Result: This do not work, following error message is seen in logs:

Invalid config for ‘template’ at switch_light_to_switch_blueprint_demo_2_with_variable.yaml, line 2: ‘variables’ is an invalid option for ‘template’, check: switch->0->variables

Some general questions from me:

  1. Am I messing up the formatting of the blueprint template for the switch causing the error?
  2. Is there any way of yaml templating the entity selector in the blueprint?
  3. Are blueprint templates limited to using variables in only binary_sensor and sensor entities?

Need help going forward with this issue, any insights very welcomed. Thanks!

1 Like

It’s a bug, write it up please… I think. I really need to spend time familiarizing myself with this area of the code.

I’ve been looking at this area of code for about 10 minutes and there’s a section that I don’t like that I’m fairly sure is causing your problems. I’m about to hit the road, so I can’t dig into it deeper at the moment. So I don’t forget about this, could you please create an issue against HA core describing this problem and the resulting error?

1 Like

Thanks for verifying it’s probably a bug, was not confident enough myself to conclude that.

I will create an issue and link it in this thread.

1 Like

Issue created: Creating Switch using Blueprint Template and variable definition do not work · Issue #145868 · home-assistant/core · GitHub

1 Like

It was a bug, not in the area I expected.

3 Likes

I’m hit by the same problem. Really looks like it’s just the “variables” object that’s not accepted for template entities in a blueprint.

I see your PR received feedback yesterday, @petro. I hope you’ll manage to have it included in core soon. Fingers crossed.

It will likely be in next release. I know it will get approved, just need to add more tests.