diff --git a/pis/01-download-and-prepare-raspi-image.yml b/pis/01-download-and-prepare-raspi-image.yml index 43e82f2..5c14501 100644 --- a/pis/01-download-and-prepare-raspi-image.yml +++ b/pis/01-download-and-prepare-raspi-image.yml @@ -1,5 +1,5 @@ # Run with -# ansible-playbook pis/download-and-prepare-raspi-image.yml +# ansible-playbook 01-download-and-prepare-raspi-image.yml --- - hosts: 127.0.0.1 @@ -88,7 +88,9 @@ - "{{target_folder}}/mounted_raspi_image/system" - "{{target_folder}}/raspian_lite_latest.zip" - name: Final Image - debug: | - The prepared image is ready at {{target_folder}}. - Copy it to sdcard with - dd bs=4M if=the_image of=/dev/your/sdcard + debug: + msg: | + The prepared image is ready at {{target_folder}}. + Copy it to sdcard with + dd bs=4M status=progress if=the_image of=/dev/your/sdcard + use e.g. /dev/sdb not /dev/sdb1 ! diff --git a/pis/02-provision_new_pi.yml b/pis/02-provision_new_pi.yml index 3cb0b2d..233e757 100644 --- a/pis/02-provision_new_pi.yml +++ b/pis/02-provision_new_pi.yml @@ -3,7 +3,7 @@ # where "raspberrypi" is the hostname of the pi --- -- hosts: all +- hosts: kitchenpi gather_facts: false vars: timezone: "Europe/Berlin" @@ -20,10 +20,7 @@ default: root tasks: - name: Do apt update/upgrade - apt: - upgrade: yes - update_cache: yes - cache_valid_time: 7200 + apt: upgrade=yes update_cache=yes cache_valid_time=7200 - name: Detect Raspi Model slurp: src=/sys/firmware/devicetree/base/model register: raspberry_model @@ -85,13 +82,23 @@ register: wifi_country changed_when: False ignore_errors: yes #to avoid error when WiFi is not present - when: wifi_ssid | bool - name: Change WiFi country command: "raspi-config nonint do_wifi_country {{ wifi_country }}" - when: wifi_ssid | bool - name: Set WiFi credentials command: "raspi-config nonint do_wifi_ssid_passphrase {{ wifi_ssid }} {{ lookup('keepass', wifi_pass_url) }}" when: wifi_ssid | bool + # Message of the day + - name: Set Message of the day + copy: src=configs/motd/{{ inventory_hostname }} dest=/etc/motd + #- name: Remove motd tail + # copy: dest=/etc/motd. + # LED off script + - name: Copy led off script + copy: src=configs/raspi-leds-off.sh dest=/usr/sbin/raspi-leds-off.sh mode="u+rwx" + - name: Copy led off service + copy: src=configs/raspi-leds-off.service dest=/lib/systemd/system/ + - name: Activate led off servic + systemd: name=raspi-leds-off state=restarted enabled=yes daemon_reload=yes handlers: - name: restart sshd diff --git a/pis/03-install-pulseaudio-bluetooth.yml b/pis/03-install-pulseaudio-bluetooth.yml deleted file mode 100644 index 62c15f5..0000000 --- a/pis/03-install-pulseaudio-bluetooth.yml +++ /dev/null @@ -1,98 +0,0 @@ -# Run with -# ansible-playbook -i raspberrypi, 03-install-pulseaudio-bluetooth.yml -# where "raspberrypi" is the hostname of the pi ---- - -- hosts: raspberrypi - gather_facts: false - remote_user: root - tasks: - # --- Initial Checks --- - - fail: msg="Make sure to set the MAC address of the BT device to variable 'bluetooth_mac_address_audio'" - when: bluetooth_mac_address_audio is undefined - - name: Detect Raspi Model - slurp: - src: /sys/firmware/devicetree/base/model - register: raspberry_model - - name: Decode Raspi Model - set_fact: - raspi_model: "{{ raspberry_model.content | b64decode }}" - - name: Check if its a Raspberry 3 (where I've tested this) - fail: - msg: I've only tested this on Raspberry 3 Model Pi, this is something else - when: 'not raspi_model.startswith("Raspberry Pi 3 Model B Plus")' - #- name: Determine MAC Address of first Bluetooth device - # command: 'hciconfig hci0' - # register: hci_output - #- name: Extract MAC address - # set_fact: - # hci0_addr: "{{ hci_output.stdout | regex_search('BD Address: ([^\\s]+)', '\\1') | first }}" - # --- The actual work --- - - name: Install pulseaudio packages - apt: - name: - - pulseaudio - - pulseaudio-utils - - pulseaudio-module-bluetooth - - alsa-utils - - bluez-tools - cache_valid_time: 7200 - state: present - install_recommends: no - - name: Add root to pulse-access group - user: - name: root - groups: - - pulse-access - - pulse - - audio - append: yes - - name: Copy DBus permission file - copy: src=dbus-pulseaudio-bluetooth.conf dest=/etc/dbus-1/system.d/pulseaudio-bluetooth.conf - - name: Copy Pulseaudio system-mode config file - copy: src=pulseaudio.cfg dest=/etc/pulse/system.pa - - name: Copy bluetoothd main.conf - copy: src=bluetooth_main.conf dest=/etc/bluetooth/main.conf - - name: Copy bluetoothd audio.conf - copy: src=bluetooth_audio.conf dest=/etc/bluetooth/audio.conf - - name: Copy bt-agent service file - template: src=bt-agent.service dest=/lib/systemd/system/bt-agent.service - - name: Copy pulseaudio service file - copy: src=pulseaudio.service dest=/lib/systemd/system/ - - name: Copy Python script for discoverable and name setting - copy: - src: start_bt_discoverable.py - dest: /bin/start_bt_discoverable - mode: u=rwx,g=rx - #- name: Stop Bluetooth - # service: - # name: bluetooth - # state: stopped - #- name: Set bluetooth device name - # ini_file: - # path: "/var/lib/bluetooth/{{hci0_addr}}/settings" - # section: General - # option: Alias - # value: "{{bluetooth_name}}" - #- name: Mark as discoverable - # ini_file: - # path: "/var/lib/bluetooth/{{hci0_addr}}/settings" - # section: General - # option: Discoverable - # value: true - - name: Enable and restart bluetooth - service: - name: bluetooth - enabled: yes - state: restarted - - name: Enable and restart pulseaudio - service: - name: pulseaudio - enabled: yes - state: restarted - - name: Enable and restart bt-agent - service: - name: bt-agent - enabled: yes - state: restarted - daemon_reload: yes diff --git a/pis/03-shairport-install.yml b/pis/03-shairport-install.yml new file mode 100644 index 0000000..df4bdf0 --- /dev/null +++ b/pis/03-shairport-install.yml @@ -0,0 +1,44 @@ +# Install instructions taken from +# https://github.com/mikebrady/shairport-sync/blob/master/INSTALL.md + +--- + +- hosts: kitchenpi + gather_facts: false + vars: + shairport_sync_version: "3.3.5" + remote_user: root + tasks: + - name: Apt install dependencies + apt: + cache_valid_time: 7200 + state: present + name: + - build-essential + - git + - xmltoman + - autoconf + - automake + - libtool + - libpopt-dev + - libconfig-dev + - libasound2-dev + - avahi-daemon + - libavahi-client-dev + - libssl-dev + - libsoxr-dev + - name: Build and Install Shairport sync (may take a while) + script: "scripts/build-shairport-sync.sh ${shairport_sync_version}" + args: + creates: /usr/local/bin/shairport-sync + - name: Copy config + template: src=configs/shairport-sync.conf dest=/etc/shairport-sync.conf + - name: Sync alsa config + template: src=configs/asound.conf dest=/etc/asound.conf + - name: Modify service file to run as root + lineinfile: + path: /lib/systemd/system/shairport-sync.service + regexp: "^#?User=" + line: "User=root" + - name: Restart shairport-sync + systemd: name=shairport-sync state=restarted enabled=yes daemon_reload=yes diff --git a/pis/04-squeezelite.yml b/pis/04-squeezelite.yml index 74a4e1a..c67f896 100644 --- a/pis/04-squeezelite.yml +++ b/pis/04-squeezelite.yml @@ -1,10 +1,14 @@ --- -- hosts: raspberrypi +- hosts: kitchenpi gather_facts: false remote_user: root tasks: - name: Apt install squeezelite package apt: name=squeezelite cache_valid_time=7200 state=present - name: Install config file - template: src=squeezelite.cfg dest=/etc/default/squeezelite + template: src=configs/squeezelite.cfg dest=/etc/default/squeezelite + - name: Sync alsa config + template: src=configs/asound.conf dest=/etc/asound.conf + - name: Restart squeezelite + systemd: name=squeezelite state=restarted enabled=yes daemon_reload=yes diff --git a/pis/05-lirc.yml b/pis/05-lirc.yml new file mode 100644 index 0000000..7b8c404 --- /dev/null +++ b/pis/05-lirc.yml @@ -0,0 +1,49 @@ +--- +# lirc needs to be custom compiled on this kernel +# https://gist.github.com/billpatrianakos/cb72e984d4730043fe79cbe5fc8f7941 +- hosts: kitchenpi + gather_facts: false + remote_user: root + tasks: + #- name: Apt install lirc package + # apt: name=lirc cache_valid_time=7200 state=present + # ignore_errors: yes + - name: Install config file lirc_options.conf + copy: src=configs/lirc/lirc_options.conf dest=/etc/lirc/lirc_options.conf + - name: Install config file lircd.conf + copy: src=configs/lirc/lircd.conf dest=/etc/lirc/lircd.conf + - name: Install remote file + copy: src=configs/lirc/hauppauge.conf dest=/etc/lirc/hauppauge.conf + - name: create temporary directory + tempfile: + state: directory + suffix: temp + register: tempdir + - name: Copy over lirc customly compiled lirc packages + copy: + src: configs/lirc/debs/ + dest: "{{ tempdir.path }}" + when: tempdir.path is defined + - name: Install custom lirc package 1 + apt: + deb: "{{ tempdir.path }}/liblirc0_0.10.1-5.2_armhf.deb" + when: tempdir.path is defined + - name: Install custom lirc package 2 + apt: + deb: "{{ tempdir.path }}/liblircclient0_0.10.1-5.2_armhf.deb" + when: tempdir.path is defined + - name: Install custom lirc package 3 + apt: + deb: "{{ tempdir.path }}/lirc_0.10.1-5.2_armhf.deb" + when: tempdir.path is defined + - name: Activate overlay in boot config + lineinfile: + path: /boot/config.txt + regexp: "^#?dtoverlay=gpio-ir" + line: "dtoverlay=gpio-ir,gpio_pin=17" + register: boot_overlay + - name: Restart lircd + systemd: name=lircd state=restarted enabled=yes daemon_reload=yes + - name: Reboot if boot overlay changed + reboot: + when: boot_overlay.changed diff --git a/pis/06-hifiberry.yml b/pis/06-hifiberry.yml new file mode 100644 index 0000000..2d9cc4d --- /dev/null +++ b/pis/06-hifiberry.yml @@ -0,0 +1,27 @@ +--- + +- hosts: newrpi + gather_facts: false + remote_user: root + tasks: + - name: Deactivate normal audio + lineinfile: + path: /boot/config.txt + regexp: "^#?dtparam=audio=on" + line: "#dtparam=audio=on" + register: boot_overlay1 + - name: Activate Hifiberry + lineinfile: + path: /boot/config.txt + regexp: "^#?dtoverlay=hifiberry-amp" + line: "dtoverlay=hifiberry-amp" + register: boot_overlay2 + #- name: Reboot if boot overlay changed + # reboot: + # when: boot_overlay1.changed or boot_overlay2.changed + + +## State in /boot/config.txt +# dtoverlay=hifiberry-amp +# # remove old: +# #dtparam=audio=on \ No newline at end of file diff --git a/pis/07-dhtsensor.yml b/pis/07-dhtsensor.yml new file mode 100644 index 0000000..97c9dcb --- /dev/null +++ b/pis/07-dhtsensor.yml @@ -0,0 +1,20 @@ +--- + +- hosts: kitchenpi + gather_facts: false + remote_user: root + tasks: + - name: apt install libgpiod2 + apt: name=libgpiod2 cache_valid_time=7200 state=present + - name: pip install adafruit-circuitpython-dht + pip: + name: adafruit-circuitpython-dht + executable: pip3 + - name: Install script config + template: src=configs/dht22_sensing.json dest=/etc/dht22_sensing.json + - name: Install script + copy: src=configs/dht22_sensing.py dest=/usr/bin/dht22_sensing owner=root mode=u+rwx + - name: Install systemd service file + copy: src=configs/dht22_sensing.service dest=/lib/systemd/system/ + - name: Add script to autostart and start now + systemd: name=dht22_sensing state=restarted enabled=yes daemon_reload=yes diff --git a/pis/configs/asound.conf b/pis/configs/asound.conf new file mode 100644 index 0000000..e9f4420 --- /dev/null +++ b/pis/configs/asound.conf @@ -0,0 +1,58 @@ +pcm.soundcard { + type hw + card {{alsa_card_name}} +} + +ctl.dmixer { + type hw + card {{alsa_card_name}} +} + +pcm.dmixer { + type dmix + ipc_key 1024 + slave { + pcm "soundcard" + channels 2 + } +} + +pcm.dmixer_plug { + type plug + slave { + pcm "dmixer" + } +} + +pcm.softvol_shairport { + type softvol + slave { + pcm "dmixer_plug" + } + control { + name "ShairPort-Sync Volume" + card 0 + } +} + +pcm.softvol_squeezelite { + type softvol + slave { + pcm "dmixer_plug" + } + control { + name "SqueezeLite Volume" + card 0 + } +} + +pcm.softvol_effects { + type softvol + slave { + pcm "dmixer_plug" + } + control { + name "Effect Volume" + card 0 + } +} diff --git a/pis/configs/dht22_sensing.json b/pis/configs/dht22_sensing.json new file mode 100644 index 0000000..8b8a4cf --- /dev/null +++ b/pis/configs/dht22_sensing.json @@ -0,0 +1,12 @@ +{ + "ha_url": "https://ha.bauer.tech", + "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxNjkxMWIzZmQ4ZWU0NDI0OTg0MjA0ZDllMDhkNGRlMCIsImlhdCI6MTU3ODE3MDU5MSwiZXhwIjoxODkzNTMwNTkxfQ.i7CdXEZy9DV9KPHAl-msK0rOfIUlPYo4zwwJ4UGhXuc", + "dht_pin": "D12", + "polling_sleep_time_seconds": 5, + + "ha_temp_sensor_name": "{{sensor_room_name_ascii|lower}}_dht22_temperatur", + "ha_temp_friendly_name": "{{sensor_room_name}} Temperatur", + + "ha_humidity_sensor_name": "{{sensor_room_name_ascii|lower}}_dht22_luftfeuchtigkeit", + "ha_humidity_friendly_name": "{{sensor_room_name}} Luftfeuchtigkeit" +} \ No newline at end of file diff --git a/pis/configs/dht22_sensing.py b/pis/configs/dht22_sensing.py new file mode 100644 index 0000000..63f3fed --- /dev/null +++ b/pis/configs/dht22_sensing.py @@ -0,0 +1,53 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import requests +import json +import time +import board +import adafruit_dht + +config = json.load(open("/etc/dht22_sensing.json")) +dht_device = adafruit_dht.DHT22(getattr(board, config['dht_pin'])) + + +def send_to_home_assistant(temperature, humidity): + headers = { + 'x-ha-access': config['token'], + 'Authorization': "Bearer {}".format(config['token']) + } + + temperature_url = "{}/api/states/sensor.{}".format(config['ha_url'], config['ha_temp_sensor_name']) + temperatur_data = { + "state": str(temperature), + "attributes": { + "device_class": "temperature", + "friendly_name": config['ha_temp_friendly_name'], + "unit_of_measurement": "°C" + } + } + requests.post(temperature_url, json=temperatur_data, headers=headers) + + humidity_url = "{}/api/states/sensor.{}".format(config['ha_url'], config['ha_humidity_sensor_name']) + humidity_data = { + "state": str(humidity), + "attributes": { + "device_class": "humidity", + "friendly_name": config['ha_humidity_friendly_name'], + "unit_of_measurement": "%" + } + } + requests.post(humidity_url, json=humidity_data, headers=headers) + + +def sense(): + try: + send_to_home_assistant(dht_device.temperature, dht_device.humidity) + except RuntimeError as error: + # Errors happen fairly often, DHT's are hard to read, just keep going + print(error.args[0]) + time.sleep(config['polling_sleep_time_seconds']) + + +while True: + sense() diff --git a/pis/configs/dht22_sensing.service b/pis/configs/dht22_sensing.service new file mode 100644 index 0000000..60cf377 --- /dev/null +++ b/pis/configs/dht22_sensing.service @@ -0,0 +1,10 @@ +[Unit] +Description=DHT22 Temperature Humidity Sensing +After=multi-user.target + +[Service] +Type=simple +ExecStart=/usr/bin/python3 /usr/bin/dht22_sensing + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/pis/configs/lirc/71-lirc.rules b/pis/configs/lirc/71-lirc.rules new file mode 100644 index 0000000..3f5f427 --- /dev/null +++ b/pis/configs/lirc/71-lirc.rules @@ -0,0 +1,3 @@ +ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="gpio_ir_recv", SYMLINK+="lirc-rx" +ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="gpio-ir-tx", SYMLINK+="lirc-tx" +ACTION=="add", SUBSYSTEM=="lirc", DRIVERS=="pwm-ir-tx", SYMLINK+="lirc-tx" diff --git a/pis/configs/lirc/debs/liblirc0_0.10.1-5.2_armhf.deb b/pis/configs/lirc/debs/liblirc0_0.10.1-5.2_armhf.deb new file mode 100644 index 0000000..4994e57 Binary files /dev/null and b/pis/configs/lirc/debs/liblirc0_0.10.1-5.2_armhf.deb differ diff --git a/pis/configs/lirc/debs/liblircclient0_0.10.1-5.2_armhf.deb b/pis/configs/lirc/debs/liblircclient0_0.10.1-5.2_armhf.deb new file mode 100644 index 0000000..1e26b50 Binary files /dev/null and b/pis/configs/lirc/debs/liblircclient0_0.10.1-5.2_armhf.deb differ diff --git a/pis/configs/lirc/debs/lirc_0.10.1-5.2_armhf.deb b/pis/configs/lirc/debs/lirc_0.10.1-5.2_armhf.deb new file mode 100644 index 0000000..8378cea Binary files /dev/null and b/pis/configs/lirc/debs/lirc_0.10.1-5.2_armhf.deb differ diff --git a/pis/configs/lirc/hauppauge.conf b/pis/configs/lirc/hauppauge.conf new file mode 100644 index 0000000..c95c8a5 --- /dev/null +++ b/pis/configs/lirc/hauppauge.conf @@ -0,0 +1,79 @@ +# +# this config file was automatically generated +# using lirc-0.7.0(any) on Sun Nov 28 20:25:09 2004 +# +# contributed by +# +# brand: Hauppauge 350 +# Created: G.J. Werler (The Netherlands) +# Project: Mythtv Fedora Pundit-R www.mythtvportal.com +# Date: 2004/11/28 +# model no. of remote control: Hauppauge A415-HPG +# devices being controlled by this remote: PVR-350 +# + +begin remote + + name Hauppauge + bits 13 + flags RC5|CONST_LENGTH + eps 30 + aeps 100 + + one 969 811 + zero 969 811 + plead 1097 + gap 114605 + toggle_bit 2 + + begin codes + KEY_GOTO 0x00000000000017BB + KEY_POWER 0x00000000000017BD + KEY_TV 0x000000000000179C + KEY_VIDEO 0x0000000000001798 + KEY_MUSIC 0x0000000000001799 + KEY_PICTURES 0x000000000000179A + KEY_EPG 0x000000000000179B + KEY_RADIO 0x000000000000178C + KEY_UP 0x0000000000001794 + KEY_LEFT 0x0000000000001796 + KEY_RIGHT 0x0000000000001797 + KEY_DOWN 0x0000000000001795 + KEY_OK 0x00000000000017A5 + KEY_EXIT 0x000000000000179F + KEY_MENU 0x000000000000178D + KEY_VOLUMEUP 0x0000000000001790 + KEY_VOLUMEDOWN 0x0000000000001791 + KEY_CHANNEL 0x0000000000001792 + KEY_MUTE 0x000000000000178F + KEY_CHANNELUP 0x00000000000017A0 + KEY_CHANNELDOWN 0x00000000000017A1 + KEY_RECORD 0x00000000000017B7 + KEY_STOP 0x00000000000017B6 + KEY_PREVIOUS 0x00000000000017B2 + KEY_PLAY 0x00000000000017B5 + KEY_FORWARD 0x00000000000017B4 + KEY_REWIND 0x00000000000017A4 + KEY_PAUSE 0x00000000000017B0 + KEY_FASTFORWARD 0x000000000000179E + BTN_1 0x0000000000001781 + BTN_2 0x0000000000001782 + BTN_3 0x0000000000001783 + BTN_4 0x0000000000001784 + BTN_5 0x0000000000001785 + BTN_6 0x0000000000001786 + BTN_7 0x0000000000001787 + BTN_8 0x0000000000001788 + BTN_9 0x0000000000001789 + KEY_NUMERIC_STAR 0x000000000000178A + BTN_0 0x0000000000001780 + KEY_NUMERIC_POUND 0x000000000000178E + KEY_RED 0x000000000000178B + KEY_GREEN 0x00000000000017AE + KEY_YELLOW 0x00000000000017B8 + KEY_BLUE 0x00000000000017A9 + end codes + +end remote + + diff --git a/pis/configs/lirc/lirc_options.conf b/pis/configs/lirc/lirc_options.conf new file mode 100644 index 0000000..5d1202c --- /dev/null +++ b/pis/configs/lirc/lirc_options.conf @@ -0,0 +1,11 @@ +[lircd] +nodaemon = False +driver = default +device = /dev/lirc0 +listen = 0.0.0.0:2222 +output = /var/run/lirc/lircd +pidfile = /var/run/lirc/lircd.pid +plugindir = /usr/lib/arm-linux-gnueabihf/lirc/plugins +permission = 666 +allow-simulate = No +repeat-max = 600 diff --git a/pis/configs/lirc/lircd.conf b/pis/configs/lirc/lircd.conf new file mode 100644 index 0000000..822a36b --- /dev/null +++ b/pis/configs/lirc/lircd.conf @@ -0,0 +1 @@ +include "hauppauge.conf" \ No newline at end of file diff --git a/pis/configs/motd/bedroompi b/pis/configs/motd/bedroompi new file mode 100644 index 0000000..a7aa4af --- /dev/null +++ b/pis/configs/motd/bedroompi @@ -0,0 +1,14 @@ + + WELCOME IN THE BEDROOM + + !__________! + |____ ____| + _____ {____}{____} _____ + __|_*_|__%%%%%%%%%%%%__|_*_| + | | %%%%%%%%%%%%%% | | + %%%%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%% + %%%%%%%%%%%%%%%%%%%% + /||||||||||||||||||||\ + |||||||||||||||||||||| + diff --git a/pis/configs/motd/kitchenpi b/pis/configs/motd/kitchenpi new file mode 100644 index 0000000..973b45f --- /dev/null +++ b/pis/configs/motd/kitchenpi @@ -0,0 +1,18 @@ + + WELCOME IN THE KITCHEN + + ___ + .' _ '. + / /` `\ \ + | | [__] + | | {{ + | | }} + _ | | _ {{ + ___________<_>_| |_<_>}}________ + .=======^=(___)=^={{====. + / .----------------}}---. \ + / / {{ \ \ + / / }} \ \ + ( '=========================' ) + '-----------------------------' + diff --git a/pis/configs/motd/newrpi b/pis/configs/motd/newrpi new file mode 100644 index 0000000..84f8f29 --- /dev/null +++ b/pis/configs/motd/newrpi @@ -0,0 +1,4 @@ + +THIS IS A NEW RASPI - CONFIGURE IT! + + diff --git a/pis/configs/raspi-leds-off.service b/pis/configs/raspi-leds-off.service new file mode 100644 index 0000000..f02399f --- /dev/null +++ b/pis/configs/raspi-leds-off.service @@ -0,0 +1,8 @@ +[Unit] +Description=Turn Raspi LEDs off at boot + +[Service] +ExecStart=/usr/sbin/raspi-leds-off.sh + +[Install] +WantedBy=multi-user.target diff --git a/pis/configs/raspi-leds-off.sh b/pis/configs/raspi-leds-off.sh new file mode 100644 index 0000000..62bd8a2 --- /dev/null +++ b/pis/configs/raspi-leds-off.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo none > /sys/class/leds/led0/trigger +echo none > /sys/class/leds/led1/trigger + +echo 0 >/sys/class/leds/led0/brightness +echo 0 >/sys/class/leds/led1/brightness diff --git a/pis/configs/shairport-sync.conf b/pis/configs/shairport-sync.conf new file mode 100644 index 0000000..9aa7f10 --- /dev/null +++ b/pis/configs/shairport-sync.conf @@ -0,0 +1,9 @@ +general = +{ + name = "{{shairport_name}}"; +}; + +alsa = +{ + output_device = "softvol_shairport"; +}; diff --git a/pis/squeezelite.cfg b/pis/configs/squeezelite.cfg similarity index 63% rename from pis/squeezelite.cfg rename to pis/configs/squeezelite.cfg index 3f3e40e..9ee3ca3 100644 --- a/pis/squeezelite.cfg +++ b/pis/configs/squeezelite.cfg @@ -1,3 +1,3 @@ SL_NAME="{{squeezelite_name}}" -SL_SOUNDCARD="pulse" +SL_SOUNDCARD="softvol_squeezelite" SB_SERVER_IP="192.168.178.80" diff --git a/pis/inventory.yml b/pis/inventory.yml index 9a33a7a..d9e63a7 100644 --- a/pis/inventory.yml +++ b/pis/inventory.yml @@ -7,10 +7,20 @@ all: children: iot: hosts: - raspberrypi: - bluetooth_mac_address_audio: B8:27:EB:AA:23:4E - bluetooth_name: MyTestRaspberry + newrpi: squeezelite_name: MyTestRaspberry + shairport_name: MyTestRaspberry + alsa_card_name: 0 + sensor_room_name_ascii: testraum + sensor_room_name: Test Raum heatingpi: bedroompi: kitchenpi: + squeezelite_name: KitchenPi + shairport_name: KitchenPi + alsa_card_name: 0 + sensor_room_name_ascii: kueche + sensor_room_name: Küche + vars: + ansible_python_interpreter: /usr/bin/python3 + diff --git a/pis/notes.md b/pis/notes.md new file mode 100644 index 0000000..05f93a7 --- /dev/null +++ b/pis/notes.md @@ -0,0 +1,2 @@ +/etc/modules + -> bedroompi: snd-bcm2835 \ No newline at end of file diff --git a/pis/pulseaudio.cfg b/pis/pulseaudio.cfg deleted file mode 100644 index 8815267..0000000 --- a/pis/pulseaudio.cfg +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/pulseaudio -nF -# - -### Automatically restore the volume of streams and devices -load-module module-device-restore -load-module module-stream-restore -load-module module-card-restore - -### Disabled: Automatically load driver modules depending on the hardware available -#.ifexists module-udev-detect.so -#load-module module-udev-detect tsched=0 -#.else -### Use the static hardware detection module (for systems that lack udev/hal support) -#load-module module-detect -#.endif - -# this is used instead -load-module module-alsa-card device_id=0 -# Parameters to try -# tsched=true tsched_buffer_size=1048576 tsched_buffer_watermark=262144 - - - -### Load several protocols -.ifexists module-esound-protocol-unix.so -load-module module-esound-protocol-unix -.endif -# here I added anonymous logins from local system -load-module module-native-protocol-unix auth-anonymous=1 - -### Automatically restore the default sink/source when changed by the user -### during runtime -### NOTE: This should be loaded as early as possible so that subsequent modules -### that look up the default sink/source get the right value -load-module module-default-device-restore - -### Automatically move streams to the default sink if the sink they are -### connected to dies, similar for sources -load-module module-rescue-streams - -### Make sure we always have a sink around, even if it is a null sink. -load-module module-always-sink - -### Automatically suspend sinks/sources that become idle for too long -#load-module module-suspend-on-idle - -### Enable positioned event sounds -load-module module-position-event-sounds - - -# enable network streaming from IPs 192.168.178.x -load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.178.0/24 auth-anonymous=1 - -# ### Automatically load driver modules for Bluetooth hardware -load-module module-bluetooth-policy -load-module module-bluetooth-discover \ No newline at end of file diff --git a/pis/pulseaudio.service b/pis/pulseaudio.service deleted file mode 100644 index 8662c03..0000000 --- a/pis/pulseaudio.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=PulseAudio system server - -[Service] -Type=notify -ExecStart=pulseaudio --daemonize=no --system --log-target=journal - -[Install] -WantedBy=multi-user.target diff --git a/pis/raspberry_pi_audio.md b/pis/raspberry_pi_audio.md index 10d8615..35882cd 100644 --- a/pis/raspberry_pi_audio.md +++ b/pis/raspberry_pi_audio.md @@ -5,8 +5,14 @@ amixer cset numid=3 2 # switches to HDMI amixer cset numid=3 1 # switches to headphone -Set up PulseAudio ------------------ +PulseAudio +----------- + +- tried network streaming, works +- tried bluetooth - somewhat works, sometimes stuttering + - when media is already playing on device and then connecting it usually works fine + - playing a second source at the same time gives ugly artifacts +-> decided to use pure ALSA instead + -(also available in playbook TOOD) diff --git a/pis/scripts/build-shairport-sync.sh b/pis/scripts/build-shairport-sync.sh new file mode 100644 index 0000000..6eb823a --- /dev/null +++ b/pis/scripts/build-shairport-sync.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +ARG1=$1 +VERSION=${ARG1:="3.3.6"} + +# Make a new temporary directory and go there +tmp_dir=$(mktemp -d) +cd $tmp_dir + +# Clone, build and install +git clone https://github.com/mikebrady/shairport-sync.git +git reset --hard origin/$VERSION +cd shairport-sync +autoreconf -fi +./configure --sysconfdir=/etc --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-systemd +make +make install + +# Clean up +cd ~ +rm -rf $tmp_dir diff --git a/pis/sensor.py b/pis/sensor.py new file mode 100644 index 0000000..9ba6bbc --- /dev/null +++ b/pis/sensor.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +import requests + +key = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxNjkxMWIzZmQ4ZWU0NDI0OTg0MjA0ZDllMDhkNGRlMCIsImlhdCI6MTU3ODE3MDU5MSwiZXhwIjoxODkzNTMwNTkxfQ.i7CdXEZy9DV9KPHAl-msK0rOfIUlPYo4zwwJ4UGhXuc" +url = "https://ha.bauer.tech" + +headers = { + 'x-ha-access': key, + 'Authorization': "Bearer {}".format(key) +} + +apiurl = url + "/api/states/sensor.schlafzimmer_temperatur" + +data = { + "state": "19", + "attributes": { + "device_class": "temperature", + "friendly_name": "Schlafzimmer Temperatur", + "unit_of_measurement": "°C" + } +} +r = requests.post(apiurl, json=data, headers=headers) + +print(r)