0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OpenWrt ホームアシスタント

Last updated at Posted at 2024-02-08

:warning:Japanese notation

検証中

はじめに

初心者対応構成

  • スクリプトでの自動設定
  • UCIとLuCi及びWinSCPにて比較しながら作業がおススメ

PowerShellSSHアクセス

ssh root@192.168.1.1
ssh root@192.168.1.1のショートカット作成(デスクトップ)
powershell
$DESKTOP = ([Environment]::GetFolderPath("Desktop") + "\192.168.1.1.lnk")
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$DESKTOP")
$Shortcut.TargetPath = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
$Shortcut.Arguments = '-windowstyle hidden -ExecutionPolicy RemoteSigned "Start-Process ssh root@192.168.1.1"'
$Shortcut.IconLocation = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe,0"
$Shortcut.WorkingDirectory = "."
$Shortcut.Save()

  • 強制的に貼り付け
  • yes

SSHログイン出来ない場合:exclamation:

known_hostsクリア

  • C:\Users\yourusername\.ssh\known_hosts ※Windows隠しファイル
powershell
Clear-Content .ssh\known_hosts -Force


OpenSSHのインストール
※Windows 10 Fall Creators Update(1709)以降標準搭載

  • 機能の確認
powershell
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'

  • 機能のインストール
powershell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0


前提条件

  • 対応機器 :
    • 256MBのストレージスペース
    • 256MBのRAM
  • 対応ファームウェア : 22.03 以降 ※FW4 (firewall4)
  • 構成状態 : 初期値前提
  • 動作確認 : 23.05.2@ BPI-R3

ホームアシスタント

インストール

wget https://raw.githubusercontent.com/openlumi/homeassistant_on_openwrt/23.05/ha_install.sh -O - | sh

# reboot
# /etc/init.d/homeassistant restart

※インストール時間: BPR-R3で約3分

Nature Remo のホーム アシスタントの統合

Nature Remoのサポート
HomeAssistantのご紹介とコマンド調教劇
OpenWrt上のContainer版HomeAssistantへのHACSのインストール
HACS

opkg update
# opkg remove uclient-fetch
opkg install wget-nossl
opkg install wget-ssl
opkg install bash

# reboot
# /etc/init.d/homeassistant restart

#sudo -u hass bash
wget -O - https://get.hacs.xyz | bash -

# reboot
# /etc/init.d/homeassistant restart

nature remoのトークン取得

#! /bin/sh
YOUR_ACCESS_TOKEN='token' # サインインで取得したトークン

/etc/init.d/homeassistant stop
cat <<"EOF" >> /etc/homeassistant/configuration.yaml
nature_remo:
  access_token:  ${YOUR_ACCESS_TOKEN}
EOF
cat <<"EOF" >> /etc/homeassistant/secrets.yaml
nature_remo_token:  ${YOUR_ACCESS_TOKEN}
EOF
sed -i -e "s/YOUR_ACCESS_TOKEN/${YOUR_ACCESS_TOKEN}/g" /etc/homeassistant/configuration.yaml
sed -i -e "s/YOUR_ACCESS_TOKEN/${YOUR_ACCESS_TOKEN}/g" /etc/homeassistant/secrets.yaml
mkdir -p /etc/homeassistant/custom_components/nature_remo
wget --no-check-certificate -O /etc/homeassistant/custom_components/nature_remo/__init__.py https://raw.githubusercontent.com/calee0219/hass-nature-remo/main/__init__.py
wget --no-check-certificate -O /etc/homeassistant/custom_components/nature_remo/climate.py https://raw.githubusercontent.com/calee0219/hass-nature-remo/main/climate.py
wget --no-check-certificate -O /etc/homeassistant/custom_components/nature_remo/manifest.json https://raw.githubusercontent.com/calee0219/hass-nature-remo/main/manifest.json
wget --no-check-certificate -O /etc/homeassistant/custom_components/nature_remo/sensor.py https://raw.githubusercontent.com/calee0219/hass-nature-remo/main/sensor.py
wget --no-check-certificate -O /etc/homeassistant/custom_components/nature_remo/switch.py https://raw.githubusercontent.com/calee0219/hass-nature-remo/main/switch.py
/etc/init.d/homeassistant start

リムーブ

# Deleting the home assistant in this way
/etc/init.d/homeassistant stop
pip3 uninstall homeassistant
rm -R /etc/homeassistant
rm -R /usr/lib/python*/site-packages/hass_frontend
rm -R /usr/lib/python*/site-packages/hass_nabucasa-*
rm -R /usr/lib/python*/site-packages/home_assistant_frontend-*
rm -R /etc/homeassistant
rm /etc/init.d/homeassistant

reboot

OpenWrt ルーターをホーム アシスタントに統合

opkg update
opkg install luci-mod-rpc

#! /bin/sh
ROUTER_IP_ADDRESS='192.168.1.1'
YOUR_ADMIN_PASSWORD='password' # rootのパスワードを入力

# Example configuration.yaml entry
cat <<"EOF" >> /etc/homeassistant/configuration.yaml
device_tracker:
  - platform: luci
    host: ROUTER_IP_ADDRESS
    username:  root
    password:  YOUR_ADMIN_PASSWORD
EOF
sed -i -e "s/ROUTER_IP_ADDRESS/${ROUTER_IP_ADDRESS}/g" /etc/homeassistant/configuration.yaml
sed -i -e "s/YOUR_ADMIN_PASSWORD/${YOUR_ADMIN_PASSWORD}/g" /etc/homeassistant/configuration.yaml

ACL

  • ユーザーhass作成
    ※hassパスワードは任意
HASS_PASSWD='openwrt'

opkg update
opkg install shadow
opkg install sudo
opkg install acl
opkg install luci-i18n-acl-ja
opkg install bash

useradd -m -d /home/hass -s /bin/ash -U hass
# passwd hass
#! /bin/sh
# Device Password
ubus call luci setPassword '{ "username": "hass", "password": "${HASS_PASSWD}" }'

sed -i -e "# %sudo ALL=(ALL:ALL) ALL/%sudo ALL=(ALL) ALL/g" /etc/sudoers 

groupadd --system sudo
usermod -a -G sudo hass

uci set rpcd.@login[1].username='hass'
uci set rpcd.@login[1].timeout='300'
uci set rpcd.@login[1].read='*'
uci set rpcd.@login[1].write='*'
uci set rpcd.@login[1].password='$p$root'
uci commit rpcd

# reboot

あとがき

インストール自体は、有志のおかげもあり、簡単
しかし、その後の設定が四苦八苦

参考資料(感謝:relaxed:

Home Assistant 2023.3.6 と OpenWRT 22.03.3 - またはその他の低予算ソリューション

OpenWrt 19.07 でマルチユーザー環境を構築

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?