Value Template for command line sensor

Hi,

from a command line sensor i get this response :
HTTP/1.1 200 OK Content-Type: text/html; charset=UTF-8 Accept-Ranges: bytes Connection: close ok<D_A_1_1>0.00</D_A_1_1>

I need only the 0.00.

Can anybody create me an Value Template.

Sorry im a noob at hassio.

That looks like a better candidate for a scrape sensor if you’re retrieving that from a web server.

That is the response from a Water Softener Machine Grunbeck SC18.
With a rest sensor there is no result. In the manual from grunbeck is write that xml is the response.

With the curl :

curl -X POST -i ‘http://192.168.2.9/mux_http’ --data ‘id=622&show=D_A_1_1~’

there is a response.

But i need only 0.00

try adding this to the end of your command line sensor:

| grep -oP "(?<=D_A_1_1>).*?(?=</D_A_1_1>)"

I dont understand where to put it in ?

sensor:
  - platform: command_line
    name: wasserdurchfluss
    command: "curl -X POST -i 'http://192.168.2.9/mux_http' --data 'id=622&show=D_A_1_1~'"

command: "curl -X POST -i 'http://192.168.2.9/mux_http' --data 'id=622&amp;show=D_A_1_1~' | grep -oP '(?<=D_A_1_1>).*?(?=</D_A_1_1>)' "

At least I think that will work…

It comes unknown as result.

What ist the&amp ? What make this ?

sorry that was a copy/paste artifact.

command: "curl -X POST -i 'http://192.168.2.9/mux_http' --data 'id=622&show=D_A_1_1~' | grep -oP '(?<=D_A_1_1>).*?(?=</D_A_1_1>)' "

It comes also unknown as result.

sorry I’m no Unix guru.

I use that in my command line sensor to return the value between two defined strings:

command: 'curl -k --silent "http://192.168.1.52:8002/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxx&pwd=yyyyyyyyyy" | grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"'

where the output of the http request is:

<CGI_Result>
    <result>0</result>
    <IOAlarm>0</IOAlarm>
    <motionDetectAlarm>1</motionDetectAlarm>
    <soundAlarm>0</soundAlarm>
    <record>0</record>
    <sdState>0</sdState>
    <sdFreeSpace>0k</sdFreeSpace>
    <sdTotalSpace>0k</sdTotalSpace>
    <ntpState>2</ntpState>
    <ddnsState>2</ddnsState>
    <url></url>
    <upnpState>0</upnpState>
    <isWifiConnected>0</isWifiConnected>
    <wifiConnectedAP></wifiConnectedAP>
    <infraLedState>0</infraLedState>
</CGI_Result>

The colums are different from your Posts.

what does that mean?

the " and `are different in your replys.

the outermost quotation marks need to be the opposite kind of the inner ones. it has to do with the way the information is parsed.

for example if you did it this way and they are all the same type:

'curl -k --silent 'http://192.168.1.52:8002/cgi-bin/CGIProxy.fcgi?cmd=getDevState&amp;usr=xxxxx&amp;pwd=yyyyyyyyyy' | grep -oP (?&lt;=motionDetectAlarm&gt;).*?(?=&lt;/motionDetectAlarm&gt;)''

then what the parser would see is:

curl -k --silent

http://192.168.1.52:8002/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxx&pwd=yyyyyyyyyy

| grep -oP

(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)

and the parser wouldn’t know where the command stopped and what parts were supposed to be included in the command and which parts are not.

I’m not entirely sure it would be a problem in a command like this but i know it’s a problem in the jinja parser in a template so it is always best to be consistent.

But why i get as result unknown ?

try to run the entire curl command (including the part i added) in the terminal and see what is returned.

As a test I just copied all of the content of your returned data from your first post above into a file I called “test”. Then in my command line terminal I ran the “grep” portion of the command from the command above and it returned the exact value I expected it to:

ex

So I know that my portion of the command will work as expected.

Can you also post the config for the command-line sensor with the portion I added that is returning unknown just so we can be sure there are no syntax errors?

  - platform: command_line
    name: wasserdurchfluss
    command: "curl -X POST -i 'http://192.168.2.9/mux_http' --data 'id=622&show=D_A_1_1~' | grep -oP '(?<=D_A_1_1>).*?(?=</D_A_1_1>)' "

have you tried to run the entire curl command in a terminal yet to see if it works there?

The answer is
pipe dquote>

without any value

i don’t understand what that means.

can you take a screen shot?