Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes since March 2022 #14

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lofi beats in docker
  • Loading branch information
agneevX committed Jun 2, 2022
commit b2b8f730eef19928af3f17378a1fa49d16a7b96b
49 changes: 32 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Layout designed mobile-first, fully optimized for all screen sizes.

![mobile_hero](https://user-images.githubusercontent.com/19761269/97078051-b3f93280-1606-11eb-86ba-9b1e0292af4f.png)

- [<img width="28px" src="https://github.com/NX211/homer-icons/raw/7cae0e85b9b822f884e81e657c1b2b49c8189b50/png/home-assistant.png" alt="Home Assistant"></img> Home Assistant setup](#img-home-assistant-setup)
- [<img width="24px" src="https://github.com/NX211/homer-icons/raw/7cae0e85b9b822f884e81e657c1b2b49c8189b50/png/home-assistant.png" alt="Home Assistant"></img> Home Assistant setup](#img-home-assistant-setup)
- [Hardware](#hardware)
- [Themes](#themes)
- [Implementations](#implementations)
Expand Down Expand Up @@ -37,8 +37,6 @@ Layout designed mobile-first, fully optimized for all screen sizes.
- [Custom plugins used](#custom-plugins-used)
- [Integrations](#integrations)
- [Lovelace](#lovelace)
- [Notes](#notes)
- [Special thanks](#special-thanks)

## Hardware

Expand Down Expand Up @@ -118,9 +116,13 @@ Add to Home Assistant with the Netdata integration.

```sh
# Install on router
opkg install vnstat
vnstat --create -i eth0
reboot
opkg install vnstat2

# Initialize WAN interface
vnstat2 --create -i eth0

# Restart vnstat daemon
/opt/etc/init.d/S32vnstat restart
```

```yaml
Expand Down Expand Up @@ -160,6 +162,7 @@ sensor:

```yml
# configuration.yaml

# Monthly internet usage
sensor:
- platform: command_line
Expand All @@ -179,7 +182,7 @@ sensor:
icon_template: mdi:upload
value_template: >-
{% if state_attr('sensor.router_monthly_wan_usage','upload') != None %}
{{ (state_attr('sensor.router_monthly_wan_usage','upload')|float/976563)|round(1) }}
{{ (state_attr('sensor.router_monthly_wan_usage','upload') | float/976563)|round(1) }}
{% else %} NaN {% endif %}

wan_monthly_usage_down:
Expand All @@ -188,14 +191,14 @@ sensor:
icon_template: mdi:download
value_template: >-
{% if state_attr('sensor.router_monthly_wan_usage','download') != None %}
{{ (state_attr('sensor.router_monthly_wan_usage','download')|float/976563)|round(1) }}
{{ (state_attr('sensor.router_monthly_wan_usage','download') | float/976563)|round(1) }}
```

</details>

### Soundbar control

Controls the volume of ALSA - 3.5mm port on the Raspberry Pi.
Controls the volume of the Alsa mixer - 3.5mm headphone port on the Raspberry Pi.

<details><summary>Expand</summary>

Expand All @@ -222,6 +225,7 @@ automation:
shell_command:
pi_volume_0: echo amixer_0 | netcat localhost 7900
pi_volume_5: echo amixer_5 | netcat localhost 7900

# Truncated. Full in ./config
```

Expand All @@ -232,21 +236,30 @@ Similar to above, the script calls the command `amixer` to increase or decrease
```bash
#!/bin/bash

if [[ $MESSAGE == 'amixer_0' ]]; then amixer -q cset numid=1 -- -10239; fi
if [[ $MESSAGE == 'amixer_5' ]]; then amixer -q cset numid=1 -- -7399; fi
if [[ $MESSAGE == 'amixer_0' ]]; then
amixer -q cset numid=1 -- -10239
fi
if [[ $MESSAGE == 'amixer_5' ]]; then
amixer -q cset numid=1 -- -7399
fi
# Truncated. Full in ./bash_scripts/hass_socket_script.sh
```

</details>

### Lo-fi beats

Plays Lo-fi beats live stream from YouTube.

Requires `screen`, `mpv` and `youtube-dl`/`youtube-dlc` to be installed.
Plays Lo-fi beats live stream from YouTube using Docker

<details><summary>Expand</summary>

```sh
git clone https://github.com/agneevX/mpv-ytdl-docker
cd mpv-ytdl-docker
git checkout testing
docker build -t mpv-ytdl:latest .
```

```yaml
# configuration.yaml
switch:
Expand All @@ -257,7 +270,7 @@ switch:
command_off: echo "lofi_off" | nc localhost 7900
```

[`socat`](https://linux.die.net/man/1/socat) runs in the background ([systemd unit file](./hass_socket.service)) and listens for commands.
[`socat`](https://linux.die.net/man/1/socat) runs as a daemon in the background ([systemd unit file](./hass_socket.service)) and listens for commands.

Once a switch is turned on, this script is called that starts the playback...

Expand All @@ -268,8 +281,10 @@ Once a switch is turned on, this script is called that starts the playback...
read MESSAGE

if [[ $MESSAGE == 'lofi_on' ]]; then
screen -S lofi -dm /usr/bin/mpv --no-video $(/path/to/youtube-dlc -g -f 95 5qap5aO4i9A); fi
if [[ $MESSAGE == 'lofi_off' ]]; then screen -S lofi -X quit; fi
docker run -d --rm --name=lofi-beats -e "VIDEO_ID=abcdef" --device=/dev/snd:/dev/snd mpv-ytdl:latest
if [[ $MESSAGE == 'lofi_off' ]]; then
docker stop lofi-beats
fi
# Truncated. Full in ./bash_scripts/hass_socket_script.sh
```

Expand Down
39 changes: 29 additions & 10 deletions bash_scripts/hass_socket_script.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
#!/bin/bash
read -r MESSAGE

if [[ $MESSAGE == 'lofi_on' ]]; then
screen -S lofi -d -m /usr/bin/mpv --ao=alsa --no-video --no-config --really-quiet "$(/home/agneev/.local/bin/youtube-dlc -g -f 95 5qap5aO4i9A)"; fi
if [[ $MESSAGE == 'lofi_off' ]]; then screen -S lofi -X quit; fi
if [[ $MESSAGE == 'lofi2_on' ]]; then
screen -S lofi2 -d -m /usr/bin/mpv --ao=alsa --no-video --no-config --really-quiet "$(/home/agneev/.local/bin/youtube-dlc -g -f 95 DWcJFNfaw9c)"; fi
if [[ $MESSAGE == 'lofi2_off' ]]; then screen -S lofi2 -X quit; fi
if [[ $MESSAGE == 'jazz_radio_on' ]]; then
screen -S jazz_radio -d -m /usr/bin/mpv --ao=alsa --no-video --no-config --really-quiet "$(/home/agneev/.local/bin/youtube-dlc -g -f 95 fEvM-OUbaKs)"; fi
if [[ $MESSAGE == 'jazz_radio_off' ]]; then screen -S jazz_radio -X quit; fi
docker_run () {
docker run -d --rm \
--name=$1 \
-e "VIDEO_ID=$2" \
--device=/dev/snd:/dev/snd \
mpv-ytdl
}

if [[ $MESSAGE == 'lofi_on' ]]; then
docker_run lofi-beats 5qap5aO4i9A
fi
if [[ $MESSAGE == 'lofi_off' ]]; then
docker stop lofi-beats
fi

if [[ $MESSAGE == 'lofi2_on' ]]; then
docker_run lofi-beats2 DWcJFNfaw9c
fi
if [[ $MESSAGE == 'lofi2_off' ]]; then
docker stop lofi-beats2
fi

if [[ $MESSAGE == 'the_good_life_radio_on' ]]; then
docker_run good-life-radio 36YnV9STBqc
fi

if [[ $MESSAGE == 'the_good_life_radio_off' ]]; then
docker stop good-life-radio
fi

if [[ $MESSAGE == 'amixer_0' ]]; then amixer -q cset numid=1 -- -10239; fi
if [[ $MESSAGE == 'amixer_5' ]]; then amixer -q cset numid=1 -- -7399; fi
Expand All @@ -32,4 +52,3 @@ if [[ $MESSAGE == 'amixer_85' ]]; then amixer -q cset numid=1 -- -32; fi
if [[ $MESSAGE == 'amixer_90' ]]; then amixer -q cset numid=1 -- 120; fi
if [[ $MESSAGE == 'amixer_95' ]]; then amixer -q cset numid=1 -- 263; fi
if [[ $MESSAGE == 'amixer_100' ]]; then amixer -q cset numid=1 -- 400; fi

15 changes: 5 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
version: "3.8"

x-env: &env
PGID: 1001
PUID: 1001
UMASK: 002
TZ: Asia/Kolkata

services:

home-assistant:
Expand All @@ -16,7 +8,7 @@ services:
depends_on:
- postgres
environment:
<<: *env
TZ: Asia/Kolkata
volumes:
- /opt/appdata/home-assistant:/config

Expand All @@ -39,7 +31,10 @@ services:
ports:
- 8700:80
environment:
<<: *env
PGID: 1001
PUID: 1001
UMASK: 002
TZ: Asia/Kolkata
OOKLA_EULA_GDPR: true
tmpfs:
- /config/www:size=500m
Expand Down