Help with passing argument to function in custom_component

Hi, I am trying to integrate the following project for a Control4 amplifier matrix custom component:

There are functions for each of the 4 zones of the amp to turn on/off and set volume. I am looking for a way to consolidate and just have 1 function/service that you pass the zone number to in a variable. I am not a coder but play around enough to know a few things. However, can’t seem to find anything on how this can be accomplished. Any advice would be appreciated.


I can help but you should first explain the problem given that i don’t have any knowledge about the specific product or service.

The way this is currently setup is by using helpers and automations. For example if you want to turn on zone 1 you can turn on a helper switch in Lovelace which will trigger an automation that will call the zone1_turn_on custom service. There is a service/function for each zone. I am looking for a way to call just a zone_turn_on service and pass the zone as a variable. This is just to simplify and consolidate repetitive code.

FYI, the linked component refers to the zones based on the name of the room rather than the zone number.

Thanks for the help.

Got it, is it fine for you to call your service as

turn_on(1) or turn_on(2)

Given that 1 and 2 will correspond to zones?

If yes, inside service call, you can access the data elements coming from user.

Example: Integration Services | Home Assistant Developer Docs

Yes, that is what I would like to do. However, if I go to developer options and services, there is only the service listed. There are no additional data fields to pass the zone value. I assume I need to declare the function definitions differently but this is where I don’t know the syntax to do this. I have tried adding a variable to the function definition like this

def turn_on(zone)

But when I try to call the service under developer options or in an automation, again, there are no additional fields to pass the zone argument. In the current version of the custom component that I linked, they define the zone functions like…

def handle_zone1_amp_on_select(call)

So I can call the service c4_services.handle_zone1_amp_on_select from an automation but there are services for each zone for on, off and volume. Not sure how to edit to accomplish passing the argument though.

Developer tools are just helping to generate a basic input but definitely not enforcing anything.

Just random example;

service: your_integration.your_service
  zone: 1

You can read the data in your service handler as'zone')