I have a script that I run after I feed my newborn. It publishes the amount of feed to mqtt and use this to record how much she is having. I also want to increment a counter to total how many feeds she is having per 24hours.
The problem is sometimes she takes a break and my wife has already input the amount into HA. I still want this new amount published but I don’t want the counter to increase as its still part of the original ‘feed’ so i have have a condition for this.
However, I cant get the trigger to work. Help would be appreciated.
You’ve completely lost me now. Unless you need it to have a date as well set it to false.
Then set the time (and date if relevant) to 3 minutes from now on the input_datetime itself and then wait 3 minutes. There’s no need for any yaml at all.
Sorry guys, HA and newborn parenting don’t mix well together. Let me start again.
A Lovelace button executes the feeding script which publishes the amount of feed to Matt. A Matt sensor reads this and displays in Lovelace.
The reason the input_datetime is in the script was to record when the last feed was. Also, it persists over restarts so I could always see the last_changed value and know how long it’s been since her last feed.
I initially had the trigger of the automation set to the state of the mqtt sensor and the counter would increase with a state change. However, if my amount my child consumed over two consecutive feeds was the same then it wouldn’t increase. So I thought I could make the trigger be when the input_datetime is changed from the script.
The condition is to avoid an increase in the count of feeds if two values are published very soon after each other as this would be the same feeding episode.
I hope I have cleared up my mess and that you are still willing to help
There’s a flaw in the logic then, because the input_datetime is being set to ‘now’ in the script, and then that’s supposed to trigger the automation.
When in fact all you need to do is add the counter.increment action to the end of the script, under a condition that the script hasn’t been run in the last 5 minutes (or whatever the time interval you want as a buffer).
Using the input_datetime to decide if the buffer time has passed won’t work, because when the script runs it will update the input_datetime, and therefore the condition will never pass because every time the condition is checked the input_datetime has only just been updated that very moment.
It worked guys - thank you so much!. Out of interest, the input_datetime is only part of the script so I can work out how long its been since her last fed. Is there a better way to do it that persist over restarts?