Thank you for taking the time to read my question.
I can communicate with my heating unit through http which I can get to via a curl command. In order to have some data readout (and automatizations) I want to have multiple command line sensors working.
However, when attempting this, I encounter an issue: only one sensor works, the rest return the error message: “Wait at least 2500ms during requests.”
To me this seems as if the heating unit does not like getting 3 commands almost simultaneously.
There seems to be a simple solution: release the curl commands a few seconds apart. I have searched far and wide on how to do this, but to no avail.
Can you delay a command line sensor? Might there be a work around I’m missing?
Thank you for the help!
Below are some of the relevant files for completeness.
config file
# Loads default set of integrations. Do not remove.
default_config:
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensor.yaml
I have disables the ‘value template’ here because only this way the message “Wait at least 2500ms during requests.” pops up, otherwise it understandably shows “unknown”.
I got it to work with (a lot of) help. I will post it here for future reference if somebody else needs this.
This should work for all OKOFEN style pellet central heating units. But of course your mileage may vary.
There is a command that you can extract all data from the heating unit, which will spit out a long JSON file.
sensor: !include sensor.yaml
shell_command:
okfload: bash /config/okofen load
okfset: bash /config/okofen set "{{ key }}" "{{ value }}"
2. add a file named “okofen” without extension to the /config folder
The content of the file is a “black magic” script
#!/bin/bash
COMMAND=$1
FILE=okofen.json
BASEURL=http://192.168.0.xx:4321/w8w0rd
shift
launchurl () {
CURL="curl -s $1"
if [[ $# == 2 ]] ; then
CURL="$CURL -o $2"
fi
RES=`$CURL`
while [[ "$RES" == "Wait at least 2500ms during requests" ]]; do
sleep 3
RES=`$CURL`
done
}
load () {
URL=$BASEURL/all?
launchurl $URL $FILE.tmp
SIZE=`stat -c%s $FILE.tmp`
if [[ $SIZE != 2917 ]] ; then
iconv -f latin1 -t utf-8 $FILE.tmp > $FILE
fi
rm $FILE.tmp
exit 0
}
get () {
cat $FILE
exit 0
}
iset () {
URL=$BASEURL/$1=$2
launchurl $URL
}
case $COMMAND in
load) load $@ ;;
get) get $@ ;;
set) iset $@ ;;
esac
3. add a file named “sensor.yaml” to the /config folder
with the sensors you want to extract from the JSON file. This is my example to get 3 values which are devided by 10 and rounded for convenience:
4. to use the value set function an an automation use shell_command.okfset key = the value adress according to your kettle JSON file value = the value to set, this can be a number or ‘true’, ’ false’, …
example: