لقد عملت على تطوير إعداد smarthome المستند إلى Home Assistant لمدة عام تقريبًا الآن (منذ مغادرة SmartThings) وبعد منحنى تعليمي أولي شديد الانحدار ، كنت سعيدًا جدًا بالمساعد المنزلي ، لذلك بدأت في العمل على توسيع نطاق الأشياء التي يقوم بها حيث إنني أعمل على توفير أساس طويل الأجل لمنزل ذكي. أحد الأشياء التي أردت إضافتها هو بيانات جمع bin لتذكيرني بالحاوية المستحقة ومتى. نظرًا لأنني أعيش في شيفيلد ، كنت بحاجة إلى سحب هذه البيانات من مزود المصادر الخارجية للسلطات المحلية (فيوليا). التفاصيل التالية كيف فعلت هذا, البناء كثيرًا على عمل الآخرين الذين فعلوا ذلك بالفعل في مناطق أخرى
Update 10-Aug-2022
I’ve tweaked the script to make it compatible with home assistant after the switch to Python 3
التحديث 20 ديسمبر 2021
I’ve made a change to both ths bash script AND the template — the first to make sure required packages are available and the second to fix a breaking change made by recent releases of home assistant
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.
أضف نصًا
- 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 script1234567891011121314151617181920212223242526272829303132333435import sysimport subprocessimport pkg_resourcesrequired = {‘beautifulsoup4’, ‘python-dateutil’, ‘requests’}installed = {pkg.key for pkg in pkg_resources.working_set}missing = required - installedif missing:python = sys.executablesubprocess.check_call([python, ‘-m’, ‘pip’, ‘install’, *missing], stdout=subprocess.DEVNULL)from bs4 import BeautifulSoupimport datetimefrom dateutil import parserimport requestsimport jsonurl = ‘https://wasteservices.sheffield.gov.uk/property/############’page = requests.get(url)if page.status_code != 200:exit(1)soup = BeautifulSoup(page.text, ‘html.parser’)out = {}bh3s = soup.find_all(‘td’, class_=“service-name”)bpds = soup.find_all(‘td’, class_=“next-service”)for i in range(len(bpds)):bin_colour = str(bh3s[i].contents[3]).lower().split(‘>’)[1].split(‘ ’)[0]out[bin_colour] = parser.parse(bpds[i].contents[2].lstrip().split(‘,’)[0]).strftime(‘%Y-%m-%d’)print(json.dumps(out))
- سوف تحتاج إلى استبدال ############ 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. يعمل منجم مرة واحدة في اليوم.123456sensor:- platform: command_linename: “Bin collections”command: “python3 /config/python-scripts/bin_collection.py”scan_interval: 86400command_timeout: 60 #needed as the website is slow to respond and will often timeout if left at default
أنشئ كيانات لكل نوع من أنواع الحاوية باستخدام config.yaml
- Immediately under the above section (لذلك لا يزال تحت جهاز الاستشعار: نشوئها ثانية) أضف ما يلي1234567891011121314- platform: templatesensors:black_bin:device_class: timestampvalue_template: ‘{{ strptime((states(“sensor.bin_collections”)|from_json())[“black”], “%Y-%m-%d”) | as_local }}’unique_id: “black_bin”brown_bin:device_class: timestampvalue_template: ‘{{ strptime((states(“sensor.bin_collections”)|from_json())[“brown”], “%Y-%m-%d”) | as_local }}’unique_id: “brown_bin”blue_bin:device_class: timestampvalue_template: ‘{{ strptime((states(“sensor.bin_collections”)|from_json())[“blue”], “%Y-%m-%d”) | as_local }}’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
أعتقد أننا فقدنا شيء ما? دعنا نعلم بتعليقك بالأسفل. إذا كنت ترغب في الاشتراك يرجى استخدام الرابط الاشتراك في القائمة في اعلى اليمين. يمكنك أيضا مشاركة هذا مع أصدقائك باستخدام الروابط الاجتماعية أدناه. في صحتك.
اترك رد