WEB REQUEST GET Problem zu Tasmota

Ich habe aktuell leider ein Problem was ich nicht Lösen kann und leider keine weiteren Informationen finde.
Ich möchte mit ESPHome Werte von einem Tasmota Device einsammeln und auf dem ESPHome Webserver visualisieren.
Tasmota bietet die Möglichkeit per Web Request Daten im Json Format auszugeben.

In meinem Fall ist der Befehl: http://192.168.178.18/cm?cmnd=status%2010
als Antwort im Browser bekomme ich dann:
{“StatusSNS”:{“Time”:“2024-07-23T21:18:52”,“DVS7420”:{“energy”:20302.00,“power”:353.150,“Meter_number”:“123456”}}}

Nun das ganze per http_request.get in ESPHome einlesen.
Leider bekomme ich dieses nicht gebacken.

YAML

esphome:
  name: displaytest
  friendly_name: displaytest

esp8266:
  board: d1_mini

# Enable logging
logger:
  level: VERY_VERBOSE

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxx"

ota:
  - platform: esphome
    password: "xxxxxx"

web_server:
  port: 80
  version: 3 

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "xxxxx"
    password: "xxxxxx"

captive_portal:

http_request:
  useragent: esphome/device
  esp8266_disable_ssl_support: true
  timeout: 10s
  #verify_ssl: false
  #id: http_request_test

time:
  - platform: sntp
    id: sntp_time
    timezone: 'Europe/Berlin'

interval:
  - interval: 1min
    then:
      - http_request.get:
          url: http://192.168.178.18/cm?cmnd=status%2010
          headers:
            Content-Type: application/json              
          capture_response: true
          #max_response_buffer_size: 4096
          on_response:
            then:
             - lambda: |-
                 json::parse_json(body, [](JsonObject root) -> bool {
                     id(power_meter).publish_state(root["power"].as< float >());
                     return true;
                 });

sensor:
  - platform: template
    name: "Power"
    id: power_meter
  - platform: wifi_signal
    name: "httptest wifi signal"
    update_interval: 60s
  - platform: uptime
    name:  "httptest uptime"


text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP Address
      id: ip
    ssid:
      name: Connected SSID
      id: ssid

Ich bekomme folgende Fehlermeldung

[22:59:34][V][sensor:043]: 'httptest uptime': Received new state 42.570999
[22:59:34][D][sensor:093]: 'httptest uptime': Sending state 42.57100 s with 0 decimals of accuracy
[22:59:34][V][json:038]: Attempting to allocate 512 bytes for JSON serialization
[22:59:34][V][json:058]: Size after shrink 76 bytes
[22:59:34][VV][api.service:140]: send_sensor_state_response: SensorStateResponse {
  key: 2428623192
  state: 42.571
  missing_state: NO
}
[22:59:34][W][component:237]: Component uptime.sensor took a long time for an operation (66 ms).
[22:59:34][W][component:238]: Components should block for at most 30 ms.
[22:59:34][VV][scheduler:225]: Running interval 'update' with interval=1000 last_execution=42185 (now=43191)
[22:59:34][VV][scheduler:225]: Running interval 'update' with interval=1000 last_execution=42192 (now=43198)
[22:59:35][VV][scheduler:225]: Running interval 'update' with interval=1000 last_execution=43185 (now=44185)
[22:59:35][VV][scheduler:225]: Running interval 'update' with interval=1000 last_execution=43192 (now=44195)
[22:59:35][VV][scheduler:225]: Running interval 'update' with interval=60000 last_execution=4294951804 (now=44509)
[22:59:36][V][http_request.arduino:055]: ESP8266 HTTP connection with WiFiClient
[22:59:36][W][http_request.arduino:065]: Using HTTP on Arduino version >= 3.1 is **very** slow. Consider setting framework version to 3.0.2 in your YAML, or use HTTPS
[22:59:36][D][http_request.arduino:124]: Content-Length: -1
[22:59:36][E][http_request.arduino:137]: Stream pointer vanished!
[22:59:36][E][http_request.arduino:137]: Stream pointer vanished!
[22:59:36][E][http_request.arduino:137]: Stream pointer vanished!
[22:59:36][E][http_request.arduino:137]: Stream pointer vanished!

Habe das LOG Level auf “VERY VERBOSE” gestellt finde jedoch den Fehler nicht.

Vielleicht hat ja jemand eine Idee.

Hi E-Mixer,
ich stand bis vorhin auch vor diesem unschönen Problem.
Fakt ist, dass es wohl im Moment (seit Juni 2024) für das http_request Problem in den aktuellen Versionen von ESPHome keine Lösung gibt.

Daher hier ein aktuell bei mir funktionierender Workaround:

external_components:
  - source: github://esphome/esphome@2024.5.5
    components: [ http_request, json ]

Einfach in deiner YAML oben einfügen, der Rest bleibt wie er ist.
Speichern, neu kompilieren und installieren- fertig.

VG
/braindump

@braindump
vielen Dank für den Tip leider bekomme ich dann diese Fehlermeldung.

INFO ESPHome 2024.8.3
INFO Reading configuration /config/esphome/displaytest.yaml...
INFO Generating C++ source...
INFO Compiling app...
Processing displaytest (board: d1_mini; framework: arduino; platform: platformio/espressif8266@4.2.1)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
Dependency Graph
|-- ESPAsyncTCP-esphome @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- noise-c @ 0.1.6
|-- ArduinoJson @ 6.18.5
|-- ESP8266HTTPClient @ 1.2
Compiling .pioenvs/displaytest/src/main.cpp.o
Archiving .pioenvs/displaytest/lib3ff/libESP8266mDNS.a
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_core/ed25519/core_ed25519.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_core/ed25519/core_ristretto255.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_core/salsa/ref/core_salsa_ref.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_generichash/blake2b/generichash_blake2.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_generichash/blake2b/ref/generichash_blake2b.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_hash/crypto_hash.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_hash/sha256/cp/hash_sha256_cp.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_hash/sha256/hash_sha256.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_hash/sha512/hash_sha512.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_onetimeauth/crypto_onetimeauth.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/argon2-core.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/argon2-encoding.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx2.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx512f.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/argon2.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/blake2b-long.c.o
/config/esphome/displaytest.yaml: In lambda function:
/config/esphome/displaytest.yaml:69:24: error: 'body' was not declared in this scope
   69 |                  json::parse_json(body, [](JsonObject root) -> bool {
      |                        ^~~~
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_scalarmult/crypto_scalarmult.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_sign/crypto_sign.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_sign/ed25519/ref10/keypair.c.o
Compiling .pioenvs/displaytest/libb33/libsodium/crypto_sign/ed25519/ref10/obsolete.c.o
*** [.pioenvs/displaytest/src/main.cpp.o] Error 1
========================== [FAILED] Took 3.35 seconds ==========================

Hi E-Mixer bist Du hier weitergekommen? ich stehe vor dem gleichen Berg…

http_request:
  useragent: esphome/device
  timeout: 10s
  verify_ssl: false
  #id: http_request_test

time:
  - platform: sntp
    id: sntp_time
    timezone: 'Europe/Berlin'

interval:
  - interval: 1min
    then:
      - http_request.get:
           url: http://192.168.1.76/cm?cmnd=Power #status%2010
           headers:
             Content-Type: application/json              
           capture_response: true
           on_response:
             then:
              - lambda: |-
                  json::parse_json(body, [](JsonObject root) -> bool {id(POWER).publish_state(root["vol"]);return true;});


Die Fehlermeldung ist dann

http_request: [source tasmota2.yaml:29]

  Component not found: http_request.
  useragent: esphome/device
  timeout: 10s
  verify_ssl: False
interval: [source tasmota2.yaml:40]
  - interval: 1min
    then:
      -
        Unable to find action with the name 'http_request.get'.
        http_request.get:
          url: http://192.168.1.76/cm?cmnd=Power
          headers:
            Content-Type: application/json
          capture_response: True
          on_response:
            then:
              - lambda: |-
                  json::parse_json(body, [](JsonObject root) -> bool {id(POWER).publish_state(root["vol"]);return true;});

@Ole Sorry für die späte Antwort.
Leider habe ich auch noch keine Lösung.
Im HA Forum gibt es einen Beitrag jedoch ohne Erfolg.
Wir müssen uns wohl leider gedulden bis die Esphome Devs. das Problem gelöst haben.

Gruß E-Mixer

Habe das Problem nun endlich mehr oder weniger gelöst bekommen.
Leider nur ein Workaround aber voll funktionsfähig.

Aufgabe: Analoge Datenpunkte von Tasmota Geräten und OpenDTU per web Request an ESPHome.

esphome:
  name: esphome-web-bb8108
  friendly_name: ESPHome Web bb8108
  min_version: 2024.11.0
  name_add_mac_suffix: false

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


external_components:
  - source: github://hlfcode/esphome@dev
    components: [ http_request ]

    

    
# Enable logging
logger:


# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxx"

ota:
  - platform: esphome
    password: "xxxxxxx"

web_server:
  port: 80

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


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "xxxxxxx"
    password: "xxxxxxx"


captive_portal:

http_request:
  verify_ssl: false

time:
  - platform: sntp
    id: sntp_time
    timezone: 'Europe/Berlin'

interval:
  - interval: 1min
    then:
      - http_request.get:
          url: "http://192.168.178.18/cm?cmnd=status%2010"
          capture_response: true
          on_response:
            then:
              - lambda: |-
                  json::parse_json(body, [](JsonObject root) -> bool {
                    if (root.containsKey("StatusSNS") && root["StatusSNS"].containsKey("DVS7420")) {
                      float energy = root["StatusSNS"]["DVS7420"]["energy"].as<float>();
                      float power = root["StatusSNS"]["DVS7420"]["power"].as<float>();

                      id(Energie).publish_state(energy);
                      id(Leistung).publish_state(power);

                      ESP_LOGD("main", "Energie: %.2f kWh, Leistung: %.2f W", energy, power);
                      return true;
                    } else {
                      ESP_LOGW("main", "Ungültige JSON-Antwort erhalten.");
                      return false;
                    }
                  });
      - http_request.get:
          url: "http://192.168.178.10/api/livedata/status"
          capture_response: true
          on_response:
            then:
              - lambda: |-
                  json::parse_json(body, [](JsonObject root) -> bool {
                    if (root.containsKey("total") && root["total"].containsKey("Power")) {
                      float Leistung = root["total"]["Power"]["v"].as<float>();
                      float ErtragTag = root["total"]["YieldDay"]["v"].as<float>();
                      float ErtragGesamt = root["total"]["YieldTotal"]["v"].as<float>();
                      id(aktLeistung).publish_state(Leistung);
                      id(Tagesertrag).publish_state(ErtragTag);
                      id(Gesamtertrag).publish_state(ErtragGesamt);
                      ESP_LOGD("main", "aktLeistung: %.2f W, Tagesertrag: %.2f Wh, Gesamtertrag: %.2f kWh", Leistung, ErtragTag, ErtragGesamt);
                      return true;
                    } else {
                      ESP_LOGW("main", "Ungültige JSON-Antwort erhalten.");
                      return false;
                    }
                  });
sensor:
  - platform: template
    id: Energie
    name: "Energie"
    unit_of_measurement: "kWh"
    accuracy_decimals: 2
  - platform: template
    id: Leistung
    name: "Leistung"
    unit_of_measurement: "W"
    accuracy_decimals: 0
  - platform: template
    id: aktLeistung
    name: "Wechselrichter Leistung"
    unit_of_measurement: "W"
    accuracy_decimals: 0
  - platform: template
    id: Tagesertrag
    name: "Tagesertrag"
    unit_of_measurement: "Wh"
    accuracy_decimals: 0
  - platform: template
    id: Gesamtertrag
    name: "Gesamtertrag"
    unit_of_measurement: "kWh"
    accuracy_decimals: 0
  - platform: wifi_signal
    name: "ESPHome Web bb8108"
    update_interval: 60s
  - platform: uptime
    name:  "ESPHome Web bb8108"

switch:
  - platform: restart
    name: "Restart ESPHome Web bb8108"
 
text_sensor:
  - platform: wifi_info
    ip_address:
      name: IP Address
      id: ip
    ssid:
      name: Connected SSID
      id: ssid