mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-16 22:06:50 +00:00
Update run_local.markdown
This commit is contained in:
parent
4b7574f590
commit
be5150e085
@ -11,18 +11,49 @@ footer: true
|
||||
|
||||
On a normal installation you have access to base machine and can install or add every things of script they you can call with a `command_line` sensor/switch. Since Hass.IO use docker and every application is strict limited to other, you can not use this old way to perform local stuff. For first view it look very limited but if you look better to that conecpt you will see that make all very stable and a wrong thing can not break your system. It will also warrenty that your system is in every time clear to eatch running thing.
|
||||
|
||||
If you need run a script to read data for a sensor or switch commands to other device, you can do that with a add-on or on HomeAssistant container with a custom component. We look now to do that in a modern way inside a add-on. For custom component you can look into [custom-component][devoloper site].
|
||||
If you need run a script to read data for a sensor or switch commands to other device, you can do that with a add-on or on HomeAssistant container with a custom component. We look now to do that in a modern way inside a add-on. For custom component you can look into [devoloper site][custom-component].
|
||||
|
||||
Before you read more on that page, please read the [addons-turtorial][add-ons turtorial]. Now you can resize your horizen to new way to do things safe.
|
||||
Before you read more on that page, please read the [add-ons turtorial][addons-turtorial]. Now you can resize your horizen to new way to do things safe.
|
||||
|
||||
First you need install a MQTT broker. You can use our [mqtt-addon][mqtt broker add-on]. Make sure you use logins and disable anonymos access if you want control sensible systems. We provide no Hass.IO way to exchange data, that will be not realy good for security and is also to slow to exchange data between containers or stop and go stuff.
|
||||
First you need install a MQTT broker. You can use our [mqtt broker add-on][mqtt-addon]. Make sure you use logins and disable anonymos access if you want control sensible systems. We provide no Hass.IO way to exchange data, that will be not realy good for security and is also to slow to exchange data between containers or stop and go stuff.
|
||||
|
||||
### {% linkable_title Sensors %}
|
||||
|
||||
Short story of that caption: We loop in our script to fetch data push to mqtt and wait until next processing is ready. Here is a basic example and struct for that process.
|
||||
|
||||
```bash
|
||||
Our Dockerfile need to install:
|
||||
|
||||
```
|
||||
RUN apk --no-cache add tzdata jq mosquitto-clients
|
||||
```
|
||||
|
||||
Now we can process it with `run.sh`:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
CONFIG_PATH=/data/options.json
|
||||
|
||||
# possile options to process
|
||||
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" -t "$TOPIC" -m "$OUTPUT" || true
|
||||
else
|
||||
echo "$(data) [ERROR] can't read sensor: $OUTPUT"
|
||||
fi
|
||||
|
||||
sleep "$WAIT_TIME"
|
||||
done
|
||||
```
|
||||
|
||||
### {% linkable_title Commands %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user