if it makes you happy
it does the same but way more complex
But yours doesn’t work as far as I can tell, because your algorithm doesn’t take into account 11, 12 and 13.
thats because it shouldnt.
its
1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, 9th, 10th, 11th, 12th, 13th, 14th, etc.
so you only need exceptions for 1, 2 and 3
its the script from apt what is very strange.
that says:
make it “th” if the date is 11, 12 or 13
else make it like we put in the dict (so use 1, 2 and 3) and if its not in the dict use “th”
so the complete first statement is obsolete.
this macro would do exactly the same:
{%- macro suffix(d) %}
{%- set sfx = {1:'st',2:'nd',3:'rd'} %}
{{- sfx.get(d%10, 'th') }}
{%- endmacro %}
we are looking at the day in date, not at the last figure from the day in date
Could you explain how the code you have presented will handle 21st, 22nd, 23rd and 31st?
i didnt think of those
probably because english isnt my first language.
and now i get the more complex part from the macro
thanks for pointing those exceptions out to me.
No problem, you teach HA, we’ll teach english Your contributions are very much valued.
@matchett808 Hey. I just stole the python file you posted here for ical URLs, but when I try to set up the sensor, HA just says “Platform not found: sensor.ical”. I had assumed that this file should go into the “custom_components/sensor/ical.py” file, but was I mistaken? Are there any other steps to getting this to work?
I had tried a similar thing in bash script before encountering this thread, but your solution is much nicer if I can get it to work.
My sensor:
- platform: command_line
name: Garbage Collection
command: 'wget -qO- [YOUR_ICAL_URL_HERE] | /home/hass/config/parse_ics.sh'
command_timeout: 60
scan_interval: 86400 # daily
value_template: '{{ value_json.displayDate }}: {{ value_json.summary }}'
json_attributes:
- uid
- date
- displayDate
- summary
- description
My bash script
#!/bin/bash
currentDate=`date -Idate`
foundFirstMatch=0
handle_event() {
local dt=${content[DTSTART]}
local entryDate="${dt:0:4}-${dt:4:2}-${dt:6:2}"
if [[ foundFirstMatch -eq 0 ]]; then
if [[ $entryDate < $currentDate ]]; then
#printf "PAST ($entryDate <= $currentDate): ${content[SUMMARY]}"; echo
foo=1
else
displayDate=`date -d "2018-11-20" "+%A, %B %-d, %Y"`
echo "{";
echo " \"uid\": \"${content[UID]}\",";
echo " \"date\": \"$entryDate\",";
echo " \"displayDate\": \"$displayDate\",";
echo " \"summary\": \"${content[SUMMARY]//\\/}\",";
echo " \"description\": \"${content[DESCRIPTION]//\\/}\"";
echo "}";
foundFirstMatch=1
fi
fi
}
declare -A content=( ) # define an associative array (aka map, aka hash)
#declare -A tzid=( ) # another associative array for timezone info
while IFS=: read -r key value; do
value=${value%$'\r'} # remove DOS newlines
if [[ $key = END && $value = VEVENT ]]; then
handle_event
content=( )
# tzid=( )
else
#if [[ $key = *";TZID="* ]]; then
# tzid[${key%%";"*}]=${key##*";TZID="}
#fi
content[${key%%";"*}]=$value
fi
done
Hi - yeah, that’s where it should go - I’ve got the following config:
sensor:
- platform: ical
name: "Refuse Collection"
url: "https://[snip]/bin-ical?uprn=[snip]"
prefix: bins
map:
- value: "Black box"
icon: mdi:glass-tulip
name: "Black - glass and electronics Bin"
- value: "Green refuse"
icon: mdi:delete
name: "Green - refuse Bin"
- value: "Brown garden bin"
icon: mdi:nature
name: "Brown - garden bin"
- value: "Blue recycling bin"
icon: mdi:recycle
name: "Blue - recycling Bin"
- value: "Food caddy"
icon: mdi:food
name: "Grey - food Bin"
This gives me 5 sensors, for the coming 5 (sensor.binsx) bin pickups (also reflects cancellations etc - so long as they update their feed)
Unable to install Pup on my Ubuntu Server for some odd reason, would anyone be kind enough to give a brief description of how to get it installed?
Trying to get the info from Sedgemoor Council via the scrape sensor but its proving impossible!
Looks like this:
Why on earth does each council have to re-invent the wheel and list the dates in a different way on their own site! It would be a million times easier just to have a single site with all the dates for the whole country but that would be too easy.
Anyway I’m using HassOS which does not include ‘pup’ but it does include ‘curl’ and ‘jq’.
Are there any alterntives to ‘pup’, maybe some python parsing could work also
tell me about it!
I use a shell_command to pull and scrape the html:
curl -s "https://page.with/relevant.html"|iconv -f iso8859-1 -t utf-8|python3 -c '
import sys, re, itertools;
pattern = "crazyRegexPattern";
source = sys.stdin.read();
rx = re.compile(pattern, re.S);
data={};
for match in itertools.islice(rx.finditer(source ),3):
caps = {**match.groupdict(), "m":int(match.groupdict()["m"])+1};
data[caps["t"]]="{y}-{m}-{d}".format(**caps);
'
This pulls in the html into source
where you can then go nuts with python
Has anyone given any thought to “bin presence detection”. Meaning - don’t remind me to put my bins out if I have already put my bins out. Some thoughts that pop into mind:
- BLE inside the bin (yuck),
- Ultrasonic sensor + nodemcu pointing at the bin’s normal spot,
- Image processing / object recognition to see if bins are out on the street.
Any easier way that is a bit simpler / thinking outside the box?
Look out the window?
Our bins already have some sort of rfid in them, so the council trucks can tell if we are double dipping by putting them in a neighbouring street that has a different collection date. (I used to live in a street that had a different bin day on the other side of the street, twas great but was before they moved to the rfids!). Anyway, it seems to me that I could probably sort this sort of detection if I really wanted to.
yup its called a button on a dashboard.
when we put the bin out and come in agai, we push the button that we did it so that we dont get reminders anymore.
untill then we are reminded every hour.
Would you be able to share the code for that?
its an appdaemon app.
do you have appdaemon installed?
what it actually does:
check google calendar (installed in HA) at 0:00
if a bin needs to go out next day an input boolean is flipped to on
every day between set times it checks on the hour if the boolean is on
if the boolean is on it checks the calendars which bin needs to go out and send a notify (in my case alexa TTS)
Wow, RFID on a trashcan? That seems overkill to me. But I guess a few bad seeds will do that to ya. I honestly never thought about putting trash in a bin and rolling to another house on the street.