syssi / esphome-soyosource-gtn-virtual-meter

ESPHome component to simulate the current clamp to control the Soyosource GTN1200 limiter
Apache License 2.0
73 stars 20 forks source link

Readout of Shelly 3 EM broken with update of ESPHome to 2024.6 & tentative solution #177

Open fploen opened 2 weeks ago

fploen commented 2 weeks ago

Unfortunately, coding changes to http_request does break the previous readout code for Shelly 3 EM.

I thought the below to be a workaround for code file shelly-3em-http-status-json.yaml https://github.com/syssi/esphome-soyosource-gtn-virtual-meter/blob/main/powermeter-sensor-examples/shelly-3em-http-status-json.yaml

However, I find that the ESP resets itself in regular time periods, but can't seem to find the reason for it... So below possibly still contains a bug I did not find so far.

I suggest the following (works for me). The definition of max_response_buffer_size is important, as the Shelly readout is more than 1k of characters.

substitutions:
  shelly_3em_url: "http://192.168.xxx.x/status/" // adjust to your Shelly 3 EM IP address

http_request:
  id: http_request0
  useragent: esphome/device
  timeout: 1000ms
  esp8266_disable_ssl_support: true (comment if no ESP8266 in use)

sensor:
  - platform: template
    id: powermeter0
    name: "Instantaneous Power"
    unit_of_measurement: W
    device_class: "power"
    accuracy_decimals: 2
    update_interval: never

interval:
  - interval: 1100ms
    then:
      - http_request.get:
          url: ${shelly_3em_url}
          headers:
            Content-Type: application/json
          capture_response: true
          max_response_buffer_size: 2000
          on_response:
            then:
              - lambda: |-
                  json::parse_json(body, [](JsonObject root) -> bool {
                    id(powermeter0).publish_state(root["total_power"]);
                    return true;
                  });
syssi commented 2 weeks ago

Do you like to make a contribution / prepare a pull request to update the broken(?) snippet.

fploen commented 2 weeks ago

Do you like to make a contribution / prepare a pull request to update the broken(?) snippet.

Actually I see a switch to the updated code version is not possible yet, due to an identified bug in the http_request memory allocation, leading to crash of ESP due to short memory. The bug is identified and should be fixed with the next update.

See here