私はホームアシスタントベースのスマートホームセットアップを約1年前から開発しています (SmartThingsを離れてから) 最初の急な学習曲線の後、私はホームアシスタントに非常に満足していたので、スマートホームの長期的な基盤を提供すると確信しているので、ホームアシスタントの機能を拡張する作業を開始しました。. 追加したかったことの1つは、ビン収集データで、どのビンがいつ期限になるかを思い出させることでした。. 私はシェフィールドに住んでいるので、地方自治体のアウトソースプロバイダーからこのデータを取得する必要がありました (ヴェオリア). 以下は私がこれをどのようにしたかを詳しく説明します, 他の地域のためにすでにそれを行った他の人の仕事に非常に基づいて構築する
Update 10-Aug-2022
I’ve tweaked the script to make it compatible with home assistant after the switch to Python 3
2021年12月20日更新
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
さまざまな例から変更したスクリプトを使用しました RobBradによるHAサポートスレッド. このスクリプトを実行するには、Beautifulsoupモジュールをホームアシスタントにインストールする必要がありました.
スクリプトを追加する
- 「SambaShare」スーパーバイザーアドオンを使用して、Windows PCから直接ホームアシスタントファイルにアクセスします。優先するアクセス方法が既にない場合は、同じようにすることをお勧めします。
- 参照する \\ha-ip-address config
- 作成する python-scripts フォルダ
- このフォルダに新しいPythonスクリプトを作成します—私は私のと呼びました bin_collection.py
- 次のスクリプトを挿入します1234567891011121314151617181920212223242526272829303132333435import 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))
- 交換する必要があります ############ 次のステップで取得する方法を説明するあなたの財産の一意の番号で
一意のアドレスを取得する
- を参照 https://wasteservices.sheffield.gov.uk/property/
- 郵便番号を入力し、リストから住所を選択します
- 新しいURLをメモします. 上記のスクリプトのURL行で使用してください—変更する必要があるのは 12 最後の桁番号
configuration.yamlからスクリプトを呼び出します
- スクリプトを実行するために必要なのは、configuration.yamlの単純なエントリだけです。
- 実行の頻度を調整することをお勧めします. 鉱山は1日1回実行されます.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
configuration.yamlを使用して、ビンのタイプごとにエンティティを作成します
- 上記のセクションのすぐ下 (まだセンサーの下にあります: セクション) 以下を追加します。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”
フロントエンドに結果を表示する
- フロントエンドに結果を表示するには、カードを追加するだけです。 3 その上のセンサー (具体的にはsensor.black_bin, sensor.blue_bin, およびsensor.brown_bin)
- configuration.yamlに追加した新しいセンサーをロードするには、HomeAssistantを再起動する必要がある場合があることに注意してください
あなた自身のいくつかの考えを持って? コメントに下記をお楽しみください! あなたが購読したい場合は、右上のメニューで購読リンクをご利用ください. また、下記の社会的なリンクを使用してお友達とこれを共有することができます. 乾杯.
返信を残す