Http_request.get does not work need one variable from webpage

Hello,
i am trying to read a value from a website and put it in a sensor template so i can see it in the espdevice
running 2025.10
this is the error i get
[E][json:059]: Parse error: IncompleteInput

i want the “Counter” value in sensor template meter_value but i get the error
[E][json:059]: Parse error: IncompleteInput

this is the json output from the website

{
	"ActTime" : 1763502375,
	"AstrTwilightEnd" : "18:44",
	"AstrTwilightStart" : "06:08",
	"CivTwilightEnd" : "17:22",
	"CivTwilightStart" : "07:31",
	"DayLength" : "08:34",
	"NautTwilightEnd" : "18:04",
	"NautTwilightStart" : "06:48",
	"ServerTime" : "2025-11-18 22:46:15",
	"SunAtSouth" : "12:26",
	"Sunrise" : "08:09",
	"Sunset" : "16:43",
	"app_version" : "2025.1 (build 16782)",
	"result" : 
	[
		{
			"AddjMulti" : 1.0,
			"AddjMulti2" : 1.0,
			"AddjValue" : 0.0,
			"AddjValue2" : 1000.0,
			"BatteryLevel" : 255,
			"Counter" : "3130.049 m3",
			"CounterToday" : "486 Liter",
			"CustomImage" : 0,
			"Data" : "3130.049 m3",
			"Description" : "",
			"Divider" : 1000.0,
			"Favorite" : 1,
			"HardwareDisabled" : false,
			"HardwareID" : 5,
			"HardwareName" : "Dummy",
			"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
			"HardwareTypeVal" : 15,
			"HaveTimeout" : false,
			"ID" : "141A8",
			"LastUpdate" : "2025-11-18 22:17:40",
			"Name" : "Watermeter",
			"Notifications" : "false",
			"PlanID" : "0",
			"PlanIDs" : 
			[
				0
			],
			"Protected" : false,
			"ShowNotifications" : true,
			"SignalLevel" : "-",
			"SubType" : "RFXMeter counter",
			"SwitchTypeVal" : 2,
			"Timers" : "false",
			"Type" : "RFXMeter",
			"TypeImg" : "counter",
			"Unit" : 1,
			"Used" : 1,
			"ValueQuantity" : "Custom",
			"ValueUnits" : "",
			"XOffset" : "0",
			"YOffset" : "0",
			"idx" : "344",
			"price" : "0.9720"
		}
	],
	"status" : "OK",
	"title" : "Devices"
}

this is my code

esphome:
  name: esp32-watermeter
  friendly_name: ESP32-Watermeter

http_request:
  verify_ssl: false
  useragent: esphome/device

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: esp-idf

# Enable logging
logger:
  level: VERBOSE
  baud_rate: 0 ## Must be 0 to prevent reading issues and buffer overflows

# Enable Home Assistant API
api:
  reboot_timeout: 0s


ota:
  - platform: esphome
    password: "fc0ddd346a0faf5c5f5638964fec706b"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  manual_ip:
    static_ip: 192.168.1.149
    gateway: 192.168.1.1
    subnet: 255.255.255.0

mqtt:
  broker: 192.168.1.50
  username: ""
  password: ""

captive_portal:

web_server:
  local: true


button:
  - platform: restart
    id: restart_button
    name: -Restart
    entity_category: diagnostic


  - platform: template
    name: "meterstand2"
    on_press:
      then:
          - http_request.get:
              url: http://192.168.1.50:8084/json.htm?type=command&param=getdevices&rid=344
              request_headers:
                Content-Type: application/json
                max_response_buffer_size: 10
              capture_response: true
              on_response:
                - if:
                    condition:
                        lambda: |-
                          return response->status_code == 200;  
                    then:
                      - lambda: |-
                          json::parse_json(body, [](JsonObject root) -> float {
                              id(meter_value).publish_state(root["Counter"]);
                              return true;
                          });


sensor:

- platform: template
  name: "Domoticz watermeter"
  id: meter_value
  accuracy_decimals: 0

also tried this example from the home assistant site but that one complains a lot about ESP_logi TAG not declared and lots of other errors.

these examples seem so simple but in real life they do not work out of the box

on_...:
- http_request.get:
    url: https://esphome.io
    capture_response: true
    on_response:
      then:
        - if:
            condition:
                lambda: return response->status_code == 200;
            then:
                - lambda: |-
                    json::parse_json(body, [](JsonObject root) -> bool {
                        if (root["vol"]) {
                            id(player_volume).publish_state(root["vol"]);
                            return true;
                        }
                        else {
                          ESP_LOGI(TAG,"No 'vol' key in this json!");
                          return false;
                        }
                    });
            else:
                - logger.log:
                    format: "Error: Response status: %d, message %s"
                    args: [ 'response->status_code', 'body.c_str()' ]

Few considerations:
Counter is not at the root and it’s not a float.

thanks.
i tried other code which also take this in consideration but same result

  - platform: template
    name: "meterstand2"
    on_press:
      then:
          - http_request.get:
              url: http://192.168.1.50:8084/json.htm?type=command&param=getdevices&rid=344
              request_headers:
                Content-Type: application/json
                max_response_buffer_size: 2048
              capture_response: true
              on_response:

                - if:
                    condition:
                        lambda: |-
                          return response->status_code == 200;  
                    then:
                      - lambda: |-
                          json::parse_json(body, [](JsonObject root) -> float {
                            if (root.containsKey("result")) {
                              JsonObject result = root["result"];
                              if (result.containsKey("Counter")) {
                                id(meter_value).publish_state(((JsonObject) root["result"])["Counter"]);
                                return true;
                              }
                            }
                            return false;
                          });

at this is what i see in the log

12:11:04.246][D][http_request.idf:043]: Received response header, name: content-length, value: 1498
[12:11:04.252][D][http_request.idf:043]: Received response header, name: content-type, value: application/json;charset=UTF-8
[12:11:04.262][E][json:059]: Parse error: IncompleteInput

Json parsing is black magic.

You can’t try to get float from that because Counter is a string “3130.049 m3”.
You need to read it as a string and exclude m3 and the convert it to float.

Also, buffer 2048 is likely too small, try >5kB

ok
tried that
string is not recognized as a type
bool and float are.

according to this side it is a valid type but esphome obviously does not support it.

bool should accept it as a string.

the problem is i can not see what is received by esphome as a response

there is no simple way to redirect the response body to the log or to mqtt.

i am busy solving problems to solve problems to solve problems while the thing i want is reasonable to ask

Try something like:

JsonObject device = root["result"][0];

const char* counterstring = device["Counter"];

float value = atof(counterstring);

thanks everybody but this is getting way to complex.

typing a thousand lines just to get 1 variable from a website.

i am taking another route to this problem.

sending a http request to the target to flip a switch so it will send me the data i need over MQTT
receiving the mqtt data inside the esphome device

getting the data from a webpage sounds a lot more easier but it turns out it is way to complex for people with limited knowledge(that’s me)

if you look on the homeassistant site there are a lot of people struggling with this and all the code(including examples which i posted) do not work

even if it does work then it could well be that after a couple of upgrades the functionality has changed or is gone.

I told you it’s black magic…

My curiosity for the time spent, so what you get with this?

on_press:
  then:
    - http_request.get:
        url: http://192.168.1.50:8084/json.htm?type=command&param=getdevices&rid=344
        max_response_buffer_size: 8000
        on_response:
          then:
            - lambda: |-
                  - lambda: |-
                      json::parse_json(body, [](JsonObject root) {
                      JsonObject device = root["result"][0];
                      const char* counterstring = device["Counter"];
                      float value = atof(counterstring);
                      id(meter_value).publish_state(value);
                      return true;
                      });