#!/bin/sh
set -e
PRETEND=echo
MQTT_SERVER=localhost # CUSTOMIZE ME
MQTT_TIMEOUT=5
# StellaZ multilevel sensor for air temperature
AIR_TEMPERATURE_CLASS=49
# intensity 10 ~= 1 minute
# wakeup is 480s ~ 8min so poll every 7mins
INTENSITY=70
get_value_id() {
node_id=$1
mosquitto_sub -W $MQTT_TIMEOUT -C 1 -h $MQTT_SERVER -t "OpenZWave/1/node/$node_id/instance/1/commandclass/$AIR_TEMPERATURE_CLASS/value/#" \
| python -c "import sys,json; j = json.load(sys.stdin); print(j['ValueIDKey'])"
}
enable_polling() {
value_id=$1
payload='{"ValueIDKey": '$value_id', "Intensity": '$INTENSITY'}'
echo mosquitto_pub -h $MQTT_SERVER -t "OpenZWave/1/command/enablepoll/" -m "$payload"
}
for node_id in $@
do
value_id=$(get_value_id $node_id)
enable_polling $value_id
done