It is recommended to increase the “number of times” item in the trigger options for automation
That’s not a number of times, that’s how long for - so it has to be in the new state for that amount of time.
Are you saying that you want to be able to have a value of days in there?
It’s not time, I want to add a repeat option like the one on the picture. Repeat 5 times to perform the action.
That wouldn’t go in the trigger section. That would go in the action section.
it’s already there
I hope to add the “repeat” option to the trigger, so that the trigger can be set to repeat the specified number of times to complete the trigger.
That’s not the way triggers work.
triggers are only active for an instant in time when the monitored values go from false to true. Then the trigger no longer “exists”. Even if the conditions that caused the trigger to be active are still true.
For that reason alone this will never be implemented.
it is the responsibility of the actions section to manage what happens after the trigger occurs.
There is actually probably viable use cases, for essentially a trigger rate threshold.
Trigger has to activated X times in X minutes.
And logic wise, wouldn’t be that difficult to implement, you just have to keep track of how many times it has been activated in the time window.
Right now - it could still be done - by creating a history_stats sensor.
Set to the type: count
and start
set to how many minutes back you want the time window to be, and duration
to the length of the time window.
This is not the same as the historical statistics. This “repetition” is from the start of the trigger to the success. After the successful trigger, the statistics are cleared in time and wait for the next trigger.
Yes, but the trigger IS an entity changing state, even when it is a device you choose as the trigger, the device has an entity (light, binary_sensor, sensor etc) that has changed state - and that is what fires the trigger. The History stats integration can therefore be used to count how many times the state changed to the state you require.
As shown in the figure, the state of kon1 changes 5 times. As a trigger condition, how to configure it? Please give an example. thank you very much!
This request is similar in nature to the for
option although for
requires state-persistence for a specified time period whereas this request requires a specified number of triggers to occur before it actually proceeds to execute the actions. In effect, it counts triggers.
Be advised that even if this were implemented, it’s unlikely to survive a restart. In other words, a restart would reset the trigger-count back to zero. That’s how it currently works for the for
option and several other things.
Out of curiosity, what problem is solved by this ‘trigger-count’ feature? Is it to debounce an input (i.e. hysteresis)?
For example: “kon1” is triggered once every rotation of the motor, and the next operation is triggered after 5 rotations.
I know how to achieve that with Home Assistant’s existing features … but it’s not as simple as picking 5
from a menu like in your Feature Request.
Can you give an example? thank you very much!
I will but it’ll need to be later because I have other commitments at the moment. Perhaps in the interim someone else will provide an example.
It was probably a language barrier issue but that isn’t what I got from the initial request explanation.
What you wanted wasn’t “repeat 5 times for each trigger event” but instead “only trigger after the trigger entity changes to the desired state 5 times”.
You can do the same thing with a counter.
set the counter to increment after every trigger.
then use the counter reaching 5 to trigger the desired actions in the original automation. and at the end of that automation reset the counter to 0.
While I was away, finity described the technique I had in mind. All you need is one counter and one automation to implement it.
You said:
“kon1” is triggered once every rotation of the motor
What kind of entity is kon1? (sensor, binary_sensor?) In other words, what kind of entity do you currently have that indicates one rotation has occurred?
I’ll just add here that the method Andrew proposed earlier works great for me.
I use it to count the number of times my automation has opened the front gate the last minute, if it’s more than some value I can’t remember right now it disables my automation since something is wrong with something in the automation.
I would like to learn more about how to use the History Stats sensor as a means to count the number of motor rotations. I understand that one should use type: count
but it’s the need for a “time window” that makes me wonder how it would function for the case where the motor’s rotational speed is not constant but variable.
In other words, if 5 rotations can occur over any period of time (within a few seconds, or a minute, or several minutes, possibly even over an hour) , how should the “time window” be configured to handle that situation? Or is it a non-issue?