I have been checking the community posts for a working solution to sending out email when a new episode is posted on a website. I first tried a return while condition loop but it seemed to run a set number of times without advancing to the notify action after the loop. I am using a wait_for_template now and it just waits without advancing to the notify action. All of the individual parts work as intended but it never advances past the wait_for_template (template evaluates as true but doesn’t advance). Here is the yaml for the automation and the script used in it.
Thank you, I will add the | trim to the script. Strangely wait_for_template as written is waiting but doesn’t move on after the the latest.episode sensor changes and the template evaluates as true. If it was just a format issue caused by not trimming white space wouldn’t it fail to evaluate correctly as the white space would be present in the input text but not on the latest.episode sensor?
I tested the template in developers template after there was an update at the website and it evaluates as true whereas its false at the start of the calendar event trigger. The traces get to the wait template and stops but never progresses even after evaluating to true. Puzzling.
The script “get last episode” runs just before the wait template. Initially the input text and sensor state would match but when the website posts the latest episode it evaluates to true (states don’t match) and should then advance to the notify action.
Hmm all I can think of is to add a notification (or logger entry) right before the wait_template that logs the value of the template that you’re using:
Thank you for the suggestion. I had already used a notification to my mobile app step when I was testing the automation initially and it evaluated as false as it should before the website changes. The wait_for_template should wait until it evaluates as true then continue to the next action. Everything works except the wait_for_template does not advance when the sensor last episode changes. The last episode sensor is populated by scrape. I noticed that for at different times for exactly 10 minutes the sensor changes to unavailable usually once a day.
Even if it’s unavailable, the condition should still evaluate to true. So I’m not sure what’s going on
As a workaround, perhaps it’s possible to split up the automation into two, the first calling the script, the second triggering on sensor.latest_episode changing.
Thanks for your help with this. I added back the notifications ahead of the wait_for _template and it triggered but refuse to advance. I decided that I am missing some basic understanding of how the wait for template works and decided to rewrite the automation to trigger on a state change in the website sensor (excluding unavailable and unknown) against the last sensor value saved in the input text. I will check how it works out and will avoid any future (non) use of wait_for_template.
To be honest, you and me both, because I would expect it to work as you’ve explained.
AFAIK, you don’t necessarily have to check against the last sensor value because sensor triggers only trigger on state changes, so this might be enough:
trigger:
trigger: state
entity_id: sensor.latest_episode
not_to:
- unavailable
- unknown
This is precisely what I ended doing with the addition of a condtion template and a setting of the input text at the end to compare in the input text. This to make sure the automation doesn’t get past the trigger if the state goes from unavailable or unknown to the unchanged website scrape.
Actually it just occurred to me that maybe I could add a not_from to the trigger so it will only trigger when there is an actual change to the website.