Docker 部署 Home Assistant 并接入米家与 ESPHome

安装 Home Assistant

docker run -d \
  -<span class="ruby">-name homeassistant \
</span>  -<span class="ruby">-privileged \
</span>  -<span class="ruby">-restart=<span class="hljs-keyword">unless</span>-stopped \
</span>  -<span class="ruby">e TZ=MY_TIME_ZONE \
</span>  -<span class="ruby">v /<span class="hljs-symbol">PATH_TO_YOUR_CONFIG:</span>/config \
</span>  -<span class="ruby">v /run/<span class="hljs-symbol">dbus:</span>/run/<span class="hljs-symbol">dbus:</span>ro \
</span>  -<span class="ruby">-network=host \
</span>  ghcr.io/home-assistant/home-assistant:stable

From home-assistant.io/installation/linux

IP:8123

这里省略初始化过程,简单点击几个按钮即可

安装 HACS

docker exec -it homeassistant bash
wget -O - https:<span class="hljs-regexp">//g</span>et.hacs.xyz | bash -
<span class="hljs-keyword">exit</span>
reboot

点击右下角的齿轮图标,选择 设备与服务,然后点击 添加集成 在弹出的页面中搜索 HACS,并选择进行安装。 按提示输入 GitHub 授权码完成登录。

安装 Xiaomi Miot Atuo

在左侧菜单中点击 HACS,搜索 Xiaomi Miot Auto,然后选择下载安装 下载完成后,重启 Home Assistant

接入米家设备

点击左下角的齿轮图标,选择 设备与服务,然后点击 设备 点击添加设备,搜索 Xiaomi Miot Auto,并选择 Add devices using Mi Account 进行账号集成。 输入小米账号(即米家 APP 我的页面顶部的数字) 和密码。 在设备连接模式下,选择 Auto

验证

回到设备页面,随便点击一个米家设备 中间的控制菜单必须有等于或多余 1 个控制项

安装 ESPHome

这里以 ESP32+DHT11 温湿度传感器为例 于使用 Docker 部署,无法直接通过 Home Assistant 添加插件

docker <span class="hljs-built_in">run</span> -d  --name=<span class="hljs-string">"ESPHome"</span> -e TZ=Asia/Shanghai   -v /<span class="hljs-built_in">home</span>/esphome:/<span class="hljs-built_in">config</span>  -v /<span class="hljs-built_in">run</span>/udev:/<span class="hljs-built_in">run</span>/udev  --privileged  --restart=always  --net=host esphome/esphome

IP:6052

安装 ESPHome 到 ESP32

点击右下角的 NEW DEVICE,然后点击 OPEN ESPHOME WEB 在新页面中选择 CONNECT,选择 ESP32,并点击 INSTALL 进行安装, 安装完成后,进行 WIFI 配置,注意 ESP32 只支持 2.4GHz 的 WIFI 回到 ESPHome 页面,点击 ADOPT 当出现安装页面时,直接点击右下角的 STOP,我们将使用另一种更快的方法

接线

DHT11(有孔那面,由左到右) VCC DATA NC GND

VCC > 3.3V DATA > D2 NC GND > GND P.S: 这里需要注意,必须在 VCC 与 DATA 中串一个 4.7kΩ的电阻

编译固件

以下配置基于我的需求,请根据实际情况进行相应修改

<span class="hljs-attr">substitutions:</span>
<span class="hljs-attr">  name:</span> esphome-web-xxxxxx
<span class="hljs-attr">  friendly_name:</span> ESPHome Web xxxxxx

<span class="hljs-attr">esphome:</span>
<span class="hljs-attr">  name:</span> ${name}
<span class="hljs-attr">  friendly_name:</span> ${friendly_name}
<span class="hljs-attr">  min_version:</span> <span class="hljs-number">2024.6</span><span class="hljs-number">.0</span>
<span class="hljs-attr">  name_add_mac_suffix:</span> <span class="hljs-literal">false</span>
<span class="hljs-attr">  project:</span>
<span class="hljs-attr">    name:</span> esphome.web
<span class="hljs-attr">    version:</span> dev

<span class="hljs-attr">esp32:</span>
<span class="hljs-attr">  board:</span> esp32dev
<span class="hljs-attr">  framework:</span>
<span class="hljs-attr">    type:</span> arduino

<span class="hljs-comment"># Enable logging</span>
<span class="hljs-attr">logger:</span>

<span class="hljs-comment"># Enable Home Assistant API</span>
<span class="hljs-attr">api:</span>

<span class="hljs-comment"># Allow Over-The-Air updates</span>
<span class="hljs-attr">ota:</span>
<span class="hljs-attr">- platform:</span> esphome

<span class="hljs-comment"># Allow provisioning Wi-Fi via serial</span>
<span class="hljs-attr">improv_serial:</span>

<span class="hljs-attr">wifi:</span>
  <span class="hljs-comment"># Set up a wifi access point</span>
<span class="hljs-attr">  ap:</span> {}

<span class="hljs-comment"># In combination with the `ap` this allows the user</span>
<span class="hljs-comment"># to provision wifi credentials to the device via WiFi AP.</span>
<span class="hljs-attr">captive_portal:</span>

<span class="hljs-attr">dashboard_import:</span>
<span class="hljs-attr">  package_import_url:</span> github://esphome/example-configs/esphome-web/esp32.yaml@main
<span class="hljs-attr">  import_full_config:</span> <span class="hljs-literal">true</span>

<span class="hljs-comment"># Sets up Bluetooth LE (Only on ESP32) to allow the user</span>
<span class="hljs-comment"># to provision wifi credentials to the device.</span>
<span class="hljs-attr">esp32_improv:</span>
<span class="hljs-attr">  authorizer:</span> none

<span class="hljs-comment"># To have a "next url" for improv serial</span>
<span class="hljs-attr">web_server:</span>

<span class="hljs-comment"># Example configuration entry</span>
<span class="hljs-attr">sensor:</span>
<span class="hljs-attr">  - platform:</span> dht
<span class="hljs-attr">    pin:</span> GPIO2 
<span class="hljs-attr">    temperature:</span>
<span class="hljs-attr">      name:</span> <span class="hljs-string">"Temperature"</span>
<span class="hljs-attr">    humidity:</span>
<span class="hljs-attr">      name:</span> <span class="hljs-string">"Humidity"</span>
<span class="hljs-attr">    update_interval:</span> <span class="hljs-number">60</span>s
pip <span class="hljs-keyword">install</span> esphome 
esphome compile <span class="hljs-number">0</span>.yaml <span class="hljs-comment">#修改成上方的 yaml 文件</span>

编译后的固件位于.pioenvs\esphome-web-8ffb98\firmware.bin

ESP32 的 IP:80 OTA Update>选择 firmware.bin 文件>Update

接入 ESPHome

点击左下角的齿轮图标,选择 设备与服务,然后点击设备 点击添加设备,选择 ESPHome,并在主机字段中输入 ESP32 的 IP 地址(注意:这里输入的是 ESP32 的 IP,而非 ESPHome 服务端的 IP) 再后回到设备页面,应该会看到设备名为 ESPHome Web xxxxxx

Armbian 安装 Qbittorrent Nox 最新版并添加进程守护

cat << EOF > <span class="hljs-regexp">/etc/</span>apt/sources.list
deb <span class="hljs-string">http:</span><span class="hljs-comment">//ftp.de.debian.org/debian bullseye main</span>
EOF

echo <span class="hljs-string">'deb http://download.opensuse.org/repositories/home:/nikoneko:/test/Raspbian_11/ /'</span> | sudo tee <span class="hljs-regexp">/etc/</span>apt<span class="hljs-regexp">/sources.list.d/</span><span class="hljs-string">home:</span><span class="hljs-string">nikoneko:</span>test.list
curl -fsSL <span class="hljs-string">https:</span><span class="hljs-comment">//download.opensuse.org/repositories/home:nikoneko:test/Raspbian_11/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_nikoneko_test.gpg > /dev/null</span>
sudo apt update

apt --fix-broken install qbittorrent-nox -y

cat << EOF > <span class="hljs-regexp">/etc/</span>systemd<span class="hljs-regexp">/system/</span>qbittorrent-nox.service
[Unit]
Description=qBittorrent Command Line Client
After=network.target
[Service]
Type=forking
User=root
ExecStart=<span class="hljs-regexp">/usr/</span>bin/qbittorrent-nox -d --webui-port=<span class="hljs-number">8080</span>
ExecStop=<span class="hljs-regexp">/usr/</span>bin/kill -w qbittorrent-nox
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

systemctl enable qbittorrent-nox
systemctl start qbittorrent-nox

qbittorrent-nox <span class="hljs-keyword">default</span>

The WebUI administrator username is: admin The WebUI administrator password was not set. A temporary password is provided for this session: xxxxxxxx You should set your own password in program preferences.

Typecho 使用 ChatGPT 为博客自动生成简介/摘要

安装插件

idealclover/AISummary-Typecho 安装插件就不多说了,就丢到插件目录里,重命名

设置插件

提升词

我所用的提升词如下: 你的任务是生成文章的摘要。请你根据以下文章内容生成 100 字内的摘要,內容尽量针对 seo 优化,请不要带有链接,除了你生成的摘要内容,请不要输出其他任何无关内容。

模型

一般来说gpt-3.5-turbo-16k够用了,或者 gpt4 也行

CSS

<span class="hljs-selector-class">.aisummary</span> {
  <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#f0f0f0</span>;
  <span class="hljs-attribute">padding</span>: <span class="hljs-number">20px</span>;
  <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">5px</span>;
  <span class="hljs-attribute">margin-bottom</span>: <span class="hljs-number">20px</span>;
}

<span class="hljs-selector-class">.aisummary</span> <span class="hljs-selector-tag">p</span> {
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>;
  <span class="hljs-attribute">line-height</span>: <span class="hljs-number">1.5</span>;
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#333</span>;
}

<span class="hljs-selector-class">.aisummary</span> <span class="hljs-selector-tag">a</span> {
  <span class="hljs-attribute">color</span>: <span class="hljs-number">#007bff</span>;
  <span class="hljs-attribute">text-decoration</span>: none;
}

<span class="hljs-selector-class">.aisummary</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> {
  <span class="hljs-attribute">text-decoration</span>: underline;
}

自动同步到简介

<span class="hljs-tag"><<span class="hljs-name">script</span>></span><span class="javascript"><span class="hljs-built_in">window</span>.addEventListener(<span class="hljs-string">"load"</span>,(<span class="hljs-function"><span class="hljs-keyword">function</span>()</span>{<span class="hljs-keyword">var</span> t=<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"ai"</span>),e=<span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">'meta[name="description"]'</span>);t&&e&&e.setAttribute(<span class="hljs-string">"content"</span>,t.textContent)}));</span><span class="hljs-tag"></<span class="hljs-name">script</span>></span>

`测试过 google 可用,bing 未知,至少我的没有成功

Tyepcho 博客添加 Open Graph 图片

在 Typecho 中使用:

<<span class="hljs-function"><span class="hljs-title">meta</span> property="og:image" content="//example.org/og/?<span class="hljs-built_in">title</span>=<?php $this-></span><span class="hljs-function"><span class="hljs-title">title</span>(); ?>&des=<?php $this-></span>description(); ?><span class="hljs-string">"/></span>
<span class="php"><span class="hljs-meta"><?php</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">og</span><span class="hljs-params">($title, $des)</span> </span>{
    $img = imagecreatefrompng(<span class="hljs-string">'./bg.png'</span>);
    $black = imagecolorallocate($img, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>);
    $title_font = <span class="hljs-string">'./ZhanKuKuaiLeTi2016XiuDingBan-1.ttf'</span>;
    $desc_font = <span class="hljs-string">'./ZhanKuKuaiLeTi2016XiuDingBan-1.ttf'</span>;
    $title_lines = explode(<span class="hljs-string">"\n"</span>, wordwrap($title, <span class="hljs-number">30</span>, <span class="hljs-string">"\n"</span>, <span class="hljs-keyword">true</span>));
    $desc_lines = explode(<span class="hljs-string">"\n"</span>, wordwrap($des, <span class="hljs-number">60</span>, <span class="hljs-string">"\n"</span>, <span class="hljs-keyword">true</span>));
    $title_y = <span class="hljs-number">60</span>;
    $desc_y = <span class="hljs-number">200</span>;

    <span class="hljs-keyword">foreach</span> ($title_lines <span class="hljs-keyword">as</span> $line) {
        imagettftext($img, <span class="hljs-number">55</span>, <span class="hljs-number">0</span>, <span class="hljs-number">10</span>, $title_y, $black, $title_font, $line);
        $title_y += <span class="hljs-number">65</span>;
    }

    <span class="hljs-keyword">foreach</span> ($desc_lines <span class="hljs-keyword">as</span> $line) {
        imagettftext($img, <span class="hljs-number">25</span>, <span class="hljs-number">0</span>, <span class="hljs-number">10</span>, $desc_y, $black, $desc_font, $line);
        $desc_y += <span class="hljs-number">30</span>;
    }

    header(<span class="hljs-string">'Content-Type: image/png'</span>);
    imagepng($img);
    imagedestroy($img);
}

<span class="hljs-comment">// Retrieve title and description from URL parameters</span>
$title = <span class="hljs-keyword">isset</span>($_GET[<span class="hljs-string">'title'</span>]) ? $_GET[<span class="hljs-string">'title'</span>] : <span class="hljs-string">'Default Title'</span>;
$des = <span class="hljs-keyword">isset</span>($_GET[<span class="hljs-string">'des'</span>]) ? $_GET[<span class="hljs-string">'des'</span>] : <span class="hljs-string">'Default Description'</span>;

<span class="hljs-comment">// Example usage:</span>
og($title, $des);
<span class="hljs-meta">?></span></span>

Ubuntu 搭建欧卡 2/美卡联机服务器 详细教程

理论上适用於美卡和欧卡,但是本文基于欧卡,美卡请自行探索~ 两款游戏经常打折,最低价 11,日常 30 多 高于 30 不建议买,另外,DLC 也是建议打折再买,可以省下不少钱

steamcmd 安装

From

sudo<span class="hljs-built_in"> add-apt-repository </span>multiverse; sudo dpkg --add-architecture i386; sudo apt update 
sudo apt install steamcmd
steamcmd
login anonymous

这里需要注意: 欧卡 id: 1948160 美卡 id: 2239530 这里以欧卡为例 app_update 1948160

安装后 cd 到游戏目录 cd '/Steam/steamapps/common/Euro Truck Simulator 2 Dedicated Server'

到这里,安装的部分就告一段落了

获取配置文件

在游戏中按~这个键,输入export_server_packages 然后打开Documents\Euro Truck Simulator 2 找到server_packages.dat,server_packages.sii 复制到save

启动

<span class="hljs-keyword">cd</span> <span class="hljs-string">'/Steam/steamapps/common/Euro Truck Simulator 2 Dedicated Server/bin/linux_x64/'</span>
chmod -xxx server_launch.<span class="hljs-keyword">sh</span>
./server_launch.<span class="hljs-keyword">sh</span>

公开列表

如果想让服务器公开到运联列表(默认是只能搜索数字的) 在这部折腾好久,最后发现欧卡的搜索有点问题,我打开的选择性模组然后就搜不到啦~ server_config.sii: 确保mods_optioning: false不然搜不到,并且show_server: true打开

打开 steam: https://steamcommunity.com/dev/managegameservers 欧卡 id: 1948160 美卡 id: 2239530 把获取到的 key 放到server_config.siiserver_logon_token

管理员

建议把自己设置为管理员 获取自己 steam id 的步骤: 打开 steam,点击右上角用户名,在左上角标题下面那行小字就是 id 啦 最后在server_config.sii:

<span class="hljs-attribute">moderator_list</span>: 1
 <span class="hljs-attribute">moderator_list[0]</span>: 你的 steamid

“`开始快乐的卡车生涯吧~ 说实话 tmp 更好玩