Group entities in automation

Thanks for your attention.

I have the following situation
I create an IR Blaster with ESPHome and I am able to control a dozen or so different pieces of hardware.
To send an IR code I need to provide the protocol, code and command.
For this I am using 3 input_text helpers to get the protocol, code and command to the ESPHome. After that it is just pressing the button to send the IR code.

While this all works nice and neatly I dislikes the way how I need to add this to an automation.
If I do then I have to add 4 service calls (protocol, code, command, press button).
What I would like is to have these 4 calls wrapped in one ‘item’ such that in can add it to an automation in a similar fashion as RGB lights. There you add the light and in the same go you can add the details.

Is this possible and if so can someone give me some pointer to look for to make this happen.

Thanks in advance

You can create your own services in ESPHome. You can pass parameters to them (protocol, code, etc…), all in one custom service call, no need for input helpers.

Here’s an example I use to control my projector:

Thanks tom,

I wasn’t aware of this but at a first glimps I think that it indeed is what I need.

Yes you can move the logic from the automation into a script and call the script from the automation with the required parameters (in this case calling a script is also a service call). Then, many automations can call the same script, passing the correct parameters. In the below example I have timere thst turn on lights when the timers are started and turnj off spefific lights when the timers end. In the below example (the parameters I pass are whether or not the automation for this is enabled (which I set on my dashboard as a switch), the duration for that timer (which I set on my dashboard as a slider for the number of seconds), and which timer to (re)start. Note I say restart because if additional motuion is later deteted in the room, the timer just restart even if already running, that way the lights never turn off when someone is in the room):

Automation that is called when motion is detected:

alias: Den Motion Detected (Lamp By Closet Automation)
description: “”

  • type: motion
    platform: device
    device_id: 5ef8f43f23c1d09910584c8c6a3cb29c
    entity_id: binary_sensor.den_motion_sensor_motion
    domain: binary_sensor
    condition: []
  • service: script.motion_detected
    enablement_input_selector_entity: input_select.den_automation_lamp_by_closet_is
    timer_duration_entity: input_number.den_adjust_couch_lamp_by_closet_timer
    timer_entity: timer.den_couch_lamp_by_closet_timer
    mode: parallel

Motion detection scripts using those three parameters:

alias: Motion Detected

  • condition: template
    value_template: “{{ is_state(enablement_input_selector_entity,‘Enabled’) }}”
  • service: timer.start
    duration: “{{ (states(timer_duration_entity)|int*60) }}”
    entity_id: “{{ timer_entity }}”
    mode: parallel
    max: 100

You would do something like this in ESPHome:

  password: !secret api_password
    - service: send_ir
        code: string
        protocol: string
        command: string
        #<your ir action here, using the variables code, protocol and command>

In Home Assistant it would used like this:

- service: esphome.your_esp_device_name_send_ir
      code: #<your code here>
      protocol: #<your protocol here>
      command: #<your command here>


This info was enough to get it finished.

I have 2 additional question that i hope relate to this. If not i will open an other topic instead

(To make the user input a bit more fail proof )
First, I can’t find out how to get protocol: string in uppercase when it’s entered in lowercase. It this possible. I tried to use toupper() but no success.

Secondly, is it possible to give a default value?

For future reference.
Here’s the end result
ESP home IR Blaster

1 Like