I don’t, but here’s the bin collection one as an example. Uses Python’s BeautifulSoup module to scrape the council website, which is a bit more complex than HA’s scrape sensor can cope with; and creates/updates the three timestamp sensors that show the next collection dates for my bins:
import hassapi as hass
from bs4 import BeautifulSoup
import datetime
from dateutil import parser
import requests
class BinCollection(hass.Hass):
def initialize(self):
"""Sets up the uprn and the first run"""
self.log("Bin collection app running")
self.uprn = 'xxxxxx'
self.run_in(self.refresh, 5)
def refresh(self, kwargs):
"""Looks up the data, sets next run at 2am tomorrow"""
url = "https://www.lichfielddc.gov.uk/homepage/6/" \
f"bin-collection-dates?uprn={self.uprn}"
page = requests.get(url)
if page.status_code != 200:
return None
soup = BeautifulSoup(page.text, 'html.parser')
bh3s = soup.find_all('h3', class_="bin-collection-tasks__heading")
bpds = soup.find_all('p', class_="bin-collection-tasks__date")
for i in range(len(bpds)):
bin_colour = bh3s[i].contents[1].split(' ')[0].lower()
bin_date = parser.parse(bpds[i].contents[0]).strftime('%Y-%m-%d')
self.log(f"{bin_date}: {bin_colour} bin")
self.set_state(f"sensor.{bin_colour}_bin",
state=bin_date,
attributes={'device_class': 'timestamp'})
tomorrow = datetime.datetime.today() + datetime.timedelta(days=1)
next_run = tomorrow.replace(hour=2, minute=0, second=0, microsecond=0)
self.log(f"Scheduling next run for {next_run.isoformat()}")
self.run_at(self.refresh, next_run)
would either of those two scenes be activated at exactly 01:00:00, and if not, what would be the way to efficiently make one of them activate at exactly 01:00:00 ?
@mmiller7 conditions work the same everywhere, so the result would be the same for your tests. It doesn’t matter whether it’s an automation’s condition, a choose or an if.
@jsh the answer is right before your post: after is inclusive and before is exclusive. But, because of the ambiguity and readability in some cases, I just opt for a template condition to make it explicit (using the various comparison operators).