Craos
November 19, 2025, 8:08am
1
I need to perform an operation ( split ) on input value before I use it in my template. So, I think, variables should work. I tried many syntaxes, but none of them work for me. Please, coukld anybody advice, what is correct approach?
My definition is:
input:
ctrl:
name: CTRL
description: Select ctrl
selector:
select:
mode: dropdown
options:
- "10:1"
- "10:2"
variables:
ctrl_val: !input ctrl
hub_nbr: "{{ ctrl_val.split(':')[0] }}"
switch_nbr: "{{ ctrl_val.split(':')[1] }}"
triggers:
- trigger: event
event_type: esphome.button_pressed
event_data:
hub: >-
{{ hub_nbr }}
switch: >-
{{ switch_nbr }}
Craos
November 19, 2025, 10:18am
3
Thanks, but there is something else. I changed it according your tip and I made it very very simple:
trigger_variables:
hub_nbr: "10"
triggers:
- trigger: event
event_type: esphome.button_pressed
event_data:
hub: >-
{{ hub_nbr }}
switch: "2"
It still doesnât work, but this works:
triggers:
- trigger: event
event_type: esphome.button_pressed
event_data:
hub: "10"
switch: "2"
Sir_Goodenough
((SG) WhatAreWeFixing.Today)
November 19, 2025, 3:01pm
4
The event trigger may not accept templates then. I donât know.
If thatâs the case trigger on the event_type only,
Then check in the conditions (or actions if you have more than one trigger) that the hub and switch numbers are what you are looking for.
IIRC, you need to template the whole event_data object:
triggers:
- trigger: event
event_type: esphome.button_pressed
event_data: |
{{ {âhubâ: hub_nbr, âswitchâ: switch_nbr} }}
EDIT: Just tested that and it doesnât work eitherâŚ
Using a more general Event trigger with a condition does work:
triggers:
- trigger: event
event_type: esphome.button_pressed
variables:
hub_nbr: "10"
switch_nbr: "3"
conditions:
- condition: template
value_template: >-
{{ (trigger.event.data.hub, trigger.event.data.switch) ==
(hub_nbr, switch_nbr) }}
petro
(Petro)
November 19, 2025, 8:44pm
7
itâs because templates are changing the values from a string to a number.
Only way to get around it would be to template the entire event_data section, which Iâm not 100% if thatâs possible.
Other way would be to make the esphome event returns ints not strs.
Shouldnât using an int as the value for the trigger variable work then⌠it doesnât.
Tried that but the automation wouldnât save because a dictionary is expected.
That doesnât seem to be an option:
petro
(Petro)
November 19, 2025, 8:55pm
9
Then thereâs no way to do this. Maybe making it a single field and concatenating the strings on esphome side? Then using the input as-is