ESPHome weatherstation, record to mysql database?

Hi everyone!

I’m probably in way over my head here…
I have set up a custom weatherstation on an ESP-07 running ESPHome, this is all integrated in HomeAssistant fine and dandy.

What I am working on next, is having the ability to view these readings on my website. So I have set up a MySQL database on the website and added a php page to upload these data. As per this guide: ESP32/ESP8266 Insert Data into MySQL Database | Random Nerd Tutorials

So, on to the question… Using http_request.post I’m getting this response in the logger from the esp device. Have I done something wrong? Any tips welcomed.

[16:37:33][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
[16:37:34][D][http_request.arduino:124]: Content-Length: -1
[16:37:34][W][component:237]: Component interval took a long time for an operation (580 ms).
[16:37:34][W][component:238]: Components should block for at most 30 ms.

Code snippet on ESP device:

interval:
  - interval: 10min
    then:
      - http_request.post:
          url: *REDACTED*post-esp-data.php
          body: !lambda |-
            char buf1[16];
            char buf2[16];
            char buf3[16];
            char buf4[16];
            char buf5[16];
            char buf6[16];
            sprintf(buf1, "%0f", id(press).state);
            sprintf(buf2, "%0f", id(i_lux).state);
            sprintf(buf3, "%0.1f", id(hum).state);
            sprintf(buf4, "%0.2f", id(temp).state);
            sprintf(buf5, "%s", id(wdir).state.c_str());
            sprintf(buf6, "%0.1f", id(my_wind).state);
            return ((std::string) "api_key=*REDACTED*" + "&sensor=WeatherStation" + "&location=*REDACTED*"
            + "&value1=" + buf1 + "&value2=" + buf2 + "&value3=" + buf3
            + "&value4=" + buf4 + "&value5=" + buf5 + "&value6=" + buf6 + "").c_str();

Ok, so for reference I kinda figured it out. Just need to know how to format this in YAML…

What I need output from the ESP device is:

POST /post-esp-data.php HTTP/1.1
Host: *REDACTED*
Accept: application/json
Content-Type: application/x-www-form-urlencoded
Content-Length: 122

api_key=*REDACTED*&sensor=WeatherStation&location=*REDACTED*&value1=1000&value2=250&value3=76.4&value4=7.7&value5=North&value6=16.5

But I’m getting wrong API key, so format is wrong…

I tried this aswell without luck:

interval:
  - interval: 10min
    then:
      - http_request.post:
          url: *REDACTED*/post-esp-data.php
          headers:
            Accept: application/json
          body: !lambda |-
            char buf1[16];
            char buf2[16];
            char buf3[16];
            char buf4[16];
            char buf5[16];
            char buf6[16];
            sprintf(buf1, "%0f", id(press).state);
            sprintf(buf2, "%0f", id(i_lux).state);
            sprintf(buf3, "%0.1f", id(hum).state);
            sprintf(buf4, "%0.2f", id(temp).state);
            sprintf(buf5, "%s", id(wdir).state.c_str());
            sprintf(buf6, "%0.1f", id(my_wind).state);
            return ((std::string) "api_key=*REDACTED*" + "&sensor=WeatherStation" + "&location=*REDACTED*"
            + "&value1=" + buf1 + "&value2=" + buf2 + "&value3=" + buf3
            + "&value4=" + buf4 + "&value5=" + buf5 + "&value6=" + buf6 + "").c_str();