Added sysdweb

This commit is contained in:
Martin Bauer
2020-05-02 11:21:52 +02:00
parent 4308dae03d
commit caf6232dfb
56 changed files with 243 additions and 386 deletions

View File

View File

@@ -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
}
}

View File

View File

@@ -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()

View File

@@ -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

View File

View File

@@ -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"
}

View File

@@ -0,0 +1,7 @@
- name: restart sshd
service:
name: sshd
state: restarted
- name: reboot
reboot:

View File

View File

View File

View File

@@ -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"

Binary file not shown.

Binary file not shown.

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1 @@
include "hauppauge.conf"

View File

View File

View File

@@ -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

View File

@@ -0,0 +1,3 @@
---
dependencies:
- role: pi-alsasetup

View File

View File

@@ -0,0 +1,9 @@
general =
{
name = "{{shairport_name}}";
};
alsa =
{
output_device = "softvol_shairport";
};

View File

View File

View File

@@ -0,0 +1,3 @@
---
dependencies:
- role: pi-alsasetup

View File

View File

@@ -0,0 +1,3 @@
SL_NAME="{{squeezelite_name}}"
SL_SOUNDCARD="softvol_squeezelite"
SB_SERVER_IP="192.168.178.80"

View File

@@ -0,0 +1,13 @@
---
wifi_ssid: "" # put SSID here to configure wifi
ansible_user: "root" # "User to connect with, put in 'pi' here if you connect the first time, else leave empty"
new_hostname: "" # set this to change the hostname
timezone: "Europe/Berlin"
wifi_country: "DE"
wifi_pass_url: "bauer_wifi" # has to be in keepass with url "wifi_pass_url"
ansible_ssh_pass: "raspberry"
ansible_become_password: "raspberry"
ansible_become: yes

View File

@@ -0,0 +1,7 @@
[user]
name = Martin Bauer
email = bauer_martin@gmx.de
[alias]
sf = submodule foreach
[core]
autocrlf = input

View File

@@ -0,0 +1,14 @@
WELCOME IN THE BEDROOM
!__________!
|____ ____|
_____ {____}{____} _____
__|_*_|__%%%%%%%%%%%%__|_*_|
| | %%%%%%%%%%%%%% | |
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%
/||||||||||||||||||||\
||||||||||||||||||||||

View File

@@ -0,0 +1,18 @@
WELCOME IN THE KITCHEN
___
.' _ '.
/ /` `\ \
| | [__]
| | {{
| | }}
_ | | _ {{
___________<_>_| |_<_>}}________
.=======^=(___)=^={{====.
/ .----------------}}---. \
/ / {{ \ \
/ / }} \ \
( '=========================' )
'-----------------------------'

View File

@@ -0,0 +1,4 @@
THIS IS A NEW RASPI - CONFIGURE IT!

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,2 @@
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCu66CgHoF+v1z5ydpu0SJzPuAa0eARLLggMAJY4vWcLfLTTlFjwPpO9kjkr4acUL5uLHZkAFqXQZC91io80bIfyBiM1i1yBq290x8sETgoNHrNzvcCQUBAeCxhcogi68F14BbpwBbejDTPKKybpuuAnVPj9YiHVFEDbqjLwoEY+HH7SkCsrK8qTyp9rHzwPGk0xPBwTnCPXqzvUCr/4H+m/5lamVIOW6XYoqnvAp5jP0mbadrmB0PwvK8cfgwPJWQeLJcqwl87mwHjjlrCinkpQbd2D8mR798bGmW/iTZ7GLCkyBNE34qKg24CzE0scWjqyWICXOrTYUXLORDt99/F martin@Laptop

View File

@@ -0,0 +1,14 @@
:colorscheme elflord
:set tabstop=4
:set shiftwidth=4
:set expandtab
"other key mappings
inoremap jk <Esc>
syntax on
" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk

View File

@@ -0,0 +1,7 @@
- name: restart sshd
service:
name: sshd
state: restarted
- name: reboot
reboot:

View File

@@ -0,0 +1,86 @@
---
- name: Do apt update/upgrade
apt: upgrade=yes update_cache=yes cache_valid_time=7200
- name: Detect Raspi Model
slurp: src=/sys/firmware/devicetree/base/model
register: raspberry_model
- name: Show Raspi Model
debug: msg={{ raspberry_model.content | b64decode }}
- name: Add authorized SSH key to root account
authorized_key:
user: root
key: "{{ lookup('file', 'sshkey.pub') }}"
state: present
- name: Activate root login with key
lineinfile:
path: /etc/ssh/sshd_config
regexp: "^#?PermitRootLogin"
line: "PermitRootLogin prohibit-password"
notify: restart sshd
- name: Deactive SSH accepting locale vars (leads to warnings)
lineinfile:
path: /etc/ssh/sshd_config
regexp: "^#?AcceptEnv LANG LC_*"
line: "#AcceptEnv LANG LC_*"
notify: restart sshd
- name: Get hostname
command: "raspi-config nonint get_hostname"
register: pi_hostname
changed_when: False
- name: Change hostname to {{ new_hostname }}
command: "raspi-config nonint do_hostname {{ new_hostname }}"
when: new_hostname | bool and pi_hostname.stdout != new_hostname
register: set_hostname
notify: reboot
- name: Get hostname
command: "raspi-config nonint get_hostname"
when: set_hostname.changed
register: pi_hostname
changed_when: False
- name: set boot mode to CLI
command: "raspi-config nonint do_boot_behaviour B1"
#I2 Change Timezone
- name: Change timezone
command: "raspi-config nonint do_change_timezone {{ timezone }}"
- name: Change locale
command: "raspi-config nonint do_change_locale en_US.UTF-8"
- name: Change password of default pi account
user:
name: pi
update_password: always
password: "{{ lookup('keepass', 'default_rpi_password') | password_hash('sha512') }}"
- name: Install Packages (vim, git, basic python stuff)
apt:
name:
- vim
- git
- python3
- python3-pip
- python3-wheel
cache_valid_time: 7200
state: present
- name: Copy vim config
copy: src=vimrc dest=/root/.vimrc
- name: Copy git config
copy: src=gitconfig dest=/root/.gitconfig
# Wifi
- name: Get WiFi country
command: "raspi-config nonint get_wifi_country"
register: wifi_country
changed_when: False
ignore_errors: yes #to avoid error when WiFi is not present
- name: Change WiFi country
command: "raspi-config nonint do_wifi_country {{ wifi_country }}"
- 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=motd/{{ pi_hostname.stdout }} 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=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

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Control systemd services through Web or REST API
Documentation=https://github.com/ogarcia/sysdweb
After=network.target
Requires=dbus.socket
[Service]
ExecStart=/usr/local/bin/sysdweb -p 10080 -l 0.0.0.0
Restart=on-failure
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,38 @@
---
- name: Apt install python3-pip
apt:
name: python3-pip
cache_valid_time: 7200
state: present
- name: Install sysdweb
pip:
name: sysdweb
executable: pip3
- name: sysdweb user
user:
name: sysdweb
shell: /usr/bin/nologin
password: "$6$TcTD23xOXln$RxN3Kd0vJRaxffoyKqjoBJM0Q5Va6REBVZ6BOgmGXs3fTAWc7voSW5QcN35t9pfro2do0LeSaeGsrMLbArZ.2."
update_password: always
- name: Configure sysdweb user
blockinfile:
path: /etc/sysdweb.conf
create: true
marker: "# {mark} ansible user"
block : |
[DEFAULT]
users = sysdweb
- name: Configure sysdweb
blockinfile:
path: /etc/sysdweb.conf
create: true
marker: "# {mark} ansible managed for {{sysdweb_name}}"
block: |
[{{sysdweb_name}}]
title = {{sysdweb_name}}
unit = {{sysdweb_name}}.service
- name: Install systemd service file
copy: src=sysdweb-system.service dest=/lib/systemd/system/
- name: Enable sysdweb autostart
systemd: name=sysdweb-system state=restarted enabled=yes daemon_reload=yes