I’m trying to cut down the number of automations from 4 to 1 by using trigger_to but can’t seem to figure out the proper code for this. Essentially an input_number is changed, I take that input_number and get its friendly name and use that in a state check, but I can’t get the state check to work. Here’s what I have. Any help would be greatly appreciated.
the light entity and input_number entity have the same friendly_name so it’s a simple string replace to check state but my solution just isn’t working.
Do you mean the input_number and light entities have the same object_id, or the same friendly_name attribute, or both?
If I understand correctly, the automation trigger is based on the input_number, but in the condition you want to check the state of the associated light. Is that right?
Assuming they have the same object_id, then this should do what you want:
If they only have the same friendly_name, it’s still possible, but a bit more involved. Let me know if the above works for you. If not, and it needs to be based on the friendly_name, then I can probably come up with something that will work for that, too.
EDIT: Out of curiosity, why do you need a template? Can’t you just use the entity_id of the light? Or are there more than one input_number/light pairs associated with this automation? (That’s why it’s usually better to provide more context - e.g., the full automation - in these topics.)
Do you mean the input_number and light entities have the same object_id, or the same friendly_name attribute, or both?
friendly_name
If I understand correctly, the automation trigger is based on the input_number, but in the condition you want to check the state of the associated light. Is that right?
yes
If they only have the same friendly_name, it’s still possible, but a bit more involved. Let me know if the above works for you. If not, and it needs to be based on the friendly_name, then I can probably come up with something that will work for that, too.
that’s what I’m working out
EDIT: Out of curiosity, why do you need a template? Can’t you just use the entity_id of the light? Or are there more than one input_number/light pairs associated with this automation? (That’s why it’s usually better to provide more context - e.g., the full automation - in these topics.)
if I had only 1 light i wouldn’t need a template, but i have a lot and they are all based on the same naming structure… ie light is light.a_day_light, light.b_day_light… .and so on… the corresponding input_number is the same input_number.a_day_light, input_number.b_day_light.
with this it’s just a matter of stripping out friendly_name to use to turn on/off the associated light as well as the mqtt topics since I can take the friendly name and use the split function to parse out my topic.
Those are object_id’s, not friendly_name’s. entity_id’s are made up of domain and object_id separated by a dot. friendly_name is an attribute. E.g., states.domain.object_id.attributes.friendly_name.
I may be wrong, but I am under the impression that the trigger data is only available in the action, and not in conditions. Not sure what you are trying to accomplish, but you should be able to expand the condition logic without using trigger data and still achieve the desired functionality.
When you say (1st part of entity), do you mean the input_number’s or the light’s entity? The first part of the entity_id is, of course, the domain. So for input_number.a_day_light that would be input_number, and for light.a_day_light that would be light. So do you mean ha/input_number/lights/leds/... or ha/light/lights/leds/..., or something else?
How about, let’s be specific. If the input_number that changed was input_number.a_day_light, what should the topic be exactly?
The payload part is easy. That should just be:
payload: '{{ trigger.to_state.state }}'
BTW, you might want to read Trigger State Object and Available Trigger Data which follows.
Ah! Ok, you mean the 1st and 2nd parts of the object_id. (Oh, and BTW, now that I look back at it, I did make a mistake on the condition. ) So, the complete automation should be: