Hello,
I’m trying to create a template sensor that calls out to a website to get a value. The website is for a snow day calculator, and I’m trying to get a value out of it that shows the percent chance of a snow day tomorrow.
The URL is Snow Day Calculator (44011)
When I do a curl on the URL the value that I’m searching for comes back in the response and looks like “theChance[20251111] = 12.3;”
Here is my yaml
- platform: rest
name: snowday
resource_template: https://www.snowdaycalculator.com/prediction.php?zipcode=44011&snowdays=0&extra=0
method: GET
unique_id: snowdaytomorrow
scan_interval: 10
value_template: >
{% set tomorrow_date = (now() + timedelta(days=1)).strftime('%Y%m%d') %}
{% set regex_pattern = "theChance\\[" + tomorrow_date + "\\] = ([\\d\\.]+);" %}
{{ response.text | regex_findall_index(regex_pattern) }}
unit_of_measurement: "%"
icon: mdi:weather-snowy
After restarting the services, no sensor is being created
I’ve tried testing it in the Template Editor. When I paste the full response, which is like 4000 lines of php code in the template editor, it just throws an error, which I presume is just because of all the special characters in it. Maybe this is my root problem? If I manually just strip the line out of the response that I want to search for, it works fine
{% set response = {"text": "theChance[20251111] = 12.3;"} %}
{% set tomorrow_date = (now() + timedelta(days=1)).strftime('%Y%m%d') %}
{% set regex_pattern = "theChance\\[" + tomorrow_date + "\\] = ([\\d\\.]+);" %}
{{ response.text | regex_findall_index(regex_pattern) }}
results in 12.3
So I know at least that part is working. Any ideas where I’m going wrong? I think Gemini is getting tired of me trying to troubleshoot.