WTH I can’t test the trigger of the automation?

When building an automation with many triggers I would like to simulate / test how it runs on specific trigger to see how the automation will flow through multiple “choose”.
Now I have to go to Developer tools, find the entity and change it’s value so the trigger in automation is evaluated and starts the automation. But that can trigger also other automations which I don’t want and also it’s recorded to history. And it’s time consuming because on phone in the app (which is where I love to create automations) I can’t open a new tab, but I have to navigate there and back.

It would be nice to test the trigger of automation: the value for the test would be calculated so trigger is “true” but this value would not be recorded so it doesn’r trigger other automation but I would be able to see the trace of an automation.

Thanks!

An option to execute the trigger, as exists for full automation and for each action, I think would fit well and solve this (I also go through this and every time I think how can this not exist).

2 Likes

This may be slightly trickier than it sounds, because trigger types can introduce variables, and the trigger setup does not always fully constrain the values. For example a state trigger that fires when one of several entities change, requires you to specify which entity. Triggering from home assistant internal events may require specify the event body, etc.

That does not make this infeasible, but does make it more effort to implement.

And of course, it is entirely possible the body of the automation not not behave as expected if entities don’t have the expected states. I have some automations where faking triggers like that would not work as expected.

2 Likes

This is likely a lot harder than it sounds and quite possibly might not work at all from some trigger types. If the primary intent is just for testing automations I would suggest something I’ve found useful. Add testing helpers (I’ve used input_boolean, input_number, & counter for this) and then added an additional trigger that uses your test helper. Then set the helper to a state that will trigger. After testing I set that trigger to disabled, so it’s available for future testing, and then it’s helper can be reused for testing other automations without triggering all the automations where it may have been used.

Would be great if you could fire an automation trigger manually to test. Similar to how one can run actions, or test conditions. This would allow the testing of complete automations

2 Likes

This would test the automation body, but that very body might have branches that check which trigger was fired (trigger.id == "my_trigger_id") and do something different based on the specific trigger. This means that you would test just part of the body for that specific trigger and not other code paths.

You can. Go to Developer Tools → States. Click on the entity your trigger depends upon. You can then (non permanently) adjust the state of the entity (using the input fields at the top of the page) to trigger your automation.

1 Like

Yes! Firing triggers directly from the automation editor would be a huge help. Especially when creating or just tweaking advanced automations on mobile.

2 Likes

I’m not sure you understand the complexity of this request. Consider the following simple numeric state trigger:

triggers:
  - trigger: numeric_state
    entity_id: sensor.foobar
    above: 42

What does your UI based triggering set the trigger.from_state.state and trigger.to_state.state variables to?

If you have a choose action in your actions block that depends on sensor.foobar’s state how does that react when the real state never went above 42?

The only way I can see around this is the tools already provided that I mentioned above.

You would just fill in the fields that is that you use in the automation, so in your example it could be done with something like this as the input

sensor.foobar
  from_state: 36
  to_state: 43

Yeah my comments above were from the duplicate WTH merged into this one (so the votes total). It’s not as relevant here.

1 Like

Shouldn’t it then be quite easy to create a pop-up directly from the place where the trigger is defined using its entity and providing you the option to temporarily alter it right there? So instead of moving out to the States page, finding the entity and altering it etc.?

Dude. Read the post directly above yours.