Today I suddenly realized how completely unnecessary it is to poll the output of tdtool every n:th minute for readings, when there's functionality in the telldus software to do things synchronously when things happen. I've now ditched my use of the scheduled weather parser and instead I put the below script in /usr/local/share/telldus/scripts/sensorevent. Works like a charm
(please note that this is Linux only. The script execution stuff isn't available for Windows)
Code: Select all
#!/bin/bash
declare -A whitelist=([oregon-2914-11-rainrate]=1
[oregon-2914-11-raintotal]=1
[fineoffset-temperature-1]=1
[fineoffset-temperature-167]=1
[fineoffset-temperature-248]=1)
timestamp=$(date +"%d %b %T")
extraarguments=""
case ${DATATYPE} in
1)
haid="${PROTOCOL}-${MODEL}-${SENSORID}"
;;
2)
haid="${PROTOCOL}-${MODEL}-${SENSORID}-humidity"
;;
4)
haid="${PROTOCOL}-${MODEL}-${SENSORID}-rainrate"
;;
8)
haid="${PROTOCOL}-${MODEL}-${SENSORID}-raintotal"
extraarguments="&calculatevalues=true"
;;
16)
haid="${PROTOCOL}-${MODEL}-${SENSORID}-winddirection"
;;
32)
haid="${PROTOCOL}-${MODEL}-${SENSORID}-windaverage"
;;
64)
haid="${PROTOCOL}-${MODEL}-${SENSORID}-windgust"
;;
esac
if [[ ${whitelist["$haid"]} ]] ; then
echo "${timestamp} - ${haid} -> ${VALUE} " >> /tmp/tdsensor.log
url="http://localhost/homeautomation/api.php?do=sensors/setValue&serial=${haid}&name=${haid}&value=${VALUE}${extraarguments}"
wget --header='Accept-Language: sv' -qO- "${url}" &> /dev/null
fi
edit: Added name argument to url. Without it HA won't be able to create new sensors so it won't work if you haven't used the parser in before.
edit 2: Added whitelist function. Please note that you need to change the whitelisted sensors or you'll get my values
Also added an argument which makes HA calculate useful rain values per hour and day for those stupid raintotal sensors. For this you need svn version 1420 or higher though (but the extra argument won't break anything in earlier versions)