Suppose we're running Home Assistant on macOS...
-
Install Rancher Desktop in Docker Mode (Moby):
-
Install Rancher Desktop
-
In Rancher Desktop, click "Settings"...
Set "Container Engine" to "dockerd (moby)"
Under "Kubernetes", uncheck "Enable Kubernetes"
(To reduce CPU Utilisation)
-
-
Install Home Assistant as a Docker Container
mkdir $HOME/home-assistant docker run -d \ --name homeassistant \ --privileged \ --restart=unless-stopped \ -e TZ=Asia/Singapore \ -v $HOME/home-assistant:/config \ -v /run/dbus:/run/dbus:ro \ --network=host \ ghcr.io/home-assistant/home-assistant:stable # If we need to snoop around the Docker Container, do this: docker exec homeassistant ps -a
-
Browse to Home Assistant for the Initial Configuration: http://localhost:8123
-
Add this to the Home Assistant Config: $HOME/home-assistant/configuration.yaml
# Shell Commands to set the Xiaomi TV Backlight. # They will be accessible as Shell Commands `tv_bright` and `tv_dim` # We'll call them in our Automated Scheduled Tasks # https://www.home-assistant.io/integrations/shell_command/ shell_command: tv_bright: ./tv-bright.sh tv_dim: ./tv-dim.sh # Virtual Switch to set the Xiaomi TV Backlight. # This will appear in the Home Assistant UI as a Home Automation Device. # So humans can click the Virtual Switch to flip the Backlight On and Off. # https://www.home-assistant.io/integrations/command_line/ command_line: - switch: name: TV Backlight command_on: ./tv-bright.sh command_off: ./tv-dim.sh
-
Restart Home Assistant to effect the changes:
Menu > Developer Tools > Check Configuration > Restart
-
In Home Assistant Settings: Add 2 Automations...
Menu > Settings > Automations > Create Automation
-
When Time is 7pm: Then Do
Shell Command tv_dim
-
When Time is 7am: Then Do
Shell Command tv_bright
-
-
We'll control Xiaomi TV via the HTTP API...
Create the Shell Script to Dim the TV Backlight: $HOME/home-assistant/tv-dim.sh
#!/bin/bash
## Shell Script to Dim the Xiaomi TV Backlight via HTTP API
set -e # Exit when any command fails
set -x # Echo commands
## IP Address of Xiaomi TV
ip=192.168.31.8
## Select `Menu > Display`
curl "http://$ip:6095/controller?action=keyevent&keycode=menu"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=up"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=up"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=enter"
sleep 0.1
## Select `Backlight`
curl "http://$ip:6095/controller?action=keyevent&keycode=down"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=down"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=enter"
sleep 0.1
## Decrease the Backlight Level from 99 to 1
for i in {1..100}
do
curl "http://$ip:6095/controller?action=keyevent&keycode=left"
sleep 0.1
done
Create the Shell Script to Brighten the TV Backlight: $HOME/home-assistant/tv-bright.sh
#!/bin/bash
## Shell Script to Brighten the Xiaomi TV Backlight via HTTP API
set -e # Exit when any command fails
set -x # Echo commands
## IP Address of Xiaomi TV
ip=192.168.31.8
## Select `Menu > Display`
curl "http://$ip:6095/controller?action=keyevent&keycode=menu"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=up"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=up"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=enter"
sleep 0.1
## Select `Backlight`
curl "http://$ip:6095/controller?action=keyevent&keycode=down"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=down"
sleep 0.1
curl "http://$ip:6095/controller?action=keyevent&keycode=enter"
sleep 0.1
## Increase the Backlight Level from 1 to 99
for i in {1..100}
do
curl "http://$ip:6095/controller?action=keyevent&keycode=right"
sleep 0.1
done