From 3eaff26ea00413a936f14416517c4de9eccccf5f Mon Sep 17 00:00:00 2001 From: pgrondek Date: Sat, 10 Apr 2021 11:45:24 +0200 Subject: [PATCH] Add automation to connect octoprint automatically --- automations/files/automations/3d-printer.yaml | 11 ++++++++++- automations/files/configuration.yaml | 14 +++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/automations/files/automations/3d-printer.yaml b/automations/files/automations/3d-printer.yaml index d22e34a..f4935a1 100644 --- a/automations/files/automations/3d-printer.yaml +++ b/automations/files/automations/3d-printer.yaml @@ -1,6 +1,5 @@ - id: 3dprinter-off alias: '[3D Printer] Turn off' - description: '' mode: single trigger: - type: value @@ -21,3 +20,13 @@ - service: switch.turn_off data: { } entity_id: switch.3d_printer_switch +- id: 3dprinter-on + alias: '[3D Printer] Turn on' + mode: single + trigger: + - platform: state + entity_id: switch.3d_printer_switch + to: 'on' + for: '00:00:05' + action: + - service: rest_command.octoprint_connect diff --git a/automations/files/configuration.yaml b/automations/files/configuration.yaml index c080b70..da6b96c 100644 --- a/automations/files/configuration.yaml +++ b/automations/files/configuration.yaml @@ -26,7 +26,7 @@ zwave: network_key: !secret zwave_network_key octoprint: - host: prusa.lan + host: 192.168.50.6 port: 5000 api_key: !secret octoprint_api_key number_of_tools: 1 @@ -74,6 +74,18 @@ spotify: shell_command: poweroff_pc: 'ssh -i /config/.ssh/id_rsa -o UserKnownHostsFile=/config/.ssh/known_hosts home-assistant@hulk.lan sudo /sbin/poweroff' +rest_command: + octoprint_connect: + url: 'http://192.168.50.6:5000/api/connection' + method: post + content_type: 'application/json' + headers: + X-Api-Key: !secret octoprint_api_key + payload: | + { + "command": "connect" + } + tplink: discovery: true switch: