i got several apps that get information from the internet.
ill give you one so you can look at it.
this app searches 2 websites for waterlevels from the river i live by.
then the app creates sensors in HA with that info.
in your case i would create a simular app.
it should search your guide and then create sensors for the next time a channel should be changed.
in another app you could then make use from the created sensors.
here it is:
###########################################################################################
# #
# Rene Tode ( [email protected] ) #
# #
# 2017/09/04 Germany #
# #
# #
# create waterlevel sensors #
# #
###########################################################################################
import appdaemon.plugins.hass.hassapi as hass
import datetime
from socket import timeout
import time
import requests
from bs4 import BeautifulSoup
class waterstanden(hass.Hass):
def initialize(self):
self.url = "http://www.hochwasser-rlp.de/vorhersage-wasserstaende/uebersicht/flussgebiet/mosel"
self.wsv_url = "https://www.pegelonline.wsv.de/gast/pegelinformationen?scrollPosition=0&gewaesser=MOSEL&order_flusskm_desc.x=7&order_flusskm_desc.y=6"
self.orten = {"trier": "TRIER UP","perl": "PERL","zeltingen":"ZELTINGEN UP","cochem":"COCHEM"}
runtime = datetime.time(12, 37, 12)
self.timestamp = datetime.datetime.now()
self.run_hourly(self.checknow,runtime)
self.checknow(self)
def checknow(self,kwargs):
actual_time = datetime.datetime.now()
data = self.get_RLP_values()
if data == "no data":
self.get_wsv_values()
for ort,wsv_ort in self.orten.items():
self.set_state("sensor.voorspelling6_waterstand_" + ort, state = "geen", attributes = {"friendly_name": "6 uurs voorspelling"})
self.set_state("sensor.voorspelling9_waterstand_" + ort, state = "geen", attributes = {"friendly_name": "9 uurs voorspelling"})
self.set_state("sensor.voorspelling24_waterstand_" + ort, state = "geen", attributes = {"friendly_name": "24 uurs voorspelling"})
def get_RLP_values(self):
try:
response = requests.get(self.url,timeout=10)
page = response.content
soup = BeautifulSoup(page, "html.parser")
table = soup("table", class_="datatable wasserstaende")
rows = table[0]("tr")
#self.log("got data from RLP")
except:
return "no data"
mosel = rows[1]("td")
mosel_prev_time = mosel[1].text
mosel_last_time = mosel[2].text
counter = 2
while counter < 6:
ortsline = rows[counter]("td")
if not "-" in ortsline[2].text:
self.set_state("sensor.waterstand_" + ortsline[0].text.lower(), state = ortsline[2].text, attributes = {"friendly_name":mosel_last_time,"tijd": mosel_last_time,"website": "RLP"})
if not "-" in ortsline[1].text:
self.set_state("sensor.vorige_waterstand_" + ortsline[0].text.lower(), state = ortsline[1].text, attributes = {"friendly_name":mosel_prev_time,"tijd": mosel_prev_time,"website": "RLP"})
#self.log(self.get_state("sensor.vorige_waterstand_" + ortsline[0].text.lower()))
try:
prev_level = int(self.get_state("sensor.vorige_waterstand_" + ortsline[0].text.lower()))
actual_level = int(self.get_state("sensor.waterstand_" + ortsline[0].text.lower()))
state = actual_level - prev_level
except:
state = "onbekend"
self.set_state("sensor.verschil_waterstand_" + ortsline[0].text.lower(), state = state, attributes = {"friendly_name":"verschil","tijd": mosel_last_time,"website": "RLP"})
counter = counter + 1
#self.log(waterlevels)
try:
table = soup("table", class_="datatable vorhersagen")
rows = table[0]("tr")
times = rows[0]("th")
time1=times[1].text.split(":")
sixhourtime = time1[1][4:]+":"+time1[2][:-4]
sixhourtime = sixhourtime.replace(".","-")
time2=times[2].text.split(":")
ninehourtime = time2[1][4:]+":"+time2[2][:-4]
ninehourtime = ninehourtime.replace(".","-")
time3=times[3].text.split(":")
twentyfourhourtime = time3[1][4:]+":"+time3[2][:-4]
twentyfourhourtime = twentyfourhourtime.replace(".","-")
counter = 2
while counter < 6:
ortsline = rows[counter]("td")
self.set_state("sensor.voorspelling6_waterstand_" + ortsline[0].text.lower(), state = self.get_prediction_str(ortsline[0].text.lower(),ortsline[1].text), attributes = {"friendly_name": sixhourtime,"tijd": sixhourtime})
self.set_state("sensor.voorspelling9_waterstand_" + ortsline[0].text.lower(), state = self.get_prediction_str(ortsline[0].text.lower(),ortsline[3].text), attributes = {"friendly_name": ninehourtime,"tijd": ninehourtime})
self.set_state("sensor.voorspelling24_waterstand_" + ortsline[0].text.lower(), state = self.get_prediction_str(ortsline[0].text.lower(),ortsline[5].text), attributes = {"friendly_name": twentyfourhourtime,"tijd": twentyfourhourtime})
counter = counter + 1
return "sensors set"
except:
return "no data"
def get_prediction_str(self,ort,raw_prediction):
try:
predictionparts = raw_prediction.split("-")
predictionaverage = int((int(predictionparts[0]) + int(predictionparts[1]))/2)
predictionrange = int((int(predictionparts[0]) - int(predictionparts[1]))/2)
actual = int(self.get_state("sensor.waterstand_" + ort))
if predictionrange < 0:
predictionrange = -(predictionrange)
predictiondifference = int(predictionaverage - actual)
predictionstr = str(predictiondifference) + " +- " + str(predictionrange)
except:
predictionstr = "onbekend"
return predictionstr
def get_wsv_values(self):
#self.log("no rlp so get wsv")
try:
try:
response = requests.get(self.wsv_url,timeout=10)
except:
self.log("wsv timeout")
return
page = response.content
soup = BeautifulSoup(page, "html.parser")
table = soup("table")
body = table[1]("tbody")
rows = body[0]("tr")
for counter in range(1,12):
cellen = rows[counter]("td")
for ort,wsv_ort in self.orten.items():
if cellen[0].text == wsv_ort:
datestr = cellen[4].text
timestr = cellen[5].text.strip()
waterlevel = cellen[6].text.strip()
waterlevel = waterlevel[:-2].strip()
prevtime = ""
prevlevel = ""
prevtime2 = ""
prevlevel2 = ""
if self.entity_exists("sensor.waterstand_" + ort):
prevlevel = self.get_state("sensor.waterstand_" + ort)
prevtime = self.get_state("sensor.waterstand_" + ort,attribute = "tijd")
if self.entity_exists("sensor.vorige_waterstand_" + ort):
prevlevel2 = self.get_state("sensor.vorige_waterstand_" + ort)
prevtime2 = self.get_state("sensor.vorige_waterstand_" + ort,attribute = "tijd")
if prevtime != timestr :
#self.log("waterstand niveau in HA gevonden: " + ort + " : " + prevtime + " : " + prevlevel + ", " + prevlevel2 + " > sensor gezet")
self.set_state("sensor.waterstand_" + ort, state = waterlevel, attributes = {"friendly_name":timestr,"tijd": timestr,"website": "WSV"})
if prevtime2 != "" and prevtime != "" and prevlevel != "":
self.set_state("sensor.vorige_waterstand_" + ort, state = prevlevel, attributes = {"friendly_name":prevtime,"tijd": prevtime,prevtime2: prevlevel2,"website": "WSV"})
difference = int(int(waterlevel) - int(prevlevel))
self.set_state("sensor.verschil_waterstand_" + ort, state = difference, attributes = {"friendly_name":"verschil","tijd": timestr,"website": "WSV"})
elif prevtime != "" and prevlevel != "":
self.set_state("sensor.vorige_waterstand_" + ort, state = prevlevel, attributes = {"friendly_name":prevtime,"tijd": prevtime,"website": "WSV"})
#self.log("got data from WSV")
except:
self.log("error in getting WSV data")
def make_utf(self, date):
new_date = date.replace("januari","januar")
new_date = new_date.replace("februari","februar")
new_date = new_date.replace("maart","march")
new_date = new_date.replace("mei","may")
new_date = new_date.replace("juni","june")
new_date = new_date.replace("juli","july")
new_date = new_date.replace("augustus","august")
new_date = new_date.replace("oktober","october")
return datetime.datetime.strptime(new_date, "%d %B %Y")
there are probably a lot of things that can be done better. this app is over a year old and i have learned a lot of new stuff in python since then. but it works so i dont care if it is pretty or best written
edit: and sorry that there are no comments, it wasnt written to share