summaryrefslogtreecommitdiffstats
path: root/mqtt_dash.sh
blob: e0378bc9f53d57ef6921f605b23c910b5454a567 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/bash

id=1

TMP=/tmp/metrics.$$

(


color()
{
guid=$(uuidgen)
echo "
    {
        \"enableIntermediateState\": true,
        \"enablePub\": true,
        \"enteredIntermediateStateAt\": 0,
        \"format\": 0,
        \"icon\": \"ic_radio_button_checked\",
        \"id\": \"$guid\",
        \"intermediateStateTimeout\": 0,
        \"jsBlinkExpression\": \"\",
        \"jsOnDisplay\": \"\",
        \"jsOnReceive\": \"\",
        \"jsOnTap\": \"\",
        \"jsonPath\": \"\",
        \"longId\": $id,
        \"name\": \"$1\",
        \"qos\": 0,
        \"retained\": false,
        \"topic\": \"$2\",
        \"topicPub\": \"\",
        \"type\": 6,
        \"updateLastPayloadOnPub\": true
    }
"
id=$[ $id + 1]
}


list() {
guid=$(uuidgen)
echo "
    {
        \"enableIntermediateState\": true,
        \"enablePub\": true,
        \"enteredIntermediateStateAt\": 0,
        \"id\": \"$guid\",
        \"intermediateStateTimeout\": 0,
        \"items\": [
"
echo "$3"

echo "
        ],
        \"jsBlinkExpression\": \"\",
        \"jsOnDisplay\": \"\",
        \"jsOnReceive\": \"\",
        \"jsOnTap\": \"\",
        \"jsonPath\": \"\",
        \"longId\": $id,
        \"mainTextSize\": \"LARGE\",
        \"name\": \"$1\",
        \"qos\": 0,
        \"retained\": false,
        \"textColor\": -1,
        \"topic\": \"$2\",
        \"topicPub\": \"\",
        \"type\": 4,
        \"updateLastPayloadOnPub\": true
    }
"

id=$[ $id + 1]
}

toggle()
{
guid=$(uuidgen)
echo "
    {
        \"enableIntermediateState\": true,
        \"enablePub\": $4,
        \"enteredIntermediateStateAt\": 0,
        \"iconOff\": \"ic_check_box_unchecked\",
        \"iconOn\": \"ic_check_box_checked\",
        \"id\": \"$guid\",
        \"intermediateStateTimeout\": 0,
        \"jsBlinkExpression\": \"\",
        \"jsOnDisplay\": \"\",
        \"jsOnReceive\": \"\",
        \"jsOnTap\": \"\",
        \"jsonPath\": \"\",
        \"longId\": $id,
        \"name\": \"$1\",
        \"offColor\": -1,
        \"onColor\": -1,
        \"payloadOff\": \"$5\",
        \"payloadOn\": \"$6\",
        \"qos\": 0,
        \"retained\": false,
        \"topic\": \"$3\",
        \"topicPub\": \"$2\",
        \"type\": 2,
        \"updateLastPayloadOnPub\": true
    }
"
id=$[ $id + 1]
}

numeric() {
guid=$(uuidgen)
echo "
    {
        \"decimalPrecision\": 1,
        \"displayPayloadValue\": true,
        \"enableIntermediateState\": false,
        \"enablePub\": $4,
        \"id\": \"$guid\",
        \"intermediateStateTimeout\": 0,
        \"jsBlinkExpression\": \"\",
        \"jsOnDisplay\": \"\",
        \"jsOnReceive\": \"\",
        \"jsOnTap\": \"\",
        \"jsonPath\": \"\",
        \"longId\": $id,
        \"maxValue\": $6,
        \"minValue\": $5,
        \"name\": \"$1\",
        \"postfix\": \"\",
        \"prefix\": \"\",
        \"progressColor\": -1,
        \"qos\": 0,
        \"retained\": false,
        \"topic\": \"$3\",
        \"topicPub\": \"$2\",
        \"type\": 3,
        \"updateLastPayloadOnPub\": true
    }

"
id=$[ $id + 1]
}


lightswitch() {
toggle $1 cmnd/$2/$3 stat/$2/$3 true OFF ON
}

lightswitch_l() {
lightswitch $1 $1 POWER 
}

radiator() {
toggle "${1}_coil" cmnd/$1/POWER stat/$1/POWER false OFF ON
echo ","
toggle "${1}_open" cmnd/$1/OPEN stat/$1/OPEN false 0 1
echo ","
numeric "${1}_temp" cmnd/$1/TEMPERATURE stat/$1/TEMPERATURE false 5.0 35.0
echo ","
numeric "${1}_low" cmnd/$1/var1 stat/$1/var1 true 5.0 35.0 
echo ","
numeric "${1}_high" cmnd/$1/var2 stat/$1/var2 true 5.0 35.0 
}



echo "["


for r in hall_radiator laundry_radiator kitchen_radiator dd_radiator1 dd_radiator2 dd_radiator3  music_room_radiator music_room_e_radiator plc0_radiator7; do
radiator $r
echo ","
done

for r in bathroom_radiator bedroom_radiator kstudy_radiator boxroom_radiator spare_bedroom_radiator ; do
radiator $r
echo ","
done

radiator 2fl_main_radiator
echo ","
radiator 2fl_stair_radiator

echo "]"


)  > ${TMP}

mosquitto_pub -h 10.32.137.1 -t metrics/exchange -f ${TMP}