mysmarthome/packages/pi_admin.yaml

553 lines
17 KiB
YAML
Raw Normal View History

2019-04-17 22:46:06 +00:00
###############################################################################
# @author : Mahasri Kalavala
# @date : 12/27/2017
# @package : Pi Admin Package
2019-12-20 15:32:28 +00:00
# @description : Got way too many Raspberry Pi's and this package is to
2019-04-17 22:46:06 +00:00
# help me with managing them via Home Assistant.
#
# How Does It Work?
#
2019-12-20 15:32:28 +00:00
# Each Raspberry Pi runs a service (a python program) locally that listens for
# commands via MQTT on a pre-defined topic. This package publishes commands
2019-04-17 22:46:06 +00:00
# to MQTT requesting each Raspberry Pi to respond and or return data.
2019-12-20 15:32:28 +00:00
# When the responses are received (on a differet topic), the sensors gets
2019-04-17 22:46:06 +00:00
# updated automatically and are displayed.
2019-12-20 15:32:28 +00:00
#
2019-04-17 22:46:06 +00:00
################################################################################
homeassistant:
customize:
script.restart_all_raspberrypis:
friendly_name: Restart All Raspberry Pis
script.restart_all_snapclients:
friendly_name: Restart All Snapserver Clients
script.shutdown_all_raspberrypis:
friendly_name: Shutdown All Raspberry Pis
script.query_wifi_info:
friendly_name: Query WiFi Info
script.query_disk_info:
friendly_name: Query Disk Info
input_select:
raspberry_pis:
name: All Raspberry Pis
options:
2019-12-20 15:32:28 +00:00
- Select One
- pi_basement
- pi_theater
- pi_kitchen
- pi_familyroom
- pi_frontroom
- pi_garage
- pi_guest1
- pi_guest2
- pi_masterbedroom
2019-04-17 22:46:06 +00:00
initial: Select One
icon: mdi:pig
rpi_commands:
name: RPi Commands
options:
2019-12-20 15:32:28 +00:00
- Select One
- Restart Server
- Shutdown
- Restart Snapcast
2019-04-17 22:46:06 +00:00
initial: Select One
icon: mdi:pig
sensor:
2019-12-20 15:32:28 +00:00
## WiFi Information related sensors
2019-04-17 22:46:06 +00:00
- platform: mqtt
state_topic: "/wifi/pi_basement"
name: Basement Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_basement"
name: Basement Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
- platform: mqtt
state_topic: "/wifi/pi_theater"
name: Theater Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_theater"
name: Theater Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
- platform: mqtt
state_topic: "/wifi/pi_kitchen"
name: Kitchen Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_kitchen"
name: Kitchen Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
- platform: mqtt
state_topic: "/wifi/pi_familyroom"
name: Family Room Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_familyroom"
name: Family Room Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
- platform: mqtt
state_topic: "/wifi/pi_frontroom"
name: Front Room Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_frontroom"
name: Front Room Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
- platform: mqtt
state_topic: "/wifi/pi_garage"
name: Garage Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_garage"
name: Garage Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
- platform: mqtt
state_topic: "/wifi/pi_guest1"
name: Guest 1 Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_guest1"
name: Guest 1 Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
- platform: mqtt
state_topic: "/wifi/pi_guest2"
name: Guest 2 Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_guest2"
name: Guest 2 Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
- platform: mqtt
state_topic: "/wifi/pi_masterbedroom"
name: master Bedroom Pi Signal Level
value_template: '{{ value_json["Signal Level"]}}'
unit_of_measurement: dBm
- platform: mqtt
state_topic: "/wifi/pi_masterbedroom"
name: Master Bedroom Pi Link Quality
value_template: '{{ value_json["Link Quality"]}}'
2019-12-20 15:32:28 +00:00
## Disk Information related Sensors
2019-04-17 22:46:06 +00:00
- platform: mqtt
state_topic: "/disk/pi_basement"
name: Basement Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_basement"
name: Basement Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
- platform: mqtt
state_topic: "/disk/pi_theater"
name: Theater Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_theater"
name: Theater Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
2019-12-20 15:32:28 +00:00
2019-04-17 22:46:06 +00:00
- platform: mqtt
state_topic: "/disk/pi_kitchen"
name: Kitchen Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_kitchen"
name: Kitchen Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
- platform: mqtt
state_topic: "/disk/pi_familyroom"
name: Family Room Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_familyroom"
name: Family Room Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
- platform: mqtt
state_topic: "/disk/pi_frontroom"
name: Front Room Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_frontroom"
name: Front Room Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
- platform: mqtt
state_topic: "/disk/pi_garage"
name: Garage Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_garage"
name: Garage Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
- platform: mqtt
state_topic: "/disk/pi_guest1"
name: Guest 1 Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_guest1"
name: Guest 1 Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
- platform: mqtt
state_topic: "/disk/pi_guest2"
name: Guest 2 Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_guest2"
name: Guest 2 Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
- platform: mqtt
state_topic: "/disk/pi_masterbedroom"
name: Master Bedroom Pi Available Disk
value_template: '{{ value_json["Available"]}}'
- platform: mqtt
state_topic: "/disk/pi_masterbedroom"
name: Master Bedroom Pi Disk Used
value_template: '{{ value_json["% Used"]}}'
script:
restart_all_raspberrypis:
sequence:
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_basement"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_theater"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_kitchen"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_familyroom"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_frontroom"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_garage"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_guest1"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_guest2"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_masterbedroom"
2019-04-17 22:46:06 +00:00
payload: CMD_REBOOT_PI
retain: false
restart_all_snapclients:
sequence:
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_basement"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_theater"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_kitchen"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_familyroom"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_frontroom"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_garage"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_guest1"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_guest2"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_masterbedroom"
2019-04-17 22:46:06 +00:00
payload: CMD_RESTART_SNAPCLIENT
retain: false
shutdown_all_raspberrypis:
sequence:
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_basement"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_theater"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_kitchen"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_familyroom"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_frontroom"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_garage"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_guest1"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_guest2"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
- service: mqtt.publish
data_template:
2019-12-20 15:32:28 +00:00
topic: "/server/pi_masterbedroom"
2019-04-17 22:46:06 +00:00
payload: CMD_SHUTDOWN_PI
retain: false
2019-12-20 15:32:28 +00:00
# Script to Query Disk Information - Publishes message 'CMD_REPORT_WIFI_DETAILS'
# to MQTT, so that the message gets received by individual Raspberry Pi
###############################################################################
2019-04-17 22:46:06 +00:00
query_wifi_info:
sequence:
- service: mqtt.publish
data:
topic: /server/pi_basement
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_theater
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_kitchen
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_familyroom
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_frontroom
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_garage
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_guest1
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_guest2
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_masterbedroom
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pizero_green
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_WIFI_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
2019-12-20 15:32:28 +00:00
# Script to Query Disk Information - Publishes message 'CMD_REPORT_DISK_DETAILS'
# to MQTT, so that the message gets received by individual Raspberry Pi
###############################################################################
2019-04-17 22:46:06 +00:00
query_disk_info:
sequence:
- service: mqtt.publish
data:
topic: /server/pi_basement
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_theater
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_kitchen
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_familyroom
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_frontroom
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_garage
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_guest1
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_guest2
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pi_masterbedroom
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
- service: mqtt.publish
data:
topic: /server/pizero_green
2019-12-20 15:32:28 +00:00
payload: "CMD_REPORT_DISK_DETAILS"
2019-04-17 22:46:06 +00:00
retain: false
###############################################################################
2019-12-20 15:32:28 +00:00
# _ _ _
# /\ | | | | (_)
# / \ _ _| |_ ___ _ __ ___ __ _| |_ _ ___ _ __ ___
2019-04-17 22:46:06 +00:00
# / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
# / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
# /_/ \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
2019-12-20 15:32:28 +00:00
#
2019-04-17 22:46:06 +00:00
###############################################################################
# Automations: Various automations to query and issue commands to Raspberry Pis
###############################################################################
automation:
2019-12-20 15:32:28 +00:00
# Queries WiFi Signal Level and Link Quality - it loads during startup, and
# updates once every 30 minutes
###############################################################################
2019-04-17 22:46:06 +00:00
- alias: Query RPi Wifi Data
initial_state: true
trigger:
- platform: time_pattern
2019-12-20 15:32:28 +00:00
minutes: "/30"
2019-04-17 22:46:06 +00:00
- platform: homeassistant
event: start
action:
- service: script.query_wifi_info
2019-12-20 15:32:28 +00:00
# Queries Disk Available and % Used - it loads during startup, and
# updates once every 30 minutes
###############################################################################
2019-04-17 22:46:06 +00:00
- alias: Query RPi Disk Data
initial_state: true
trigger:
- platform: time_pattern
2019-12-20 15:32:28 +00:00
minutes: "/30"
2019-04-17 22:46:06 +00:00
- platform: homeassistant
2019-12-20 15:32:28 +00:00
event: start
2019-04-17 22:46:06 +00:00
action:
- service: script.query_disk_info
2019-12-20 15:32:28 +00:00
# Issues commands to Raspberry Pi via MQTT - On Demand
###############################################################################
2019-04-17 22:46:06 +00:00
- alias: Raspberry Pi Command
initial_state: true
trigger:
- platform: state
entity_id: input_select.rpi_commands
condition:
- condition: template
2019-12-20 15:32:28 +00:00
value_template: "{{ states('input_select.raspberry_pis') | lower != 'select one' }}"
2019-04-17 22:46:06 +00:00
- condition: template
2019-12-20 15:32:28 +00:00
value_template: "{{ states('input_select.rpi_commands') | lower != 'select one' }}"
2019-04-17 22:46:06 +00:00
action:
service: mqtt.publish
data_template:
retain: false
2019-12-20 15:32:28 +00:00
topic: "{{ '/server/' ~ states('input_select.raspberry_pis') }}"
2019-04-17 22:46:06 +00:00
payload: >-
2019-12-20 15:32:28 +00:00
{% if states('input_select.rpi_commands') | lower == "restart server" %}
2019-04-17 22:46:06 +00:00
CMD_REBOOT_PI
2019-12-20 15:32:28 +00:00
{% elif states('input_select.rpi_commands') | lower == "restart snapcast" %}
2019-04-17 22:46:06 +00:00
CMD_RESTART_SNAPCLIENT
{% else %}
CMD_SHUTDOWN_PI
{% endif %}