How to get weather on esp using API with key?

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
cccp79
Normal user
Posts: 33
Joined: 06 Nov 2023, 10:24
Location: RU

How to get weather on esp using API with key?

#1 Post by cccp79 » 06 Nov 2023, 11:02

Hello everyone, is it possible to use Generic HTTP Advanced to get weather data using the API with a key, receive a json response and analyze its desired values on a dummy device? I forgot to say - this is an https request form "https://api.weather.........." . I guess it's possible, but I don't understand how and where to specify the API key? Then, to parse the json, I understand you need to use the MQTT import plugin? But I can't get a response from the server (404). Help me figure this out. Thank you.

User avatar
Ath
Normal user
Posts: 4151
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to get weather on esp using API with key?

#2 Post by Ath » 06 Nov 2023, 11:32

Please check out this pending pull request: #4856 where a code-change is suggested to also retrieve weather info from OpenWeatherMap (starting from this comment).

Currently, ESPEasy doesn't support this, mostly because the response from most webservers will be overloading the limited resources of specifically an ESP8266.
/Ton (PayPal.me)

cccp79
Normal user
Posts: 33
Joined: 06 Nov 2023, 10:24
Location: RU

Re: How to get weather on esp using API with key?

#3 Post by cccp79 » 06 Nov 2023, 11:50

Ok, thanks for link. Can such a task be solved by self-creating a plugin based on arduino codes, just for my needs? I want to try, learn how to create simple plugins according to the instructions.

TD-er
Core team member
Posts: 9581
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to get weather on esp using API with key?

#4 Post by TD-er » 22 Nov 2023, 13:19

Please note you cannot use HTTPS (with the S) in ESPEasy

cccp79
Normal user
Posts: 33
Joined: 06 Nov 2023, 10:24
Location: RU

Re: How to get weather on esp using API with key?

#5 Post by cccp79 » 27 Dec 2024, 13:06

Hello everyone I found a weather service that responds to http (without S) requests. Please tell me, which plugin can I use to send and receive an api request? Or is it possible only with the help of rules and Dummy Device?

User avatar
Ath
Normal user
Posts: 4151
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to get weather on esp using API with key?

#6 Post by Ath » 27 Dec 2024, 13:38

In general, ESPEasy does not supply any content when addressing a HTTP service, either via GET, POST or PUT. The only exception is when addressing a Thingspeak server via SendToHTTP, and the FEATURE_THINGSPEAK_EVENT is included in the build (any build without LIMIT_BUILD_SIZE set, so not available in ESP8266 builds 1M, Collection, Climate, Display, Energy or NeoPixel). By default this feature is enabled in ESP32 builds.
How to use that Thingspeak feature is documented in a SendToHTTP Rules example.

Other webservices are currently not (actively) supported.
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#7 Post by chromo23 » 27 Dec 2024, 19:06

cccp79 wrote: 27 Dec 2024, 13:06 Hello everyone I found a weather service that responds to http (without S) requests. Please tell me, which plugin can I use to send and receive an api request? Or is it possible only with the help of rules and Dummy Device?
Besides Thingspeak i also added a OpenWeatherMap and Open-Meteo support. I recommend Open-Meteo because it doesn’t require an API key. Both services support HTTP and are free to a certain extent.
I can support you with prebuilt binaries or you can use the branch of my fork to compile it yourself since it is not officially included into ESPEasy…

User avatar
Ath
Normal user
Posts: 4151
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to get weather on esp using API with key?

#8 Post by Ath » 28 Dec 2024, 11:00

chromo23 wrote: 27 Dec 2024, 19:06 Besides Thingspeak i also added a OpenWeatherMap and Open-Meteo support. I recommend Open-Meteo because it doesn’t require an API key. Both services support HTTP and are free to a certain extent.
I can support you with prebuilt binaries or you can use the branch of my fork to compile it yourself since it is not officially included into ESPEasy…
Maybe we should try to make this support more structural, so it's usable for everyone, except in the LIMIT_BUILD_SIZE builds for size reasons as it is already for Thingspeak support.

Please make a PR with your additional work :)
/Ton (PayPal.me)

cccp79
Normal user
Posts: 33
Joined: 06 Nov 2023, 10:24
Location: RU

Re: How to get weather on esp using API with key?

#9 Post by cccp79 » 28 Dec 2024, 13:43

Like @chromo23, I also need to receive data from weather services without having physical sensors. You can tell me, I can't figure it out. Where can I find either a binary with support for the services that @chromo23 made, or what is the name of the plugin and where can I find it? thank you in advance.

cccp79
Normal user
Posts: 33
Joined: 06 Nov 2023, 10:24
Location: RU

Re: How to get weather on esp using API with key?

#10 Post by cccp79 » 28 Dec 2024, 13:47

chromo23 wrote: 27 Dec 2024, 19:06
cccp79 wrote: 27 Dec 2024, 13:06 Hello everyone I found a weather service that responds to http (without S) requests. Please tell me, which plugin can I use to send and receive an api request? Or is it possible only with the help of rules and Dummy Device?
Besides Thingspeak i also added a OpenWeatherMap and Open-Meteo support. I recommend Open-Meteo because it doesn’t require an API key. Both services support HTTP and are free to a certain extent.
I can support you with prebuilt binaries or you can use the branch of my fork to compile it yourself since it is not officially included into ESPEasy…
Alternatively, can enable this service. weatherapi.com

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#11 Post by chromo23 » 29 Dec 2024, 15:35

Ath wrote: 28 Dec 2024, 11:00 Please make a PR with your additional work :)
I will do but it has to wait until next year. ;)
cccp79 wrote: 28 Dec 2024, 13:43 You can tell me, I can't figure it out. Where can I find either a binary with support for the services that @chromo23 made, or what is the name of the plugin and where can I find it? thank you in advance.
You have unfortunately also wait until next year for a binary. If you know how to build you own, you can find it here: https://github.com/chromoxdor/ESPEasy/t ... ther-event
Make sure to do a custom build with #define FEATURE_OMETEO_EVENT included in custom.h

cccp79 wrote: 28 Dec 2024, 13:47 Alternatively, can enable this service. weatherapi.com

Can you explain what makes this better than Open-Meteo?
The advantages of Open-Meteo are no API key and the only limit for the free version is the restriction to 10000 calls per day.
Open-Meteo also provides a nice website to "click together" you url depending on your needs (https://open-meteo.com/en/docs)

Rudy69
New user
Posts: 2
Joined: 20 Aug 2024, 19:08

Re: How to get weather on esp using API with key?

#12 Post by Rudy69 » 29 Dec 2024, 22:46

This is the workaround I use to get weather data
I have a router with openwrt installed, on which I have scheduled this command every 10':

Code: Select all

curl -q http://192.168.1.100/control?cmd=AsyncEvent,setOpenMeteo=$(curl 'api.open-meteo.com/v1/forecast?latitude=45.6789&longitude=9.8765&current=temperature_2m,precipitation,rain,precipitation_probability,snowfall,weather_code,cloud_cover,wind_speed_10m,wind_gusts_10m&timezone=auto&forecast_days=1' -s | jq -c '[.current | .temperature_2m,.precipitation,.rain,.precipitation_probability,.snowfall,.weather_code,.cloud_cover,.wind_speed_10m,.wind_gusts_10m]' | tr -d '[]')
then on the ESP module 192.168.1.100 I have this rule that writes the values ​​in 2 Dummy Device Quad

Code: Select all

on setOpenMeteo do 
  TaskValueSet 1,1,%eventvalue1%
   TaskValueSet 1,2,%eventvalue2%
    TaskValueSet 1,3,%eventvalue3%
     TaskValueSet 1,4,%eventvalue4%
     TaskValueSet 2,1,%eventvalue6%
    TaskValueSet 2,2,%eventvalue7%
   TaskValueSet 2,3,%eventvalue8%
  TaskValueSet 2,4,%eventvalue9%
Endon

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#13 Post by chromo23 » 02 Jan 2025, 21:45

cccp79 wrote: 28 Dec 2024, 13:43 Like @chromo23, I also need to receive data from weather services without having physical sensors. You can tell me, I can't figure it out. Where can I find either a binary with support for the services that @chromo23 made, or what is the name of the plugin and where can I find it? thank you in advance.
You can now download a binary here for testing: https://github.com/letscontrolit/ESPEas ... 2590203835
Edit: I totally forgot, that I disabled by default and it is only available for custom build where you have to enable it with "#define FEATURE_OPENMETEO_EVENT 1" when this is merged with ESPEasy. But write here what binary you need and i can build you one for testing.

Short description from the code:
Generate an event with the response of an open-meteo request.
No need for an api key and it is free (daily requests are limited to 10,000 in the free version).
Visit the URL (https://open-meteo.com/en/docs) and build your personal URL by selecting the location and values you want to receive.
Supported variable kinds are current, hourly, daily!
In rules you can grep the reply by the kind of weather variables with “On OpenMeteo# Do …”.
e.g. “On OpenMeteo#current Do …”.
Note: hourly and daily results are arrays which can become very long.
Best to make separate calls, especially for hourly results.


Short how-to:
1. visit https://open-meteo.com/en/docs
2. select in the side menu your topic (e.g. Weather Forecast, Marine Forcast, Air Quality)
3. click together what you need and scroll down to the API Response section where you find this:
openM.png
openM.png (27.88 KiB) Viewed 8192 times
(if you click on the "Open in new tab" you´ll get a preview with the data)

4. copy everything after "open-meteo.com"
5. use the copied part of the url with sendtohttp. example:`sendtohttp api.open-meteo.com,80,"/v1/forecast?..."` (make sure to use the quotes!)


Example:
Command:

Code: Select all

sendtohttp api.open-meteo.com,80,"/v1/forecast?latitude=52.5244&longitude=13.4105&current=temperature_2m,relative_humidity_2m&daily=temperature_2m_max,temperature_2m_min,uv_index_max&timezone=Europe%2FLondon&forecast_days=3"
Response:

Code: Select all

2580494: EVENT: OpenMeteo#current=4.3,76
2580503: EVENT: OpenMeteo#daily=7.5,2.4,1.2,1.5,-1.0,-1.1,1.00,0.95,0.70
As 'forecast_days' is set to 3, we have three values for each daily variable. As these are combined, we have nine event values.
"temperature_2m_max" can be accessed with %eventvalue1% - %eventvalue3%, "temperature_2m_min" with %eventvalue4% - %eventvalue6% and "uv_index_max" with %eventvalue7% - %eventvalue9%
Last edited by chromo23 on 03 Jan 2025, 09:54, edited 1 time in total.

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#14 Post by kniazio » 03 Jan 2025, 09:24

You can now download a binary here for testing: https://github.com/letscontrolit/ESPEas ... 2590203835
Should this work for esp32c6 as well? It doesn't work for me. Which version for esp32c6 should I choose from the above page?

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#15 Post by chromo23 » 03 Jan 2025, 09:49

kniazio wrote: 03 Jan 2025, 09:24 Should this work for esp32c6 as well? It doesn't work for me. Which version for esp32c6 should I choose from the above page?
Ohh sorry. That was not very smart of me. :roll:
The feature is only available in custom builds where you have to enable it by:

Code: Select all

#define FEATURE_OPENMETEO_EVENT         1
But i can build you a binary. What do you need?

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#16 Post by kniazio » 03 Jan 2025, 11:05

chromo23 wrote: 03 Jan 2025, 09:49
kniazio wrote: 03 Jan 2025, 09:24 Should this work for esp32c6 as well? It doesn't work for me. Which version for esp32c6 should I choose from the above page?
Ohh sorry. That was not very smart of me. :roll:
The feature is only available in custom builds where you have to enable it by:

Code: Select all

#define FEATURE_OPENMETEO_EVENT         1
But i can build you a binary. What do you need?
Actually, I need to use this function to get data from the inverter from the url:
192.168.1.199/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System
I need to do this on esp32c6
If possible.
If it is not possible, I would like a file for reading weather data.

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#17 Post by chromo23 » 03 Jan 2025, 11:16

kniazio wrote: 03 Jan 2025, 11:05 Actually, I need to use this function to get data from the inverter from the url:
192.168.1.199/solar_api/v1/GetInverterRealtimeData.cgi
The openmeteo-event is tailored to parse the JSON response of open-meteo.com
To parse the data of your inverter a new parser needs to be written.
Can you post the response of "192.168.1.199/solar_api/v1/GetInverterRealtimeData.cgi"
If it is not that complicated i could try to write one for you.
kniazio wrote: 03 Jan 2025, 11:05 If it is not possible, I would like a file for reading weather data.
The normal_ESP32c6_4M316k... ?

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#18 Post by kniazio » 03 Jan 2025, 11:31

chromo23 wrote: 03 Jan 2025, 11:16
kniazio wrote: 03 Jan 2025, 11:05 Actually, I need to use this function to get data from the inverter from the url:
192.168.1.199/solar_api/v1/GetInverterRealtimeData.cgi
The openmeteo-event is tailored to parse the JSON response of open-meteo.com
To parse the data of your inverter a new parser needs to be written.
Can you post the response of "192.168.1.199/solar_api/v1/GetInverterRealtimeData.cgi"
If it is not that complicated i could try to write one for you.
kniazio wrote: 03 Jan 2025, 11:05 If it is not possible, I would like a file for reading weather data.
The normal_ESP32c6_4M316k... ?
Yes, it is SeeedStudio 4MB. I will send the data from the inverter response later when I get back from work

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#19 Post by chromo23 » 03 Jan 2025, 11:42

kniazio wrote: 03 Jan 2025, 11:31 Yes, it is SeeedStudio 4MB. I will send the data from the inverter response later when I get back from work
esp32c34M_openmeteo.zip
(1.93 MiB) Downloaded 85 times

User avatar
Ath
Normal user
Posts: 4151
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to get weather on esp using API with key?

#20 Post by Ath » 03 Jan 2025, 12:01

chromo23 wrote: 03 Jan 2025, 11:42 esp32c34M_openmeteo.zip
The filename doesn't match the content, there is actually an ESP32-C6 build inside :?
/Ton (PayPal.me)

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#21 Post by kniazio » 03 Jan 2025, 12:03

chromo23 wrote: 03 Jan 2025, 11:42
kniazio wrote: 03 Jan 2025, 11:31 Yes, it is SeeedStudio 4MB. I will send the data from the inverter response later when I get back from work
esp32c34M_openmeteo.zip
Inverter inquiry:

Code: Select all

http://192.168.1.199/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System
Inverter Response:

Code: Select all

{
   "Body" : {
      "Data" : {
         "DAY_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 119
            }
         },
         "PAC" : {
            "Unit" : "W",
            "Values" : {
               "1" : 36
            }
         },
         "TOTAL_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 23161700
            }
         },
         "YEAR_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 10309
            }
         }
      }
   },
   "Head" : {
      "RequestArguments" : {
         "DeviceClass" : "Inverter",
         "Scope" : "System"
      },
      "Status" : {
         "Code" : 0,
         "Reason" : "",
         "UserMessage" : ""
      },
      "Timestamp" : "2025-01-03T12:03:38+01:00"
   }
}
Last edited by kniazio on 03 Jan 2025, 12:05, edited 1 time in total.

TD-er
Core team member
Posts: 9581
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to get weather on esp using API with key?

#22 Post by TD-er » 03 Jan 2025, 12:04

Looks a lot like the Victron plugin we recently added.
Only that is fetching data from serial.

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#23 Post by kniazio » 03 Jan 2025, 13:24

chromo23 wrote: 03 Jan 2025, 11:42
kniazio wrote: 03 Jan 2025, 11:31 Yes, it is SeeedStudio 4MB. I will send the data from the inverter response later when I get back from work
esp32c34M_openmeteo.zip
My module is esp32c6. Can I upload this file from c3 to my c6?

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#24 Post by chromo23 » 03 Jan 2025, 13:32

kniazio wrote: 03 Jan 2025, 13:24
chromo23 wrote: 03 Jan 2025, 11:42
kniazio wrote: 03 Jan 2025, 11:31 Yes, it is SeeedStudio 4MB. I will send the data from the inverter response later when I get back from work
esp32c34M_openmeteo.zip
My module is esp32c6. Can I upload this file from c3 to my c6?
unzip the file and you´ll see, that only the naming of the zip file i wrong ;)

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#25 Post by chromo23 » 03 Jan 2025, 13:43

kniazio wrote: 03 Jan 2025, 12:03 Inverter inquiry:
i´ll take a look at it.. it is simple enough :)
Ath wrote: 03 Jan 2025, 12:01 The filename doesn't match the content, there is actually an ESP32-C6 build inside
There are too many ESP32 around :D

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#26 Post by kniazio » 03 Jan 2025, 13:48

chromo23 wrote: 03 Jan 2025, 13:43
kniazio wrote: 03 Jan 2025, 12:03 Inverter inquiry:
i´ll take a look at it.. it is simple enough :)
Ath wrote: 03 Jan 2025, 12:01 The filename doesn't match the content, there is actually an ESP32-C6 build inside
There are too many ESP32 around :D
Thank you. I would be very grateful

User avatar
Ath
Normal user
Posts: 4151
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to get weather on esp using API with key?

#27 Post by Ath » 03 Jan 2025, 13:56

chromo23 wrote: 03 Jan 2025, 13:43 There are too many ESP32 around :D
And more are coming, P4, H2, C5, C61... not certain they will all be supported by ESPEasy soon, but probably, one day... :?
/Ton (PayPal.me)

TD-er
Core team member
Posts: 9581
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to get weather on esp using API with key?

#28 Post by TD-er » 03 Jan 2025, 14:02

Well C5 and C61 are not available yet, not even in test silicon (at least not to me yet...)
H2 and P4 are on my desk already, but I'm not sure if we will ever support the H2 as it does not have WiFi, only Zigbee/Thread.
Its only plus might be the low(er) power so it doesn't make sense to add Ethernet to it as it is then absolutely no low-power anymore.

The P4 also doesn't have WiFi, but it does have quite a lot other nice new features.
No idea when the final silicon will be available for the P4 as the one I have is a beta-version with known silicon bugs.

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#29 Post by chromo23 » 03 Jan 2025, 17:23

kniazio wrote: 03 Jan 2025, 13:48 Thank you. I would be very grateful
Can you test the builds? It checks if the URL ends with "GetInverterRealtimeData.cgi?Scope=System"
c6_4M_ometeo_inverter.zip
(1.93 MiB) Downloaded 88 times
Output should be something like:

Code: Select all

627408: Inverter: Day Energy: 119, PAC: 36, Total Energy: 23161700, Year Energy: 10309
627777: EVENT: InverterReply=119,36,23161700,10309
You catch it with:

Code: Select all

On InverterReply Do
 LogEntry,'Day Energy: %eventvalue1% Wh'
Endon

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#30 Post by kniazio » 03 Jan 2025, 17:37

chromo23 wrote: 03 Jan 2025, 17:23
kniazio wrote: 03 Jan 2025, 13:48 Thank you. I would be very grateful
Can you test the builds? It checks if the URL ends with "GetInverterRealtimeData.cgi?Scope=System"
c6_4M_ometeo_inverter.zip

Output should be something like:

Code: Select all

627408: Inverter: Day Energy: 119, PAC: 36, Total Energy: 23161700, Year Energy: 10309
627777: EVENT: InverterReply=119,36,23161700,10309
You catch it with:

Code: Select all

On InverterReply Do
 LogEntry,'Day Energy: %eventvalue1% Wh'
Endon

Code: Select all

SendToHTTP 192.168.1.199,80,"/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System"
>SendToHTTP 192.168.1.199,80,"/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System"
00:06:42.133 : (305024) Info   : Inverter: Day Energy: 172, PAC: 0, Total Energy: 23161700, Year Energy: 10361
It seems that everything is OK. Thank you very much. I will try to present it graphically now

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#31 Post by kniazio » 03 Jan 2025, 19:09

For now it looks like this:

Rules:

Code: Select all

on System#Boot do
  timerSet,1,60  // Ustaw timer na 60 sekund
endon

on Rules#Timer=1 do
  SendToHTTP 192.168.1.199,80,"/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System"
  timerSet,1,60  // Kolejny odczyt za 60 sekund
endon
on InverterReply do
  let,1,%eventvalue1% // Przypisz pierwszą wartość (DAY_ENERGY)
  let,2,%eventvalue2% // Przypisz drugą wartość (PAC)
  let,3,%eventvalue3% // Przypisz trzecią wartość (TOTAL_ENERGY)
  let,4,%eventvalue4% // Przypisz czwartą wartość (YEAR_ENERGY)

  taskvalueset,1,1,[VAR#1] // Przypisz do Dummy Device (pole 1)
  taskvalueset,1,2,[VAR#2] // Przypisz do Dummy Device (pole 2)
  taskvalueset,1,3,[VAR#3] // Przypisz do Dummy Device (pole 3)
  taskvalueset,1,4,[VAR#4] // Przypisz do Dummy Device (pole 4)

  logEntry,Dane falownika: DAY_ENERGY=[VAR#1] PAC=[VAR#2] TOTAL_ENERGY=[VAR#3] YEAR_ENERGY=[VAR#4]
endon
Thanks to: @chromo23
Attachments
inverter.jpg
inverter.jpg (160.91 KiB) Viewed 7979 times

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#32 Post by kniazio » 03 Jan 2025, 19:23

Variant2:

Rules:

Code: Select all

on System#Boot do
  timerSet,1,60  // Ustaw timer na 60 sekund
endon

on Rules#Timer=1 do
  SendToHTTP 192.168.1.199,80,"/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System"
  timerSet,1,60  // Kolejny odczyt za 60 sekund
endon
on InverterReply do
  let,1,%eventvalue1% // DAY_ENERGY (Wh)
  let,2,%eventvalue2% // PAC (W)
  let,3,%eventvalue3% // TOTAL_ENERGY (Wh)
  let,4,%eventvalue4% // YEAR_ENERGY (Wh)

  // Przelicz wartości na kWh
  let,5,[VAR#1]/1000 // DAY_ENERGY (kWh)
  let,6,[VAR#3]/1000 // TOTAL_ENERGY (kWh)
  let,7,[VAR#4]/1000 // YEAR_ENERGY (kWh)

  logEntry,Dzień (kWh)=[VAR#5] Całość (kWh)=[VAR#6] Rok (kWh)=[VAR#7]

  // Zapisz wartości do urządzenia Dummy Device (opcjonalne)
  taskvalueset,1,1,[VAR#5] // DAY_ENERGY (kWh)
  taskvalueset,1,2,[VAR#2] // PAC (W)
  taskvalueset,1,3,[VAR#6] // TOTAL_ENERGY (kWh)
  taskvalueset,1,4,[VAR#7] // YEAR_ENERGY (kWh)
endon
Attachments
inverter2.jpg
inverter2.jpg (159.25 KiB) Viewed 7973 times

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#33 Post by kniazio » 04 Jan 2025, 17:54

Fronius Inverter url-s
Attachments
fronius.rar
(596 Bytes) Downloaded 75 times

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#34 Post by chromo23 » 04 Jan 2025, 20:42

kniazio wrote: 04 Jan 2025, 17:54 Fronius Inverter url-s
I knew this would come so a made the parser more universal. :)

How-to:
1. add either #json or ?json to the end of the URL (either will always work) to tell ESPEasy that the response is in Json format.
example: SendToHTTP 192.168.1.199,80,"/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System?json"

2. create a file called json.keys and add the keys you want the values from (each key in an extra line):
example:

Code: Select all

Body.Data.DAY_ENERGY.Value
Body.Data.PAC.Value
3. upload the file

4. grep the data with "On JsonReply Do"


EXTRAS:
1. grouping or separate calls with different URLs.

- add a number to #json or ?json e.g.: SendToHTTP 192.168.1.199,80,"/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System?json1"
- add the number + ":" to the key you want to group:
example:

Code: Select all

1:Body.Data.DAY_ENERGY.Value
2:Body.Data.PAC.Value
- grep the data with "On JsonReply#<number> Do". e.g.:"On JsonReply#1 Do"

This way you can call more than one URL or put an array in a separate response, as the amount of eventvalues would probably be too long.
Rule example using %eventpar% to only have one rules block:

Code: Select all

On JsonReply* Do
  If %eventpar% = 1
   LogEntry,'%eventpar% 1: %eventvalue1% 2: %eventvalue2% 3: %eventvalue3%'
  Elseif  %eventpar% = 2
   LogEntry,'%eventpar% 1: %eventvalue1% 2: %eventvalue2% 3: %eventvalue3%'
  Endif
Endon

EDIT: When using groups in the key file but not adding a number at the end of the URL ALL keys will be parsed!

As requested per PM from @kniazio here the binary and a demo key file:
esp8266_4M_ometeo+jsonparser.zip
(634.23 KiB) Downloaded 75 times

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#35 Post by chromo23 » 04 Jan 2025, 20:57

kniazio wrote: 03 Jan 2025, 19:23Variant2:
I forgot to add the OpenMeteo event.
If you have already downloaded the file, please download it again.

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#36 Post by kniazio » 04 Jan 2025, 21:35

The values ​​are read but:
In the previous file if the parameter value was "0" it was displayed in the log (PAC example)
Now if the value is "0" it is not displayed in the log which causes the value in DummyDevice to shift
This is how it is currently:

Code: Select all

1536764: EVENT: http#192.168.1.199=200
1536769: EVENT: JsonReply=5360,23162302,10898
This is how it was in the previous version:

Code: Select all

1536764: EVENT: http#192.168.1.199=200
1536769: EVENT: InverterReply=5360,0,23162302,10898
Unless I don't understand something
serial_log:

Code: Select all

00:35:48.228 : (13408) Info   : Successfully processed 4 out of 4 keys
00:35:48.233 : (17080) Info   : ACT  : timerSet,1,60
00:35:48.240 : (17176) Info   : EVENT: http#192.168.1.199=200
00:35:48.245 : (17224) Info   : EVENT: JsonReply=5360,23162302,10898
It says that it successfully read 4 keys and the response is only 3. Because one of the keys is "0" (PAC)
PAC is the instantaneous value of the inverter power and at night it is "0". And not only at night.

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#37 Post by chromo23 » 04 Jan 2025, 21:58

kniazio wrote: 04 Jan 2025, 21:35 In the previous file if the parameter value was "0" it was displayed in the log (PAC example)
What does the output looks like in your browser when PAC is 0?

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#38 Post by kniazio » 04 Jan 2025, 22:04

chromo23 wrote: 04 Jan 2025, 21:58
kniazio wrote: 04 Jan 2025, 21:35 In the previous file if the parameter value was "0" it was displayed in the log (PAC example)
What does the output looks like in your browser when PAC is 0?

Code: Select all

{
   "Body" : {
      "Data" : {
         "DAY_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 536
            }
         },
         "PAC" : {
            "Unit" : "W",
            "Values" : {
               "1" : 0
            }
         },
         "TOTAL_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 23162302
            }
         },
         "YEAR_ENERGY" : {
            "Unit" : "Wh",
            "Values" : {
               "1" : 10898
            }
         }
      }
   },
   "Head" : {
      "RequestArguments" : {
         "DeviceClass" : "Inverter",
         "Scope" : "System"
      },
      "Status" : {
         "Code" : 0,
         "Reason" : "",
         "UserMessage" : ""
      },
      "Timestamp" : "2025-01-04T21:27:56+01:00"
   }
}
In the previous version for esp32c6 everything was OK
Attachments
fronius2.jpg
fronius2.jpg (21.08 KiB) Viewed 7772 times
Last edited by kniazio on 04 Jan 2025, 22:14, edited 1 time in total.

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#39 Post by chromo23 » 04 Jan 2025, 22:13

kniazio wrote: 04 Jan 2025, 22:04 In the previous version for esp32c6 everything was OK
A lot has changed since then. The only thing i can imagine it, that the key in the keyfile is not right. I´ll investigate...

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#40 Post by kniazio » 04 Jan 2025, 22:17

Code: Select all

Body.Data.DAY_ENERGY.Values.1
Body.Data.PAC.Values.1
Body.Data.TOTAL_ENERGY.Values.1
Body.Data.YEAR_ENERGY.Values.1

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#41 Post by chromo23 » 04 Jan 2025, 22:26

kniazio wrote: 04 Jan 2025, 22:17

Code: Select all

Body.Data.DAY_ENERGY.Values.1
Body.Data.PAC.Values.1
Body.Data.TOTAL_ENERGY.Values.1
Body.Data.YEAR_ENERGY.Values.1
I found it... need to update the code...


User avatar
Ath
Normal user
Posts: 4151
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to get weather on esp using API with key?

#43 Post by Ath » 04 Jan 2025, 22:42

I think you need to make an ESP32-C6 build...
/Ton (PayPal.me)

User avatar
chromo23
Normal user
Posts: 931
Joined: 10 Sep 2020, 16:02
Location: germany

Re: How to get weather on esp using API with key?

#44 Post by chromo23 » 04 Jan 2025, 22:46

Ath wrote: 04 Jan 2025, 22:42 I think you need to make an ESP32-C6 build...
chromo23 wrote: 04 Jan 2025, 20:42 As requested per PM from @kniazio here the binary and a demo key file:
There where things happening in the background... ;)

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#45 Post by kniazio » 04 Jan 2025, 22:56

chromo23 wrote: 04 Jan 2025, 22:35 Can you test this: ESP_Easy_mega_20250104_custom_274_ESP8266_4M1M.bin.zip
You are great. Everything is working as it should now.
Will there be the same compilation for esp32c6 someday?
Attachments
fronius3.jpg
fronius3.jpg (21.97 KiB) Viewed 7746 times

cccp79
Normal user
Posts: 33
Joined: 06 Nov 2023, 10:24
Location: RU

Re: How to get weather on esp using API with key?

#46 Post by cccp79 » 05 Jan 2025, 09:31

chromo23 wrote: 02 Jan 2025, 21:45
cccp79 wrote: 28 Dec 2024, 13:43 Like @chromo23, I also need to receive data from weather services without having physical sensors. You can tell me, I can't figure it out. Where can I find either a binary with support for the services that @chromo23 made, or what is the name of the plugin and where can I find it? thank you in advance.
You can now download a binary here for testing: https://github.com/letscontrolit/ESPEas ... 2590203835
Edit: I totally forgot, that I disabled by default and it is only available for custom build where you have to enable it with "#define FEATURE_OPENMETEO_EVENT 1" when this is merged with ESPEasy. But write here what binary you need and i can build you one for testing.

Short description from the code:
Generate an event with the response of an open-meteo request.
No need for an api key and it is free (daily requests are limited to 10,000 in the free version).
Visit the URL (https://open-meteo.com/en/docs) and build your personal URL by selecting the location and values you want to receive.
Supported variable kinds are current, hourly, daily!
In rules you can grep the reply by the kind of weather variables with “On OpenMeteo# Do …”.
e.g. “On OpenMeteo#current Do …”.
Note: hourly and daily results are arrays which can become very long.
Best to make separate calls, especially for hourly results.


Short how-to:
1. visit https://open-meteo.com/en/docs
2. select in the side menu your topic (e.g. Weather Forecast, Marine Forcast, Air Quality)
3. click together what you need and scroll down to the API Response section where you find this:
openM.png
(if you click on the "Open in new tab" you´ll get a preview with the data)

4. copy everything after "open-meteo.com"
5. use the copied part of the url with sendtohttp. example:`sendtohttp api.open-meteo.com,80,"/v1/forecast?..."` (make sure to use the quotes!)


Example:
Command:

Code: Select all

sendtohttp api.open-meteo.com,80,"/v1/forecast?latitude=52.5244&longitude=13.4105&current=temperature_2m,relative_humidity_2m&daily=temperature_2m_max,temperature_2m_min,uv_index_max&timezone=Europe%2FLondon&forecast_days=3"
Response:

Code: Select all

2580494: EVENT: OpenMeteo#current=4.3,76
2580503: EVENT: OpenMeteo#daily=7.5,2.4,1.2,1.5,-1.0,-1.1,1.00,0.95,0.70
As 'forecast_days' is set to 3, we have three values for each daily variable. As these are combined, we have nine event values.
"temperature_2m_max" can be accessed with %eventvalue1% - %eventvalue3%, "temperature_2m_min" with %eventvalue4% - %eventvalue6% and "uv_index_max" with %eventvalue7% - %eventvalue9%
Hi! Can you show me what a controller looks like in the web interface with "#define FEATURE_OPENMETEO_EVENT 1" enabled? I'm just trying to compile the firmware in PIO for my board and I don't understand what the end result should look like yet.

kniazio
Normal user
Posts: 104
Joined: 12 Jun 2016, 11:12

Re: How to get weather on esp using API with key?

#47 Post by kniazio » 05 Jan 2025, 09:58

You're probably going to yell at me.

I didn't expect to have so much data.

They won't fit on the SSD1306 display.

I'd like to display the data on the ILI934x/ILI948x TFT display but it's not on the list in my Wemos D1 Mini
I am very sorry for the confusion

Here are my data:
Attachments
fronius4.jpg
fronius4.jpg (51.79 KiB) Viewed 7663 times

cccp79
Normal user
Posts: 33
Joined: 06 Nov 2023, 10:24
Location: RU

Re: How to get weather on esp using API with key?

#48 Post by cccp79 » 05 Jan 2025, 12:55

Apparently, I did not understand something from the instructions (for some reason, I initially thought that this task was solved in the form of a plugin). I'm getting a response from OpenMeteo. But now I can't send the data to Dummy. Please help me. * I know that such API requests are for ESP32, but I managed to compile custom firmware for ESP-01S and now I want to try whether it will work or not. Don't swear too much)

Code: Select all

367384: ACT : sendtohttp api.open-meteo.com,80,'/v1/forecast?latitude=55.192375&longitude=37.786879¤t=temperature_2m,relative_hu
367548: EVENT: http#api.open-meteo.com=200
367552: EVENT: OpenMeteoReply=-4.3,82,-9.0,0.00,0.00,0.00,3,99,985.1,3.08,234

Code: Select all

On System#Boot do    
  timerSet,1,60     

On Rules#Timer=1 do  
  timerSet,1,60
  sendtohttp api.open-meteo.com,80,"/v1/forecast?latitude=55.192375&longitude=37.786879&current=temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,rain,snowfall,weather_code,cloud_cover,surface_pressure,wind_speed_10m,wind_direction_10m&wind_speed_unit=ms&timezone=Europe%2FMoscow&forecast_days=1"
Endon 

On OpenMeteo do

  let,1,%eventvalue1% 
  let,2,%eventvalue2% 
  let,3,%eventvalue3% 
  let,4,%eventvalue4%

  taskvalueset,1,1,[VAR#1] // Przypisz do Dummy Device (pole 1)
  taskvalueset,1,2,[VAR#2] // Przypisz do Dummy Device (pole 2)
  taskvalueset,1,3,[VAR#3] // Przypisz do Dummy Device (pole 3)
  taskvalueset,1,4,[VAR#4]
  
  LogEntry,'Values : Temp=[VAR#1] Hum=[VAR#2] Baro=[VAR#3] UV=[VAR#4]'

Endon
Attachments
2.png
2.png (43.28 KiB) Viewed 7637 times
1.png
1.png (39.74 KiB) Viewed 7637 times

User avatar
Ath
Normal user
Posts: 4151
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to get weather on esp using API with key?

#49 Post by Ath » 05 Jan 2025, 13:18

kniazio wrote: 05 Jan 2025, 09:58 I didn't expect to have so much data.

They won't fit on the SSD1306 display.

I'd like to display the data on the ILI934x/ILI948x TFT display but it's not on the list in my Wemos D1 Mini
That plugin (P095) has to be enabled separately.
A major difference between P036 (OledFramed) and other display plugins is that P036 has a paging feature, that can alternate all available lines in groups (pages), so all data can be viewed. And also a scrolling feature for when lines are too long to fit in the display width.
Depending on font size and rotation, quite some data can fit on a TFT display, but the font can be really small :shock:
/Ton (PayPal.me)

User avatar
Ath
Normal user
Posts: 4151
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to get weather on esp using API with key?

#50 Post by Ath » 05 Jan 2025, 13:22

cccp79 wrote: 05 Jan 2025, 12:55 Apparently, I did not understand something from the instructions
Not sure why you have your Dummy device connected to a remote unit (1)? Quite sure you didn't do that on purpose, as then the values will be transmitted from that unit if it's available in the P2P network. Set that option to 0 to have it work locally (as it was by default).
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests