Create large number of helpers with script

Hello,

For our new house i need to create alot of helpers (lightgroups).
For example our bedroom:

I have 16 GU10 light bulbs for which i created the following helpers manually.

Plafondspots light.plafondspots
Plafondspots - raam links light.plafondspots_raam_links
Plafondspots - raam rechts light.plafondspots_raam_rechts
Plafondspots - ramen light.plafondspots_ramen
Plafondspots - wand inloopkast light.plafondspots_wand_inloopkast
Plafondspots - wand inloopkast links light.plafondspots_wand_inloopkast_links
Plafondspots - wand inloopkast rechts light.plafondspots_wand_inloopkast_rechts
Wandspots - links tv light.wandspots_links_tv
Wandspots - links tv - links light.wandspots_links_tv_links
Wandspots - links tv - rechts light.wandspots_links_tv_rechts
Wandspots - rechts tv light.wandspots_rechts_tv
Wandspots - rechts tv - links light.wandspots_rechts_tv_links
Wandspots - rechts tv - rechts light.wandspots_rechts_tv_rechts
Wandspots - tv light.wandspots_tv

I have 16 more rooms/area’s to go, mistakes are made easily.

Is there any scripted way to create my helpers?

create a file
groups_lights.yaml

add it to your configuration yaml if you dont have it with
group: !include groups_lights.yaml

in the group_lights.yaml define all your light groups


celing-lights:
  name: celimg ligths
  entities:
    - light.plafondspot_1
    - light.plafondspot_2
    - light.plafondspot_3
    - light.plafondspot_4
    
plafondspots_raam_links:
  name: Plafondspots - Raam Links
  entities:
    - light.plafondspot_1
    - light.plafondspot_2

and so on untill you add all

restart and you will load those

do you know how to use python?

you can do python script to make your yaml code

import yaml

# Example data structure:
groups = {
    "plafondspots": ["light.plafondspot_1", "light.plafondspot_2", "light.plafondspot_3"],
    "plafondspots_raam_links": ["light.plafondspot_1", "light.plafondspot_2"],
    "wandspots_links_tv": ["light.wandspot_1", "light.wandspot_2"],
}

output = []
for group_name, entities in groups.items():
    output.append({
        "platform": "group",
        "name": group_name.replace("_", " ").title(),
        "unique_id": group_name,
        "entities": entities
    })

print(yaml.dump(output, sort_keys=False))

and the output past it on you light: section in your configuration.yaml

remember to Check configuration before reboot

thanks, i thought about using yaml (i used to do it like that in the early days). But i changed to helpers due to the better integration within HA. Thats why i was hoping i could create helpers with a script. Cause as far as i understand it correctly a group in the configuration.yaml file isnt the same a “helper group”

i dont think is possible to make a bulk of helpers , but i can be wrong

Maybe using rest api

i find this

import requests

# Home Assistant URL (no trailing slash)
BASE_URL = "http://homeassistant.local:8123"  # Change to your instance
TOKEN = "YOUR_LONG_LIVED_ACCESS_TOKEN"        # Paste your token here

HEADERS = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json",
}

def create_input_boolean(object_id, name, icon="mdi:toggle-switch"):
    url = f"{BASE_URL}/api/config/input_boolean/config/{object_id}"
    payload = {
        "name": name,
        "icon": icon,
        "initial": False
    }
    response = requests.post(url, json=payload, headers=HEADERS)
    if response.status_code == 200:
        print(f"Created {object_id}")
    else:
        print(f"Failed to create {object_id}: {response.status_code} {response.text}")

def main():
    count = 10  # Adjust how many helpers to create
    for i in range(1, count + 1):
        object_id = f"auto_boolean_{i}"
        name = f"Auto Boolean {i}"
        create_input_boolean(object_id, name)

if __name__ == "__main__":
    main()

this is for boolean you can try with lights

edit *********************

wait there is not light on helpers , you cant create a light helper the only option is with template
yaml

You’ll get better results generating YAML file as packages.

I create “templates” outside of HA. These contains sensor templates, automations, input numbers, alerts, displays, etc. Then use a shell script to replicate into HA.

95% of my config and UI across two houses is created this way.