Skip to content

Commit be5150e

Browse files
authored
Update run_local.markdown
1 parent 4b7574f commit be5150e

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

source/hassio/run_local.markdown

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,49 @@ footer: true
1111

1212
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.
1313

14-
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].
14+
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].
1515

16-
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.
16+
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.
1717

18-
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.
18+
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.
1919

2020
### {% linkable_title Sensors %}
2121

2222
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.
2323

24+
Our Dockerfile need to install:
25+
26+
```
27+
RUN apk --no-cache add tzdata jq mosquitto-clients
28+
```
29+
30+
Now we can process it with `run.sh`:
2431
```bash
32+
#!/bin/bash
33+
set -e
34+
35+
CONFIG_PATH=/data/options.json
36+
37+
# possile options to process
38+
MQTT_SERVER=$(jq --raw-output '.server' $CONFIG_PATH)
39+
MQTT_PORT=$(jq --raw-output '.port' $CONFIG_PATH)
40+
TOPIC=$(jq --raw-output '.topic' $CONFIG_PATH)
41+
USER=$(jq --raw-output '.user' $CONFIG_PATH)
42+
PASSWORD=$(jq --raw-output '.password' $CONFIG_PATH)
43+
WAIT_TIME=$(jq --raw-output '.seconds' $CONFIG_PATH)
44+
45+
# read data
46+
while true
47+
do
48+
if OUTPUT="$(/read_my_sensor.sh)"
49+
then
50+
mosquitto_pub -h "$MQTT_SERVER" -p "$MQTT_PORT" -t "$TOPIC" -m "$OUTPUT" || true
51+
else
52+
echo "$(data) [ERROR] can't read sensor: $OUTPUT"
53+
fi
2554

55+
sleep "$WAIT_TIME"
56+
done
2657
```
2758

2859
### {% linkable_title Commands %}

0 commit comments

Comments
 (0)