home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.16k stars 29.84k forks source link

bug in automation trigger id #122519

Open JokeRsevilla opened 1 month ago

JokeRsevilla commented 1 month ago

The problem

sorry for my english, example error in this automation, the trigger is input_button.pulsador_lavadero no id trigger, but result condition is 'true'. If change order of triggers It works well. Solution id: "0" for rest of triggers.

alias: new automation description: "" trigger:

I think it's a bug

What version of Home Assistant Core has the issue?

core-2024.7.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

jorgwolski commented 1 month ago

Can confirm that behavior. For if-then or choose, options with an ID as condition are also fired by a trigger without defined ID.

jorgwolski commented 1 month ago

Update: Only happening, if the first trigger gets the ID "1" and the second ID is not defined.

A trigger without a user defined id gets the index number as id (trigger.idx) which is 1 for the second trigger

JokeRsevilla commented 1 month ago

No, I discovered it in a complex automation, something like this (trigger 2 was executed):

trigger 1 (without ID) trigger 2 (without ID) trigger 3 (without ID) trigger 4 (without ID) trigger 5 (without ID) trigger 6 (without ID) trigger 7 (without ID) trigger 8 (ID 1) trigger 9 (ID 1) trigger 10 (ID 1) trigger 11 (ID 2)

The condition: if trigger ID 1 = true

I investigated the traces and tried to reproduce it with a simple, invented automation and had the same error.

When I changed the order of the triggers in the invented automation, the error no longer occurred. I don't know why...

jorgwolski commented 1 month ago

Try it with non-numerical IDs. That should work.

JokeRsevilla commented 1 month ago

Yes! If the trigger doesn't have a numeric ID, there's no error. But I still think it's a bug, why not use a numeric ID?

TheFes commented 1 month ago

Because if you don't give an id to a trigger, it will get the index (as string) of the trigger assigned as id. Which is already a number. But counting starts at 0. So if you give the first trigger the id "1" and you give no id to the second trigger, they will both have "1" as id.

home-assistant[bot] commented 1 month ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (automation) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `automation` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign automation` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


automation documentation automation source (message by IssueLinks)