Why is my curl we sensor only returning 25 character?

I’ve been pulling my hair out for much of the day with this.

My command_line sensor pulls in some data as follows

  - platform: command_line  
    command: 'curl -s | xxd -r -p'
    name: candy_washing_machine_100
    scan_interval: 20
    command_timeout: 30

So this is gathering the contents of

On here is an load of data, in a hex format


Using Hex to ASCII | Hex to Text converter I can convert this back into ASCII and get


This is the data I would like to get into my sensor.

I believe using " | xxd -r -p" in my curl command is converting the hex to plain text for me, however my sensor is only returning th first 25 characters of this so I get incomplete JSON meaning I can’t then filter down to the data I need

Am I missing something obvious here. Any help much appreciated

Thank you

The state can only hold 255 characters.
What you have there is 788 characters.

I assume if you take the first 255 characters and convert them you get what you have in your state.
You need to make sure it becomes an attribute.
not sure how that is done when it is in hex, but normally you would add:

      - statusLavatrice

to the sensor.


The 788 characters are in hex, they are converted to ASCII and command line level so should be returned at ASCII and then only 355 characters.

Your point still stands however that this is too much for a value, I just don’t understand why it would return 25 characters. (Coincidentally 255 characters of hex would equate to a lot more text too).

I have already tried to use a value_template and also attributes, but then I can’t get any data at all.

  - platform: command_line  
    command: 'curl -s | xxd -r -p'
    name: candy_washing_machine_101
    value_template: '{{ value_json.statusLavatrice.Pr }}'
    scan_interval: 20
    command_timeout: 30
      - statusLavatrice

I’m should suspect that the sensor value should give me 15, being the value of Pr.

However, the value of the sensor is now shown as “unknown”.

It’s in these kind of situations I use Node red to just get it done.
Perhaps there is a error in the logs?

There is no “value_json” for a command-line sensor, only for rest/mqtt.
Use jq in you commad line to extract the value.

1 Like

I didn’t notice that. Good catch!

But then again… Why did he get a partial state?

Well, I tried the code and HA gave me an explicit error.

ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'value_json' is undefined when rendering '{{ value_json.statusLavatrice.Pr }}'

There must be some confusion at hand…

EDIT: | xxd -r -p | jq .statusLavatrice.Pr works nicely in a plain shell, but not inside docker. There is something fishy with xxd

EDIT2: | xxd -r -p -c 1000 | jq .statusLavatrice.Pr works

Good morning.

Thank you very much for your help.

I had tried | jq yesterday too but to no avail.

Judging by your edits, you think -c fixed the issue I was having? Im not familiar with XXD but this is something to do with the number of “columns” it returns isnt it? Very odd, but thank you so much, i wouldnt have got here alone!