diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..e45ae11 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,8 @@ +--- + +# should we install cronie? +install_and_enable_cronie: false + +# play a video in the background with sound +multimedia_akku_warning: true + diff --git a/files/akku.sh b/files/akku.sh new file mode 100644 index 0000000..8d61ca3 --- /dev/null +++ b/files/akku.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +power="$((`cat /sys/class/power_supply/BAT0/energy_now` * 100 / `cat /sys/class/power_supply/BAT0/energy_full_design`))" + +if (( $power < 25 && $power > 15 )); then + zenity --warning --title="Low Power" --text="$power percent remaining.\n\nPlease recharge soon!" --display=:0.0 +elif (( $power < 15 && $power > 9 )); then + zenity --warning --title="Low Power" --text="$power percent remaining.\n\nPlease recharge soon!" --display=:0.0 + mpv /opt/low_battery.mkv -fs --volume 130 --start 00:00:18 --vo=tct > /dev/null +elif (( $power < 9 && $power > 5 )); then + zenity --warning --title="Critical Power" --text="$power percent remaining.\n\nPlease recharge NOW!" --display=:0.0 +elif (( $power < 5 )); then + zenity --warning --title="Critical Power" --text="$power percent remaining.\n\nRECHARGE!\nNOW!" --display=:0.0 +fi diff --git a/files/low_battery.mkv b/files/low_battery.mkv new file mode 100644 index 0000000..b38ce02 Binary files /dev/null and b/files/low_battery.mkv differ diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..edec8cf --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,55 @@ +--- + +- name: copy sound warning script + become: yes + copy: + src: 'files/akku.sh' + dest: '/opt/akku.sh' + owner: 'root' + group: 'root' + mode: '0755' + +- name: copy sound warning video + become: yes + copy: + src: 'files/low_battery.mkv' + dest: '/opt/low_battery.mkv' + owner: 'root' + group: 'root' + mode: '0644' + when: multimedia_akku_warning + +- name: install zenity and mpv for notifications + become: yes + package: + name: + - zenity + - mpv + state: present + +- name: Check akku every 2 minutes + become: yes + cron: + name: check if akku still okay + job: /opt/akku.sh + minute: '*/3' + user: '{{ user }}' + cron_file: /etc/crontab + +- name: Make sure cron is installed + become: true + when: install_and_enable_cronie + package: + name: + - cronie + state: present + +- name: Make sure cron is running + become: true + when: install_and_enable_cronie + systemd: + name: cronie.service + state: started + enabled: yes + daemon_reload: yes +