I’ve been developing my Home Assistant based smarthome setup for around a year now (since leaving SmartThings) and after an initial steep learning curve I’ve been veyr happy with home assistant so I have started working to expand the things it does as I am conifdent it offers a long term basis for my smarthome. One thing I wanted to add was bin collection data to remind me which bin is due when. As I live in Sheffield I needed to pull this data from the local authorities out-sources provider (فيوليا). The following details how I did this, building very much on the work of others who have done it already for other regions
I used a script which i modified from various examples on a HA support thread by RobBrad. For this script to run I needed to install the beautifulsoup module on home-assistant.
قم بتثبيت وحدة BeautifulSoup python
- Install the Supervisor add-on ‘SSH and Web Terminal’
- Open the terminal from the main left-hand menu
- Use the command pip3 تثبيت beautifulsoup4
أضف نصًا
- I use the ‘Samba Share’ supervisor addon to access my home assistant files directly from my windows PC — unless you already have a preferred access method I recommend doing the same
- اذهب الى \\ha-ip-address config
- create a مخطوطات بيثون ملف
- Create a new python script in this folder — I called mine bin_collection.py
- Insert the following script
from bs4 import BeautifulSoup import datetime from dateutil import parser import requests import json url = 'https://wasteservices.sheffield.gov.uk/property/############' page = requests.get(رابط) إذا page.status_code != 200: خروج(1) حساء = شوربة جميلة(page.text, "html.parser") خارج = {} bh3s = soup.find_all('td', فئة_ ="اسم الخدمة") bpds = soup.find_all('td', فئة_ ="الخدمة التالية") لأني في النطاق(فقط(بي بي دي إس)): bin_colour = str(bh3s[أنا].محتويات[3]).أدنى().انشق، مزق('>')[1].انشق، مزق(")[0] خارج[بن_اللون] = محلل(بي بي دي إس[أنا].محتويات[2].lstrip().انشق، مزق(',')[0]).strftime('٪ Y-٪ m-٪ d') مطبعة(json.dumps(خارج))
- سوف تحتاج إلى استبدال ############ with the unique number for your property which I will explain how to get in the next step
احصل على عنوانك الفريد
- اذهب الى https://wasteservices.sheffield.gov.uk/property/
- أدخل رمزك البريدي وحدد عنوانك من القائمة
- قم بتدوين عنوان url الجديد. Use it in the url line in the script above — the only part you will need to change is the 12 digit number at the end
اتصل بالبرنامج النصي الخاص بك من config.yaml
- إدخال بسيط في config.yaml هو كل ما هو مطلوب لتشغيل البرنامج النصي
- You may want to adjust the frequency of the run. Mine runs once per day.
المستشعر: - منصة: command_line name: "مجموعات بن" يأمر: "python3 /config/python-scripts/bin_collection.py" scan_interval: 86400 مهلة_القيادة: 60 #مطلوب لأن موقع الويب بطيء في الاستجابة وغالبًا ما تنتهي مهلته إذا تم تركه افتراضيًا
أنشئ كيانات لكل نوع من أنواع الحاوية باستخدام config.yaml
- Immediately under the above section (لذلك لا يزال تحت جهاز الاستشعار: نشوئها ثانية) أضف ما يلي
- منصة: template sensors: black_bin: device_class: timestamp value_template: '{{ (تنص على("أجهزة الاستشعار")|from_json())["أسود"] }}' unique_id: "black_bin" بني_بن: device_class: timestamp value_template: '{{ (تنص على("أجهزة الاستشعار")|from_json())["بني"] }}' unique_id: "بني_بن" blue_bin: device_class: timestamp value_template: '{{ (تنص على("أجهزة الاستشعار")|from_json())["أزرق"] }}' unique_id: "blue_bin"
اعرض النتائج على الواجهة الأمامية
- To show the results on the front end simply add a card with the 3 أجهزة استشعار عليه (specifically sensor.black_bin, جهاز الاستشعار, والمستشعر)
- Note you may need to restart home assistant to load the new sensors you added to configuration.yaml
وجدت هذا مفيدا? يرجى إعلامنا عن طريق إسقاط التعليق أدناه. إذا كنت ترغب في الاشتراك يرجى استخدام الرابط الاشتراك في القائمة في اعلى اليمين. يمكنك أيضا مشاركة هذا مع أصدقائك باستخدام الروابط الاجتماعية أدناه. في صحتك.
اترك رد