From 2b83cf6374e2bc519641ad2fc0aa6100de02f483 Mon Sep 17 00:00:00 2001 From: Florian Brinker Date: Tue, 22 Oct 2019 20:40:01 +0200 Subject: [PATCH] Implement Wallboard Display Toggle with Automations --- alexa.yaml | 4 ++++ automations/wallboard.yaml | 25 +++++++++++++++++++++++++ configuration.yaml | 12 ++++++++++++ lovelace-views/devices.yaml | 23 ++++++++++++++++------- scripts.yaml | 24 +++++++++++++++++++++++- scripts/install-wallboard-sshkey.sh | 28 ++++++++++++++++++++++++++++ switches.yaml | 12 +++++++++++- 7 files changed, 119 insertions(+), 9 deletions(-) create mode 100644 automations/wallboard.yaml create mode 100755 scripts/install-wallboard-sshkey.sh diff --git a/alexa.yaml b/alexa.yaml index 096a721..283beb8 100644 --- a/alexa.yaml +++ b/alexa.yaml @@ -17,6 +17,7 @@ - switch.harmony_playstation - switch.harmony_denon_power - switch.desktop_wol + - switch.wallboard_display # include_domains: # - switch # exclude_entities: @@ -62,4 +63,7 @@ switch.desktop_wol: name: Computer description: Computer im Büro + switch.wallboard_display: + name: Display + description: Wallboard Display # ACHTUNG: WHITELIST EBENFALLS ERGÄNZEN! \ No newline at end of file diff --git a/automations/wallboard.yaml b/automations/wallboard.yaml new file mode 100644 index 0000000..ed3f5c2 --- /dev/null +++ b/automations/wallboard.yaml @@ -0,0 +1,25 @@ +- alias: Wallboard On + trigger: + - platform: state + entity_id: binary_sensor.anyone_home + to: 'on' + - platform: state + entity_id: sensor.harmony_activity + from: 'Fire TV sehen' + action: + service: switch.turn_on + data: + entity_id: switch.wallboard_display + +- alias: Wallboard Off + trigger: + - platform: state + entity_id: binary_sensor.anyone_home + to: 'off' + - platform: state + entity_id: sensor.harmony_activity + to: 'Fire TV sehen' + action: + service: switch.turn_off + data: + entity_id: switch.wallboard_display \ No newline at end of file diff --git a/configuration.yaml b/configuration.yaml index 5d24f4f..5c2cf93 100644 --- a/configuration.yaml +++ b/configuration.yaml @@ -204,6 +204,18 @@ binary_sensor: value_template: "{{ is_state('sensor.camera_mode_office', 'start') or is_state('sensor.camera_mode_office', 'recording') }}" cctv_motion_detection_active: value_template: "{{ (is_state('sensor.camera_mode_office', 'start') or is_state('sensor.camera_mode_office', 'recording')) and is_state('sensor.camera_motion_office', 'True') }}" + - platform: command_line + name: Wallboard HDMI Status + command: !secret wallboard_hdmi_status_cmd + payload_on: display_power=1 + payload_off: display_power=0 + scan_interval: 60 + - platform: template + sensors: + anyone_home: + value_template: >- + {{ is_state('person.florian', 'home') + or is_state('person.jenny', 'home') }} weather: - platform: openweathermap diff --git a/lovelace-views/devices.yaml b/lovelace-views/devices.yaml index 6166d65..27b7629 100644 --- a/lovelace-views/devices.yaml +++ b/lovelace-views/devices.yaml @@ -26,10 +26,19 @@ cards: - entity: sensor.device_mobile_fb_battery name: Handy-Akku icon: mdi:battery - - type: entities - title: Wake On Lan - show_header_toggle: false - entities: - - entity: switch.desktop_wol - name: Desktop-PC - icon: mdi:desktop-classic + - type: horizontal-stack + cards: + - type: entities + title: Wake On Lan + show_header_toggle: false + entities: + - entity: switch.desktop_wol + name: Desktop-PC + icon: mdi:desktop-classic + - type: entities + title: Wallboard + show_header_toggle: false + entities: + - entity: switch.wallboard_display + name: Display + icon: mdi:tablet diff --git a/scripts.yaml b/scripts.yaml index 9057159..96f2fcf 100644 --- a/scripts.yaml +++ b/scripts.yaml @@ -165,4 +165,26 @@ shinobi_notify: Confidence: {{ confidence }} Letzte Aufnahmen: - [{{ video_last }}]({{ video_url }}/{{ video_last }}) - - [{{ video_previous }}]({{ video_url }}/{{ video_previous }}) \ No newline at end of file + - [{{ video_previous }}]({{ video_url }}/{{ video_previous }}) + +# Wallboard + +wallboard_hdmi_on: + sequence: + - service: shell_command.ssh + data: + sshkey: !secret sshkey_wallboard_hdmi + host: !secret wallboard_ip + user: !secret wallboard_ssh_user + port: !secret wallboard_ssh_port + command_or_param: display_power 1 + +wallboard_hdmi_off: + sequence: + - service: shell_command.ssh + data: + sshkey: !secret sshkey_wallboard_hdmi + host: !secret wallboard_ip + user: !secret wallboard_ssh_user + port: !secret wallboard_ssh_port + command_or_param: display_power 0 \ No newline at end of file diff --git a/scripts/install-wallboard-sshkey.sh b/scripts/install-wallboard-sshkey.sh new file mode 100755 index 0000000..f307995 --- /dev/null +++ b/scripts/install-wallboard-sshkey.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +DIR=$(dirname "$(readlink -f "$0")") + +KEYFILE="$DIR/../ssh-key/homeassistant-wallboard-hdmi-sshkey" +TARGET="~/.ssh/authorized_keys" + +if [ $# == 0 ] ; then + echo "Usage: install-wallboard-hdmi-sshkey.sh user@wallboard-ip" + exit 1; +fi + +if [ ! -f $KEYFILE ]; then + echo "You need to create the SSH-Key-File first: \"$KEYFILE\"" + echo "Use: \"ssh-keygen -t ed25519 -C homeassistant-wallboard-hdmi-sshkey -f $KEYFILE\"" + exit 1 +fi + +SSHKEY=$(<"$KEYFILE.pub") +echo "command=\"vcgencmd \$SSH_ORIGINAL_COMMAND\" $SSHKEY" | ssh $1 '\ + mkdir -p .ssh && \ + chmod 700 .ssh && \ + touch .ssh/authorized_keys && \ + chmod 600 .ssh/authorized_keys && \ + tee -a .ssh/authorized_keys \ +' >/dev/null + +echo "Installed the ssh key into \"$1:$TARGET\"." diff --git a/switches.yaml b/switches.yaml index 4179b3f..b1ca81b 100644 --- a/switches.yaml +++ b/switches.yaml @@ -127,4 +127,14 @@ turn_on: service: script.shinobi_active turn_off: - service: script.shinobi_idle \ No newline at end of file + service: script.shinobi_idle + +### Wallboard + + wallboard_display: + friendly_name: Wallboard Display Toggle + value_template: "{{ is_state('binary_sensor.wallboard_hdmi_status', 'on') }}" + turn_on: + service: script.wallboard_hdmi_on + turn_off: + service: script.wallboard_hdmi_off \ No newline at end of file