Help with http request get, please

Can anyone help me with finding the fault here?
It says "parse is not af member og esphome::json
This is how long I have come with help of ChatGPT:

type or paste code here
esphome:
  name: ecoteck-pilleovn
  friendly_name: Ecoteck pilleovn

esp8266:
  board: esp01_1m

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_pilleovn

ota:
  - platform: esphome
    password: !secret ota_pilleovn_password


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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ecoteck-Pilleovn"
    password: !secret wifi_password

captive_portal:

# HTTP Webserver til GET-anmodninger
web_server:
  port: 80

# Template sensor for temperatur1 (float)
sensor:
  - platform: template
    name: "temperatur1"
    id: temperatur1
    unit_of_measurement: "°C"
    device_class: "temperature"

# Variabel til at gemme temperaturen
globals:
  - id: temperature_value
    type: float
    restore_value: no
    initial_value: '0.0'

# HTTP request configuration
http_request:
  useragent: esphome/device
  id: http_request_id
  verify_ssl: false

interval:
  - interval: 59s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - http_request.get:
              url: !secret ecoteck_get_url
              capture_response: true
              on_response:
                - if:
                    condition:
                        lambda: |-
                          return response->status_code == 200;  
                    then:
                      - lambda: |-
                          // Deklarer json_data og parse JSON-responsen korrekt
                          auto json_data = json::parse(body);
                          
                          // Håndter temperatur1 (float)
                          if (json_data.contains("temperatur1")) {
                            float temperatur1 = json_data["temperatur1"];
                            id(temperatur1).publish_state(temperatur1);  // Opdater sensor med temperatur
                          }

Don’t rely on robot hallucinations. This example from the ESPHome docs might help:

It uses json::parse_json which presumably does exist.

1 Like

This is excellent advice. AI can and will make assumptions about functions that it thinks should be there. It is left as an exercise for the user to figure out which parts are correct and which are not. If you don’t know what you are doing, having an assistant that can type really fast but makes lots of mistakes isn’t as helpful as it first sounds.

Thanks
This did it

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

1 Like