From e1e337d4a47fe692aca651c88d6f3b6c31a8fd79 Mon Sep 17 00:00:00 2001 From: aidbish <38182386+aidbish@users.noreply.github.com> Date: Mon, 1 Jul 2019 17:22:40 +1000 Subject: [PATCH] Removes Hassio running local things (#9748) * No longer required https://github.com/home-assistant/home-assistant.io/issues/9713 * Update Hassio_navigation --- .../_includes/asides/hassio_navigation.html | 1 - source/hassio/run_local.markdown | 104 ------------------ 2 files changed, 105 deletions(-) delete mode 100644 source/hassio/run_local.markdown diff --git a/source/_includes/asides/hassio_navigation.html b/source/_includes/asides/hassio_navigation.html index 124a47ff1be..ffb99b948b0 100644 --- a/source/_includes/asides/hassio_navigation.html +++ b/source/_includes/asides/hassio_navigation.html @@ -17,7 +17,6 @@ diff --git a/source/hassio/run_local.markdown b/source/hassio/run_local.markdown deleted file mode 100644 index ff94891a927..00000000000 --- a/source/hassio/run_local.markdown +++ /dev/null @@ -1,104 +0,0 @@ ---- -layout: page -title: "Run local scripts" -description: "Instructions on how to run a local script for Home Assistant." -date: 2017-04-30 13:28 -sidebar: true -comments: false -sharing: true -footer: true ---- - -Hass.io is a managed environment, which means you can't install applications that can be embedded into Home Assistant using the `command_line` sensor/switch. - -There are three options if you need to run a script which reads data from a sensor or sends commands to other devices on Hass.io. - -The first option is to write a custom integration for Home Assistant. This implies that you can communicate with your device using Python. For more information about developing a custom component, take a look at [custom-component development][custom-component]. - -The second option is to use STDIN inside an add-on and use the service `hassio.addon_stdin` to send data. For more information, have a look at [internal add-on communication][communication]. Here you will also find how you can easily access the Home Assistant Rest API. - -The third option is to create a local add-on for Hass.io that sends the data to Home Assistant via MQTT. Before we dive into this, read up on [Hass.io add-on development][addons-tutorial] first. - -For security and speed, Hass.io does not provide a way for containers to communicate directly. So the first step is to set up a communication channel. We're going to use MQTT for this using the [MQTT broker add-on][mqtt-addon]. - -### {% linkable_title Sensors %} - -We loop in our script to fetch data and push it to MQTT and wait until the next process is ready. Here is a basic example and structure for that process. - -In our Dockerfile we need to install: - -``` -RUN apk --no-cache add jq mosquitto-clients -``` - -Now we can process it with `run.sh`: - -```bash -#!/bin/bash -set -e - -CONFIG_PATH=/data/options.json - -# possible options for processing -MQTT_SERVER=$(jq --raw-output '.server' $CONFIG_PATH) -MQTT_PORT=$(jq --raw-output '.port' $CONFIG_PATH) -TOPIC=$(jq --raw-output '.topic' $CONFIG_PATH) -USER=$(jq --raw-output '.user' $CONFIG_PATH) -PASSWORD=$(jq --raw-output '.password' $CONFIG_PATH) -WAIT_TIME=$(jq --raw-output '.seconds' $CONFIG_PATH) - -# read data -while true -do - if OUTPUT="$(/read_my_sensor.sh)" - then - mosquitto_pub -h "$MQTT_SERVER" -p "$MQTT_PORT" -u "$USER" -P "$PASSWORD" -t "$TOPIC" -m "$OUTPUT" || true - else - echo "$(data) [ERROR] can't read sensor: $OUTPUT" - fi - - sleep "$WAIT_TIME" -done -``` - -### {% linkable_title Commands %} - -We wait for incoming data from the MQTT broker. We can also use an `input_boolean` that triggers an automation to publish a custom command to MQTT topic that can process multiple things in one add-on. - -In our Dockerfile we need to install: - -``` -RUN apk --no-cache add jq mosquitto-clients -``` - -Now we can process it with `run.sh`: - -```bash -#!/bin/bash -set -e - -CONFIG_PATH=/data/options.json - -# possible options for processing -MQTT_SERVER=$(jq --raw-output '.server' $CONFIG_PATH) -MQTT_PORT=$(jq --raw-output '.port' $CONFIG_PATH) -TOPIC=$(jq --raw-output '.topic' $CONFIG_PATH) -USER=$(jq --raw-output '.user' $CONFIG_PATH) -PASSWORD=$(jq --raw-output '.password' $CONFIG_PATH) - -# read data -while read -r message -do - if [ "$message" == "on" ]; then - /do_command_on.sh || true - else - /do_command_off.sh || true - fi - -done < <(mosquitto_sub -h "$MQTT_SERVER" -p "$MQTT_PORT" -u "$USER" -P "$PASSWORD" -t "$TOPIC" -q 1) -``` - -[MQTT-addon]: /addons/mosquitto/ -[custom-component]: /developers/component_loading/ -[addons-tutorial]: /developers/hassio/addon_tutorial/ -[communication]: /developers/hassio/addon_communication/