Programmer's entertainment: the Kindle lock screen displays the component information in homeassistant and obtains the Kindle power in homeassistant

Mintimate 2022-05-04 16:03:18 阅读数:840

programmerentertainmentkindlelockscreen
The head picture can be less ??? Obviously not.

Blog :https://www.mintimate.cn

Mintimate’s Blog, Just to share with you

Now everything pays attention to interconnection , I introduced it a while ago Smart bubble panel Kindle Prison break and raspberry pie installation Home Assistant. This time, , Let's teach you how to organically combine the two , Realization :

  • Kindle Replace the lock screen with Home Assistant The monitoring panel , And refresh regularly (KPW4 And above , You may have to press the power key or wake up the smart cover , It's fine too Kindle Always turn on the power before , because Kindle The economizer will be disconnected Wi-Fi).
  • Home Assistant You can see Kindle The remaining power of (KPW4 And above , ditto ).

Article premise

The premise is simple , As mentioned above , We need to :

Be careful ️:KPW4 And above Kindle, Because the screen will be automatically disconnected after locking Wi-Fi, And because of firmware , The user cannot press the power button again until the power button is turned on ; So automatically and regularly declare data , stay KPW4 in the future , The user needs to manually light up the screen to make a declaration ( Mainly , I don't know Kindle Of Wake Up What is the instruction ……), perhaps ~ You can take Kindle Keep the power on for power on ~~ This will not trigger sleep break Wi-Fi The mechanism of .

Realization effect

The effect is very simple , for instance : our Home Assistant The monitoring panel :

Control panel

After us , Take a screenshot of the page and sharpen it , You can get such a black-and-white picture :

Processed pictures

Last , Push it to Kindle On , Apply as lock screen wallpaper :

Lock screen wallpaper

Be careful : This is the lock screen wallpaper , No Kindle Built in browser .

coordination Home Assistant The built-in Webhook hook ( Be similar to Git Of hook), Can achieve Kindle Power tracking :

Kindle Power tracking

When charging Kindle Will not start sleep off the network , It can be used to track power consumption :

Kindle Power tracking

wuhu , Charging is still very fast ⁄(⁄ ⁄ ⁄ω⁄ ⁄ ⁄)⁄

The preparation of the instruments

The tools to prepare are simple , Remove the basic Kindle Prison break and Home Assistant Out of demand , We also need plug-ins :

  • Kindle plug-in unit Kual: For managing plug-ins
  • Kindle plug-in unit MR Package Installer: For installing plug-ins
  • Kindle plug-in unit ScreenSavers Hack: Used to change Kindle wallpaper
  • Kindle plug-in unit Online Screensaver: For loading and downloading Web Kindle Picture as ScreenSavers Hack Of wallpaper .

The above tools , Download address :

Other tools are :

  • Docker Containers hass-lovelace-kindle-screensaver: For deploying a nodejs service , Regularly HA The control panel is grayed out Kindle picture ( Used as wallpaper ).

above Docker Address of the container :

HA Set up

For the convenience of follow-up operation , Let's finish first Home Assistant Internal operation :

  • Create auxiliary entity class : We need to create auxiliary entity classes , For later Webhook Receiving parameters (Kindle Power and Kindle Charging state )
  • Create long-term Token: We create a long-term Token( Ten years ), be used for Docker The container is airtight 、 Remote login .

Create long-term Token

We enter Home Assistant Graphical interface , You can create a Token token :

token

The token should be like this :

Get the token

We need to pay attention to ️: The token content will only be displayed once , It is recommended to save it in Notepad or after forgetting , Delete the old and recreate .

Auxiliary class entity

after , We need to create auxiliary class entities , It's simple , stay configuration.yaml Add a configuration file to the , I'm here for the convenience of management , Adopt multi file mode :

Multi file mode

Create a... Respectively input_boolean and input_number type , It is convenient to receive parameters later :

input_boolean.yaml:

kindle_battery_charging:
name: Kindle Battery Charging
icon: mdi:book-check-outline

input_number.yaml:

kindle_battery_level:
icon: mdi:currency-usd
name: Kindle Battery Level
min: 1
max: 100
step: 0.1
Created entities

after , restart Home Assistant that will do , These auxiliary entities are used below .

establish webhook

after , In order to use the auxiliary entity class we created above , And provide a webhook Address , Let's add an automation template : One click Add automation template

after , Use templates to create automated :

Create automated

This is the time , You can select the auxiliary entity above :

Create auxiliary script

We need to pay attention to , Here I create this script (webhook) It's called KindleAuto, This can be customized , However, the changes will be synchronized later .

Lock screen wallpaper rendering

The above said , We need to install ScreenSavers Hack plug-in unit , I believe everyone knows the installation method , If not …… You can read the tutorial accompanying the book .

After installation , We need to pay attention , We'd better put only one picture :

Just one picture

Be careful ️: The content of this picture will be later OnlineScreensaver Cover

This chapter , This paper mainly introduces Docker Container configuration .

Docker Containers

Originally , I want to write one myself Kindle Wallpaper generated , But I found that the boss had written :

My raspberry pie has Docker Environmental Science , So I pulled it directly on the raspberry pie Docker Containers :

docker pull sibbl/hass-lovelace-kindle-screensaver
Pull the mirror image

Container start parameters

According to the stable introduction :https://github.com/sibbl/hass-lovelace-kindle-screensaver#usage

We're starting Docker Environment variables need to be set in the process , The environment variable parameters I recommend :

  • HA_BASE_URL='http://192.168.2.153:8123'
  • RENDERING_TIMEOUT=30000
  • RENDERING_DELAY=5000
  • HA_BATTERY_WEBHOOK=KindleAuto
  • RENDERING_SCREEN_WIDTH=1150
  • RENDERING_SCREEN_HEIGHT=1450
  • HA_SCREENSHOT_URL='/lovelace/info?kiosk'
  • HA_ACCESS_TOKEN='eyJ0eXAi*O6JdOXtQe5co'
  • LANGUAGE="en"
  • TZ=Asia/Shanghai

among ,HA_BASE_URL by Home Assistant Address ;RENDERING_TIMEOUT by Docker obtain Home Assistant Data timeout period , Set up here 30s;LANGUAGE Set the language for English ( Do not set to Chinese ~ No Chinese font );TZ Is the time zone ;HA_BATTERY_WEBHOOK by Webhook name , Set above ;RENDERING_SCREEN_WIDTH Set picture width ;RENDERING_SCREEN_HEIGHT Set the image height ;HA_ACCESS_TOKEN Above, Home Assistant Set up Token.

HA_SCREENSHOT_URL Is that we need to be in Kindle The lock screen shows

panel , such as :

panel

Then add ?kiosk Of get request , It's actually Home Assistant Front end plug-ins :https://github.com/maykar/kiosk-mode, You can hide the sidebar with this plug-in :

Hide sidebar

therefore , Finally, I created Docker Containers :

docker run -d -e HA_BASE_URL='http://192.168.2.153:8123' -e RENDERING_TIMEOUT=30000 -e LANGUAGE="en" -e LANG="zh_CN.UTF-8" -e TZ=Asia/Shanghai -e RENDERING_DELAY=5000 -e HA_BATTERY_WEBHOOK=KindleAuto -e RENDERING_SCREEN_WIDTH=1150 -e RENDERING_SCREEN_HEIGHT=1450 -e HA_SCREENSHOT_URL='/lovelace/info?kiosk' -e HA_ACCESS_TOKEN='eyJ******5co' -p:5000:5000 sibbl/hass-lovelace-kindle-screensaver
establish Docker
Created Docker state

If there's nothing wrong , You can access it through the browser :

DockerDemo

Next , We can go back to Kindle On , Continue the subsequent configuration .

If you guys don't understand Docker Containers , There will be a chance to publish an article in the future , Give you a detailed explanation Docker(**-**)

OnlineScreensaver plug-in unit

As I said before , Need to install Online Screensaver Expand , The final result should be like this :

Installed plug-ins

This plug-in has not been updated for a long time , In the new Kindle On the system version , Need to repair permissions .

Patch permissions

Fixing permissions is simple , stay Online Screensaver Inside :

Online Screensaver Inside

We need to change enable.sh,、disable.sh、update.sh and schedule.sh In file :

source config.sh
source utils.sh

Is the full absolute path :

source /mnt/us/extensions/onlinescreensaver/bin/config.sh
source /mnt/us/extensions/onlinescreensaver/bin/utils.sh

And put utils.sh Internal :

wait_for ()

Method , Change the whole to :

wait_for () {
ENDWAIT=$(( $(currentTime) + $1 ))
REMAININGWAITTIME=$(( $ENDWAIT - $(currentTime) ))
logger "Starting to wait for timeout to expire: $1"
# wait for timeout to expire
while [ $REMAININGWAITTIME -gt 0 ]; do
EVENT=$(lipc-wait-event -s $1 com.lab126.powerd readyToSuspend,wakeupFromSuspend,resuming)
REMAININGWAITTIME=$(( $ENDWAIT - $(currentTime) ))
logger "Received event: $EVENT"
case "$EVENT" in
readyToSuspend*)
set_rtc_wakeup $REMAININGWAITTIME
;;
wakeupFromSuspend*|resuming*)
logger "Finishing the wait"
break
;;
*)
logger "Ignored event: $EVENT"
;;
esac
done
logger "Wait finished"
}

after , It can be used normally .

Configure the service

after , open config.sh, We configure it according to the prompts , Such as my :

My configuration

We need to pay attention to :

  • IMAGE_URI: We configured above Docker Address of the container (5000 port )
  • LOGFILE: Log file output

Running successfully

Last , restart Kindle:

restart Kindle

All configurations can be applied . You can see the effect without accident :

Lock screen wallpaper

Of course , You can also be in KUAL Manual update in :

Update manually

Of course , If there are questions , You can view the log :

Kindle journal

As I said earlier ,KPW4 After sleep ( Without power on ) It will automatically turn off Wi-Fi.

That is to say , We need to take Kindle Wake up the ( Press the power button ), After etc. Kindle Connected to the Wi-Fi after , The wallpaper will be updated .

Actually Kindle The essence is Linux, Yes, you can write scripts manually and open them regularly Wi-Fi And we Docker On the container Web Communicating , But I can't write this , I'll leave it to you ~~

版权声明:本文为[Mintimate]所创,转载请带上原文链接,感谢。 https://bfun.fun/2022/124/202205041538305727.html