#command_line sensor fails to run curl -X

1 messages · Page 1 of 1 (latest)

short rampart
#

error message:
Wait at least 2500ms during requests

I am struggeling since three days to get a python script running to read out some json data from a heating controller based in same subnet.

The script itself runs without any problems from the ssh session on the homeassistant host started as root or other user, but it fails when started using the command_line sensor:

`import requests
import json
import sys
Url = 'http://192.168.178.227:4321/Ccct/hk2'

resp = requests.get(Url)

f = open('log.txt', 'w')
f.write(f'{resp.status_code}\n')
f.write(resp.text)
f.close()

e = {}

try:
e = str(resp.json())
except Exception as ex:
e['time_prg'] = ex.args[0]
finally:
print(json.dumps(e))
sys.exit(0)`

if the script is running in the ssh session, it completes with the output:

"{'hk2': {'L_roomtemp_act': 0, 'L_roomtemp_set': 80, 'L_flowtemp_act': 191, 'L_flowtemp_set': 80, 'L_comfort': 0, 'L_state': 8, 'L_statetext': 'Betriebsart Aus', 'L_pump': 0, 'remote_override': 0, 'mode_auto': 0, 'time_prg': 0, 'temp_setback': 180, 'temp_heat': 220, 'temp_vacation': 150, 'name': 'Verein', 'oekomode': 0, 'autocomfort': -1, 'autocomfort_sunset': 0, 'autocomfort_sunrise': 0}}"

if it is executed by homeassistant I got return code 1, and log.txt contains:
401 Wait at least 2500ms during requests

I now tried to switch to curl. Using curl I had exactly the same problem:

curl -X GET http://192.168.178.227:4321/Ccct/hk2 -o curlout.txt

runs without any problem when executing in ssh, but fails with the output:

Wait at least 2500ms during requests

when executed by homeassistant.

How can I fix this behavior?

Any help is greatly appreciated!!

best regards

Peter

near houndBOT
#

Please use a code share site to share code or logs, for example:

Please don't use Pastebin, since it can randomly add spaces to the main view. Please also don't share text as images since it makes it harder for people to help you. Remember that others may have colour blindness, impaired vision, etc.

dark trench
#

Share the script and I'm sure somebody can help

#

Keep in mind that when you're running it from SSH that's a different container to where HA runs, so if your script requires Python packages then they may not be available

short rampart
short rampart
near houndBOT
#

When using Discord's Reply feature it defaults to pinging the person you reply to, which can get frustrating for the target. Use Shift + click on the Reply option, or click @ ON to @ OFF to stop this - on the right side of the compose bar.

You have to change this every time (thank the Discord devs for that).

dark trench
#

At least you now shared the error, but it sounds like HA can't reach the device, or it's not responding

short rampart
#

how to test that best?

dark trench
#

If you're at home with Docker, opening a shell inside the container to run the curl may help

short rampart
#

docker exec -it $(docker ps -f name=homeassistant -q) bash bash-5.1# curl -X GET http://192.168.178.227:4321/Ccct/hk2 { "hk2":{ "L_roomtemp_act":0, "L_roomtemp_set":80, "L_flowtemp_act":192, "L_flowtemp_set":80, "L_comfort":0, "L_state":8, "L_statetext":"Betriebsart Aus", "L_pump":0, "remote_override":0, "mode_auto":0, "time_prg":0, "temp_setback":180, "temp_heat":220, "temp_vacation":150, "name":"Verein", "oekomode":0, "autocomfort":-1, "autocomfort_sunset":0, "autocomfort_sunrise":0 }

looks like it is working within docker.

Very strange - where to look next?

dark trench
#

What exactly does your command line sensor/whatever look like

near houndBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks. Here's an example

Don't forget you can edit your post rather than repeatedly posting the same thing.

For over 15 lines you must use a code share site such as https://dpaste.org/ (pick YAML for the language), http://pastie.org/ (pick YAML for the language), or https://paste.debian.net/ (pick YAML for the language).

short rampart
#

sorry for the delay, I had to do some other stuff in meanwhile
`sensor:

  • platform: command_line
    command: curl -X GET http://192.168.178.227:4321/Ccct/hk2 -o curlout.txt
    name: curl test
    value_template: "{{ json_value['hk1']['name'] }}"
    json_attributes:

    • mode_auto
    • time_prg
    • name
  • platform: command_line
    name: hkx
    command: python3 test2.py
    value_template: "{{ jason_value['name'] }}"
    json_attributes:
    - mode_auto
    - time_prg
    - name`

#

well, the curl command would leave -o curlout.txt, when running correctly

short rampart
#

oh man - the one who can read is in advantage!

#

The message: Wait at least 2500ms during requests tells me (that's my knowledge after some try and error test circles), that the target JSON-Server on the heat controller does only accept one request every 2500 ms.
The first request in the HA loop was a RESTful Sensor request. All following requests by various command_line sensor possibilities in the same cycle did run in the 2,5 seconds, when the JSON Server blocks following requests - just boring.