Fix ansible-lint violations: FQCN, formatting, bugs, role renames

- Auto-fix FQCN, YAML formatting, jinja spacing, and free-form module
  syntax via ansible-lint --fix
- Fix comments misplaced inside module args by the auto-fixer
  (bluetooth-monitor, pi_standard_setup, pi_musicmouse)
- Fix notify: references left stale (lowercase) after handler names
  were re-cased, which would have silently broken reboot/restart
  handlers (pi_disable_onboard_bluetooth, pi_hifiberry_amp,
  pi_squeezelite, pi_standard_setup)
- Fix a task in pis/debmatic-install.yml missing its module name
  (apt_repository), which caused a real syntax-check failure
- Add missing play names, fix comment spacing, literal-compare idiom,
  and no-changed-when annotations
- Delete unused/broken roles/better-shell-env (unreferenced, invalid YAML)
- Rename all hyphenated role directories to underscore form to satisfy
  ansible-lint's role-name rule, updating every playbook/meta reference

Remaining lint findings (var-naming, package-latest, risky-file-permissions,
no-handler) intentionally left for follow-up per user decision.
This commit is contained in:
2026-09-08 17:13:00 +02:00
parent f79c106437
commit ab9763ec49
158 changed files with 775 additions and 660 deletions

Binary file not shown.

View File

@@ -0,0 +1,7 @@
# pi_dhtsensor
Installs the DHT22 temperature/humidity sensor polling script based on the
legacy `Adafruit_DHT` library (removing the circuitpython variant/
`libgpiod2` if present — mutually exclusive with `pi_dhtsensor_circuitpython`).
**Key vars:** `dht_pin`, `dht_polling_sleep_time_seconds`

View File

@@ -0,0 +1,3 @@
---
dht_pin: 12
dht_polling_sleep_time_seconds: 20

View File

@@ -0,0 +1,93 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import requests
import json
import time
import Adafruit_DHT
config = json.load(open("/etc/dht22_sensing.json"))
class Filter:
def __init__(self, filter_length, max_mean_deviation):
self._length = filter_length
self.values = []
self.max_mean_deviation = max_mean_deviation
def mean(self):
return sum(self.values) / len(self.values)
def is_valid_value(self, val):
if len(self.values) == 0:
return True
else:
return abs(val - self.mean()) < self.max_mean_deviation
def add_if_valid(self, val):
if val is None:
return False
if self.is_valid_value(val):
self.values.append(val)
if len(self.values) > self._length:
self.values.pop(0)
return True
else:
return False
def send_to_home_assistant(temperature, humidity):
# print(f"Sending temperature {temperature}, humidity {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": "{:.1f}".format(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": "{:.1f}".format(humidity),
"attributes": {
"device_class": "humidity",
"friendly_name": config['ha_humidity_friendly_name'],
"unit_of_measurement": "%"
}
}
requests.post(humidity_url, json=humidity_data, headers=headers)
if __name__ == "__main__":
temp_filter = Filter(4, 10)
humidity_filter = Filter(4, 10)
while True:
sensor = Adafruit_DHT.DHT22
humidity, temperature = Adafruit_DHT.read_retry(
sensor, config['dht_pin'])
temp_valid = temp_filter.add_if_valid(temperature)
humidity_valid = humidity_filter.add_if_valid(humidity)
if not (temp_valid and humidity_valid):
print(
f"Discarding value {temperature}C / {humidity}%, because to far from means {temp_filter.mean()}C, {humidity_filter.mean()}%")
else:
try:
send_to_home_assistant(temperature, humidity)
except Exception as e:
print("Failed sending to home assistant")
print(e)
time.sleep(float(config['polling_sleep_time_seconds']))

View File

@@ -0,0 +1,10 @@
[Unit]
Description=DHT22 Temperature Humidity Sensing
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/dht22_sensing
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,46 @@
---
# Use the deprecated version here instead, not the new circuitpython adafruit-circuitpython-dht version
# the new version needs a lot of CPU time and doesn't work correctly on old raspi 1
# a copy of the deprecated repo is downloaded as zip (if it goes away)
- name: Uninstall libgpiod2 (circuitpython) if present
ansible.builtin.apt:
name: libgpiod2
cache_valid_time: "7200"
state: absent
- name: Pip uninstall adafruit-circuitpython-dht
ansible.builtin.pip:
name: adafruit-circuitpython-dht
executable: pip3
state: absent
extra_args: "--break-system-packages"
- name: Pip install adafruit-dht
ansible.builtin.pip:
name: adafruit-dht
executable: pip3
extra_args: "--break-system-packages"
- name: Install script config
ansible.builtin.template:
src: dht22_sensing.json
dest: /etc/dht22_sensing.json
- name: Install script
ansible.builtin.copy:
src: dht22_sensing.py
dest: /usr/bin/dht22_sensing
owner: root
mode: u+rwx
- name: Install systemd service file
ansible.builtin.copy:
src: dht22_sensing.service
dest: /etc/systemd/system/
- name: Add script to autostart and start now
ansible.builtin.systemd:
name: dht22_sensing
state: restarted
enabled: "yes"
daemon_reload: "yes"
- name: Add to sysdweb
ansible.builtin.include_role:
name: pi_sysdweb
vars:
sysdweb_name: dht22_sensing

View File

@@ -0,0 +1,12 @@
{
"ha_url": "{{home_assistant_url}}",
"token": "{{home_assistant_token}}",
"dht_pin": "{{dht_pin}}",
"polling_sleep_time_seconds": "{{dht_polling_sleep_time_seconds}}",
"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"
}