'value_json' is undefined when rendering

That means it’s 100% not json, so your output is adding special hidden characters because your encoding is wrong.

As I can not influence the esp32’s json output, is there a way to get this command_line switch working properly?

I have tried many ways even as you suggested, but nothing seems to work.

Try this:

value_template: "{{ (value|regex_findall('evseState.: ([a-z]*),'))[0] }}"

Will do. Where/how does this check for evsestate = true?

He really should just output proper JSON. That hot mess of an output won’t work if he wants any other value.

I have done the hexdump.

Can you point me to the exact error in the json? I can then ask to author of the code to fix it.

value_template: "{{ (value|regex_findall('evseState.: ([a-z]*),'))[0] }}"

Doesn’t work. The switch turns off right after turning it on.

It doesn’t: it returns true or false, or whatever else evseState shows. That should be the same as checking for true.

No: the hexdump looks valid to me.

What are you using to view the values of hexdump, I’m unfamiliar with the output, it has no order associated w/ the proper characters.

Nm, got it

Embarrassingly, Excel. I forgot to ask for hexdump -c, so had to swap them all around. There’s no extra junk being returned from the curl call directly. I don’t know where the problem is. That hexdump output corresponds to:

{"type":"parameters","list":[{"vehicleState":1,"evseState":false,"maxCurrent":20,"actualCurrent":6,"actualPower":0,"duration":2850000,"alwaysActive":false,"lastActionUser":"API","lastActionUID":"API","energy":0,"mileage":0,"meterReading":0,"currentP1":0,"currentP2":0,"currentP3":0,"useMeter":true}]}

…and the template editor has no issues with treating that as a JSON object directly.

I have used an online validator that uses the URL and not the copy/pasted data. I opened my firewall for that temporarily and ran the test repeatedly:

# curl -X GET http://192.168.207.98/getParameters | hexdump -c
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   298  100   298    0     0   9896      0 --:--:-- --:--:-- --:--:--  9933
0000000   {   "   t   y   p   e   "   :   "   p   a   r   a   m   e   t
0000010   e   r   s   "   ,   "   l   i   s   t   "   :   [   {   "   v
0000020   e   h   i   c   l   e   S   t   a   t   e   "   :   1   ,   "
0000030   e   v   s   e   S   t   a   t   e   "   :   f   a   l   s   e
0000040   ,   "   m   a   x   C   u   r   r   e   n   t   "   :   2   0
0000050   ,   "   a   c   t   u   a   l   C   u   r   r   e   n   t   "
0000060   :   6   ,   "   a   c   t   u   a   l   P   o   w   e   r   "
0000070   :   0   ,   "   d   u   r   a   t   i   o   n   "   :   3   4
0000080   0   0   0   ,   "   a   l   w   a   y   s   A   c   t   i   v
0000090   e   "   :   f   a   l   s   e   ,   "   l   a   s   t   A   c
00000a0   t   i   o   n   U   s   e   r   "   :   "   A   P   I   "   ,
00000b0   "   l   a   s   t   A   c   t   i   o   n   U   I   D   "   :
00000c0   "   A   P   I   "   ,   "   e   n   e   r   g   y   "   :   0
00000d0   ,   "   m   i   l   e   a   g   e   "   :   0   ,   "   m   e
00000e0   t   e   r   R   e   a   d   i   n   g   "   :   0   ,   "   c
00000f0   u   r   r   e   n   t   P   1   "   :   0   ,   "   c   u   r
0000100   r   e   n   t   P   2   "   :   0   ,   "   c   u   r   r   e
0000110   n   t   P   3   "   :   0   ,   "   u   s   e   M   e   t   e
0000120   r   "   :   t   r   u   e   }   ]   }                        
000012a

I had to do this, because the way it chunks things. I’m not seeing any extra characters either. FYI…

data = """227b 7974 6570 3a22 7022 7261 6d61 7465
7265 2273 222c 696c 7473 3a22 7b5b 7622
6865 6369 656c 7453 7461 2265 313a 222c
7665 6573 7453 7461 2265 663a 6c61 6573
222c 616d 4378 7275 6572 746e 3a22 3032
222c 6361 7574 6c61 7543 7272 6e65 2274
363a 222c 6361 7574 6c61 6f50 6577 2272
303a 222c 7564 6172 6974 6e6f 3a22 3832
3035 3030 2c30 6122 776c 7961 4173 7463
7669 2265 663a 6c61 6573 222c 616c 7473
6341 6974 6e6f 7355 7265 3a22 4122 4950
2c22 6c22 7361 4174 7463 6f69 556e 4449
3a22 4122 4950 2c22 6522 656e 6772 2279
303a 222c 696d 656c 6761 2265 303a 222c
656d 6574 5272 6165 6964 676e 3a22 2c30
6322 7275 6572 746e 3150 3a22 2c30 6322
7275 6572 746e 3250 3a22 2c30 6322 7275
6572 746e 3350 3a22 2c30 7522 6573 654d
6574 2272 743a 7572 7d65 7d5d"""
out = ''.join([chr(int(c[2:], base=16)) + chr(int(c[:2], base=16)) for c in data.split()])

output is

{"type":"parameters","list":[{"vehicleState":1,"evseState":false,"maxCurrent":20,"actualCurrent":6,"actualPower":0,"duration":2850000,"alwaysActive":false,"lastActionUser":"API","lastActionUID":"API","energy":0,"mileage":0,"meterReading":0,"currentP1":0,"currentP2":0,"currentP3":0,"useMeter":true}]}

So now we established that the json is correct right?
Then why does HA throw this error after a restart?

What’s the hardware setup here? Is HA on a different machine to 192.168.207.98? Is it on the same subnet? Where did you run the hexdump command?

The API is running on a esp32, HA is running on a Proxmox host, where I made the Hex Dump. All on the same subnet.

If you need me to test anything else, please let me know!

This is from the HA VM:

CleanShot 2023-10-25 at 16.26.57

Humor me and create these 2 sensors…

command_line:
  - sensor:
      name: EVSE test 1
      command: "curl -X GET http://192.168.207.98/getParameters"
      value_template: "{{ value[:250] }}"
  - sensor:
      name: EVSE test 2
      command: "curl -X GET http://192.168.207.98/getParameters"
      value_template: "{{ value[250:] }}"

post the states of both here.

{"type":"parameters","list":[{"vehicleState":2,"evseState":false,"maxCurrent":20,"actualCurrent":6,"actualPower":0,"duration":4000,"alwaysActive":false,"lastActionUser":"API","lastActionUID":"API","energy":0,"mileage":0,"meterReading":0,"currentP1":0
,"currentP2":0,"currentP3":0,"useMeter":true}]}

Seems to be correctly formatted.

not sure what to tell you then. You should not be getting that error at all. It seems like your device is doing something odd.

This should work, but keep in mind this integration polls, so when you click the turn on, it can take upwards of 30 seconds for the state to change in the UI.

command_line:
  - switch:
      name: EVSE
      unique_id: command_line_evse
      icon: mdi:ev-station
      command_on: "curl http://192.168.207.98/setStatus?active=true"
      command_off: "curl http://192.168.207.98/setStatus?active=false"
      command_state: "curl -X GET http://192.168.207.98/getParameters"
      value_template: >
        {% set found = value | regex_findall('"evseState":true|"evseState":false') %}
        {{ 'true' in found[0] if found else false }}
1 Like