-
Notifications
You must be signed in to change notification settings - Fork 104
/
run.sh
executable file
·129 lines (110 loc) · 4.38 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/with-contenv bashio
conf_directory="/config/rtl_433"
if bashio::services.available "mqtt"; then
host=$(bashio::services "mqtt" "host")
password=$(bashio::services "mqtt" "password")
port=$(bashio::services "mqtt" "port")
username=$(bashio::services "mqtt" "username")
retain=$(bashio::config "retain")
if [ "$retain" = "true" ] ; then
retain=1
fi
else
bashio::log.info "The mqtt addon is not available."
bashio::log.info "This is not a problem if you are using an external MQTT broker."
bashio::log.info "If you are using the Home Assistant Mosquitto Broker addon, try restarting it, and then restart the rtl_433 addon."
bashio::log.info "For an external broker, manually update the output line in the configuration file with mqtt connection settings, and restart the addon."
fi
if [ ! -d $conf_directory ]
then
mkdir -p $conf_directory
fi
# Check if the legacy configuration file is set and alert that it's deprecated.
conf_file=$(bashio::config "rtl_433_conf_file")
if [[ $conf_file != "" ]]
then
bashio::log.warning "rtl_433 now supports automatic configuration and multiple radios. The rtl_433_conf_file option is deprecated. See the documentation for migration instructions."
conf_file="/config/$conf_file"
echo "Starting rtl_433 -c $conf_file"
rtl_433 -c "$conf_file"
exit $?
fi
# Create a reasonable default configuration in /config/rtl_433.
if [ ! "$(ls -A $conf_directory)" ]
then
cat > $conf_directory/rtl_433.conf.template <<EOD
# This is an empty template for configuring rtl_433. mqtt information will be
# automatically added. Create multiple files ending in '.conf.template' to
# manage multiple rtl_433 radios, being sure to set the 'device' setting. The
# device must be set before mqtt output lines.
# https://github.com/merbanan/rtl_433/blob/master/conf/rtl_433.example.conf
output mqtt://\${host}:\${port},user=\${username},pass=\${password},retain=\${retain}
report_meta time:iso:usec:tz
# To keep the same topics when switching between the normal and edge versions,
# use this output line instead.
# output mqtt://\${host}:\${port},user=\${username},pass=\${password},retain=\${retain},devices=rtl_433/9b13b3f4-rtl433/devices[/type][/model][/subtype][/channel][/id],events=rtl_433/9b13b3f4-rtl433/events,states=rtl_433/9b13b3f4-rtl433/states
# Uncomment the following line to also enable the default "table" output to the
# addon logs.
# output kv
# Disable TPMS sensors by default. These can cause an overwhelming number of
# devices and entities to show up in Home Assistant.
# This list is generated by running:
# rtl_433 -R help 2>&1 | grep -i tpms | sd '.*\[(\d+)\].*' 'protocol -$1'
# [59] Steelmate TPMS
# [60] Schrader TPMS
# [82] Citroen TPMS
# [88] Toyota TPMS
# [89] Ford TPMS
# [90] Renault TPMS
# [95] Schrader TPMS EG53MA4, PA66GF35
# [110] PMV-107J (Toyota) TPMS
# [123]* Jansite TPMS Model TY02S
# [140] Elantra2012 TPMS
# [156] Abarth 124 Spider TPMS
# [168] Schrader TPMS SMD3MA4 (Subaru)
# [180] Jansite TPMS Model Solar
# [186] Hyundai TPMS (VDO)
# [201] Unbranded SolarTPMS for trucks
# [203] Porsche Boxster/Cayman TPMS
protocol -59
protocol -60
protocol -82
protocol -88
protocol -89
protocol -90
protocol -95
protocol -110
protocol -123
protocol -140
protocol -156
protocol -168
protocol -180
protocol -186
protocol -201
protocol -203
EOD
fi
# Remove all rendered configuration files.
rm -f $conf_directory/*.conf
rtl_433_pids=()
for template in $conf_directory/*.conf.template
do
# Remove '.template' from the file name.
live=$(basename $template .template)
# By sourcing the template, we can substitute any environment variable in
# the template. In fact, enterprising users could write _any_ valid bash
# to create the final configuration file. To simplify template creation,
# we wrap the needed redirections into a temparary file.
echo "cat <<EOD > $live" > /tmp/rtl_433_heredoc
cat $template >> /tmp/rtl_433_heredoc
# Ensure a newline exists in case the template doesn't have one at the end
# of its file.
echo >> /tmp/rtl_433_heredoc
echo EOD >> /tmp/rtl_433_heredoc
source /tmp/rtl_433_heredoc
echo "Starting rtl_433 with $live..."
tag=$(basename $live .conf)
rtl_433 -c "$live" > >(sed -u "s/^/[$tag] /") 2> >(>&2 sed -u "s/^/[$tag] /")&
rtl_433_pids+=($!)
done
wait -n ${rtl_433_pids[*]}