Hi,
I’m new to HA and struggling a lot but also enjoying every sometimes tedious and frustrating moment as I learn bit by bit and the insane joy I get from solving a puzzle is just immense.
My current task is to query our local councils website and find out which bin goes out and when.
They have a two part form where you have to enter your Postcode and then select your address from the retrieved list of houses at that Postcode.
I have a working CURL POST command which does this and I can run this on the command line of my Pi and it gives me the full HTML page (expected) containing a table with the two bins and the next collection dates.
The command I am using is:
curl -X POST https://www.scotborders.gov.uk/bincollections -d "postcode=EH24 6XX&address=123456789"
I’ve added this as a shell_command to my configuration.yaml file and restarted.
shell_command:
bin_dates: curl -X POST https://www.scotborders.gov.uk/bincollections -d "postcode=EH24 6XX&address=123456789"
I’m trying to call this from an automation as the service shell_command.bin_dates and send the output as a message to my phone (via a script) but no alert is being sent. The message sends as soon as I remove the {{ bindates }}. I’m doing this as I don’t know of any other way of displaying the response within HA.
action:
- service: shell_command.bin_dates
response_variable: bindates
data: {}
- service: script.send_message_to_phone
data:
title: Your next bin is
message: {{ bindates }}
I’m assuming one of two things are happening here. Either {{ bindates }} is empty in which case I would have expected a message to be sent with just a title. Or the full HTML output of CURL is too large for the message so nothing sends (but I can’t see any limits to the message size in the docs). Or something else, at this stage in my HA journey, it could be anything
What I need to do and this is where I’m struggling, is to strip the response from CURL down to just the sections of the table I am after and I don’t know how to do this. Sadly the Council webpage doesn’t give me nice JSON I can run through to grab the values.
The section I am after is:
<h2 id="dates">Bin collection days and dates for My ADDRESS</h2>
<table border="1">
<thead>
<tr>
<th>Bin</th>
<th>Collection day</th>
<th>Next collection</th>
</tr>
</thead>
<tbody>
<tr>
<td>General</td>
<td>Tuesday every 2 weeks</td>
<td>12/12/2023</td>
</tr>
<tr>
<td>Recycling</td>
<td>Thursday every 2 weeks</td>
<td>21/12/2023</td>
</tr>
<tr>
<td>Food</td>
<td>No collection</td>
<td>No collection</td>
</tr>
</tbody>
</table>
Specifically the first two containing General and Recycling and the dates.
Eg:
General 12/12/2023
Recycling: 21/12/2023
Ideally I would run this daily and it would send a message if it was the night before one of the bin dates and advise which bin goes out so we can be the streets binfluencer.
Any help on how to proceed would be most appreciated. And thank you.
Many thanks,