How to read status from tasmota power plug with http_request. get in ESPHOME?

I struggle since weeks on this topic. Neither esphome.io , github or chatGPT could help me. (My knowledge ends when it comes to lambda-things):

I am looking for a script for ESPHOME to read the status of a Tasmota power plug in esphome.
All read examples does not work or could not compiled.
Could anyone help me in this topic?

thank you already for your time :slight_smile:
br
Ole

so post what’s the correct syntax to read Tasmota and your trial with esphome.

You need to configure http:

Sending this to tasmota you get the response in json:

http://192.168.0.30/cm?cmnd=POWER

Yes this is right the HTTP command is this

Here my last trial, which also does not compile:

binary_sensor:
  - platform: template
    name: "Tasmota Switch Status"
    id: tasmota_switch
    lambda: |-
      return id(tasmota_status).state == "ON";

sensor:
  - platform: http_request
    name: "Tasmota Status"
    id: tasmota_status
    method: GET
    url: http://192.168.1.76/cm?cmnd=Power
    headers:
      Content-Type: application/json
    value_template: "{{ value_json.POWER }}"
    scan_interval: 10s

interval:
  - interval: 10s
    then:
      - lambda: |-
          if (id(tasmota_status).state == "ON") {
            id(tasmota_switch).publish_state(true);
          } else {
            id(tasmota_switch).publish_state(false);
          }

Here the error message:

INFO ESPHome 2023.10.1
INFO Reading configuration tasmota2.yaml...
Failed config

sensor.http_request: [source tasmota2.yaml:51]

  Platform not found: 'sensor.http_request'.
  platform: http_request
  name: Tasmota Status
  id: tasmota_status
  method: GET
  url: http://192.168.1.76/cm?cmnd=Power
  headers:
    Content-Type: application/json
  value_template: {{ value_json.POWER }}
  scan_interval: 10s

First of all you have to add the component to your yaml:
http_request:
Also, I have doubt there is sensor platform for it.
You could make the request with interval component.

This is how I request power from Shelly Em and update template sensor(id spower).

then:
                - http_request.get:
                    url: http://192.168.0.240/emeter/1
                    verify_ssl: false
                    on_response:
                      then:
                        - lambda: |-
                            json::parse_json(id(http_request_data).get_string(), [](JsonObject root) {
                            id(spower).publish_state(root["power"]);
                            });

You could use device group and a dummy relay

If the tasmota plug is toggled on/off then then it syncs with that relay

If he can depend on Home Assistant he can use this:

binary_sensor:
  - platform: homeassistant
    id: ha_light_frente
    entity_id: light.frente

unfort. i can not link to HA. the system is running standalone (only esphome)

Here is an example of esphome for esphome:

binary_sensor:
  - platform: template
    name: "Esphome state"
    id: ryzen_power
    device_class: plug

http_request:
  useragent: esphome/device
  id: http_request_id
  verify_ssl: false

interval:
  - interval: 10s
    then:
      if:
        condition:
          wifi.connected:
        then:
          - http_request.get:
              url: http://192.168.0.44/binary_sensor/ryzen_power
              capture_response: true
              on_response:
                - if:
                    condition:
                        lambda: |-
                          return response->status_code == 200;  
                    then:
                      - lambda: |-
                          json::parse_json(body, [](JsonObject root) -> bool {
                              id(ryzen_power).publish_state(root["state"]);
                              return true;
                          });

But there is some bug in esphome, which prevents the return of the tasmota status.
If you try to use it on tasmota you will get the error below and you will need to flash another firmware via USB.

[14:38:03][D][http_request.arduino:119]: Content-Length: -1
[14:38:03][E][http_request.arduino:132]: Stream pointer vanished!

You can try help here: