Created
January 20, 2023 08:38
-
-
Save Schm1tz1/6e1b9cdb49e2376b1ea3ee11bbc8fa46 to your computer and use it in GitHub Desktop.
openHAB Scripts to get vcontrold values and push via REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getTempA;Vitodens_Outside_Temp | |
getTempWWist;Vitodens_WW_Temp | |
getTempWWsoll;Vitodens_WW_Temp_Set | |
getBrennerStatus;Vitodens_Brenner_Status | |
getBrennerStarts;Vitodens_Brenner_Starts | |
getBrennerStunden1;Vitodens_Brenner_Stunden | |
getTempAbgas;Vitodens_Brenner_Abgas_Temp | |
getTempVListM1;Vitodens_Heizung_Vorlauf_Temp | |
getTempRL17A;Vitodens_Heizung_Ruecklauf_Temp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
VC_COMMAND_MAP="/home/openhabian/vclient/command_item_map.txt" | |
SED_LINE="" | |
declare -A itemMap | |
for i in $(cat ${VC_COMMAND_MAP}); do | |
mapFrom="$(echo $i | cut -d ';' -f1 | xargs)" | |
mapTo="$(echo $i | cut -d ';' -f2 | xargs)" | |
SED_LINE+="s/\<$mapFrom\>/$mapTo/g;" | |
itemMap+=[$mapFrom]=$mapTo | |
done | |
VC_COMMANDS=$(cat ${VC_COMMAND_MAP} | cut -d ';' -f1 | tr '\n' ',') | |
VC_RESULT=($(vclient --host localhost:3002 --command $VC_COMMANDS --munin | tr ' ' ':')) | |
for i in "${VC_RESULT[@]}"; do | |
key="$(echo $i | cut -d ':' -f1 | sed 's/.value//g' | xargs)" | |
mappedKey=$(echo $key | sed $SED_LINE) | |
value="$(echo $i | cut -d ':' -f2 | xargs)" | |
# regex-check whether we have a number or not | |
re='^[+-]?[0-9]+([.][0-9]+)?$' | |
if ! [[ $value =~ $re ]] ; then | |
echo "$key: '$value' is not a number - skipping!" >&2; | |
else | |
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "${value}" "http://openhabianpi:8080/rest/items/${mappedKey}" -u "<API-Key for OH>" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment