Using the Ecowitt API to retrieve data from your Personal Weather Station (PWS)

I could not believe how hard it was to get data from my Personal Weather Station (PWS) into Home Assistant. The various API’s for Wunderground and Ecowitt refused to work for me. But I was looking at the Ecowitt page for my PWS and found that they had released an API which alows you to get data from their servers. See this page:
https://doc.ecowitt.net/web/#/apiv3en?page_id=1

Assuming you set up your PWS to send data to ecowitt,
1.look up your PWS MAC address from the wsview phone app from the Device List
2. create an application key and API key on the ecowitt platform

The following code retrieves all of the data available from my PWS. You might need to play with the API call on the resource line to see what is available to you.

Note the data is returned in Imperial units. there are API parameters to change the various units but they did not want to work for me so I did the conversion to metric units in the value_template. If you are using different units, be sure to adjust my settings.

#-----Ecowitt PWS via their API-----
  - platform: rest
    name: pws
    json_attributes:
      - code
      - data
      - msg
      - time
    resource: https://api.ecowitt.net/api/v3/device/real_time?application_key=XXXXXX&api_key=YYYYY&mac=AA:BB:CC:DD:EE:FF&call_back=all
    #scan_interval: 10
    method: GET
    value_template: "OK"    
  - platform: template
    sensors:
      pws_outdoor_temp:
        unit_of_measurement: 'ºC'
        value_template: '{{ ((states.sensor.pws.attributes.data.outdoor.temperature.value|float - 32) * 5 / 9)|round(1)}}'
      pws_dew_point:
        unit_of_measurement: 'ºC'
        value_template: '{{ ((states.sensor.pws.attributes.data.outdoor.dew_point.value|float - 32) * 5 / 9)|round(1)}}'
      pws_feels_like:
        unit_of_measurement: 'ºC'
        value_template: '{{ ((states.sensor.pws.attributes.data.outdoor.feels_like.value|float - 32) * 5 / 9)|round(1)}}'
      pws_outdoor_humidity:
        unit_of_measurement: '%'
        value_template: '{{ (states.sensor.pws.attributes.data.outdoor.humidity.value|float)|round(0)}}'
      pws_indoor_temp:
        unit_of_measurement: 'ºC'
        value_template: '{{ ((states.sensor.pws.attributes.data.indoor.temperature.value|float - 32) * 5 / 9)|round(1)}}'
      pws_indoor_humidity:
        unit_of_measurement: '%'
        value_template: '{{ (states.sensor.pws.attributes.data.indoor.humidity.value|float)|round(0)}}'
      pws_abs_pressure:
        unit_of_measurement: 'hPa'
        value_template: '{{ (states.sensor.pws.attributes.data.pressure.absolute.value|float * 33.863886666667)|round(1)}}'
      pws_rel_pressure:
        unit_of_measurement: 'hPa'
        value_template: '{{ (states.sensor.pws.attributes.data.pressure.relative.value|float * 33.863886666667)|round(1)}}'
      pws_hourly_rain:
        unit_of_measurement: 'mm'
        value_template: '{{ (states.sensor.pws.attributes.data.rainfall.hourly.value|float * 25.4)|round(0)}}'
      pws_daily_rain:
        unit_of_measurement: 'mm'
        value_template: '{{ (states.sensor.pws.attributes.data.rainfall.daily.value|float * 25.4)|round(0)}}'
      pws_weekly_rain:
        unit_of_measurement: 'mm'
        value_template: '{{ (states.sensor.pws.attributes.data.rainfall.weekly.value|float * 25.4)|round(0)}}'
      pws_monthly_rain:
        unit_of_measurement: 'mm'
        value_template: '{{ (states.sensor.pws.attributes.data.rainfall.monthly.value|float * 25.4)|round(0)}}'
      pws_yearly_rain:
        unit_of_measurement: 'mm'
        value_template: '{{ (states.sensor.pws.attributes.data.rainfall.yearly.value|float * 25.4)|round(0)}}'
      pws_rainfall_rate:
        unit_of_measurement: 'mm/h'
        value_template: '{{ (states.sensor.pws.attributes.data.rainfall.rain_rate.value|float * 25.4)|round(0)}}'
      pws_solar:
        unit_of_measurement: 'W/m2'
        value_template: '{{ (states.sensor.pws.attributes.data.solar_and_uvi.solar.value|float * 25.4)|round(0)}}'
      pws_uvi:
        unit_of_measurement: 'W/m2'
        value_template: '{{ (states.sensor.pws.attributes.data.solar_and_uvi.uvi.value|float)|round(0)}}'
      pws_wind_direction:
        unit_of_measurement: 'º'
        value_template: '{{ (states.sensor.pws.attributes.data.wind.wind_direction.value|float)|round(0)}}'
      pws_wind_gust:
        unit_of_measurement: 'km/h'
        value_template: '{{ (states.sensor.pws.attributes.data.wind.wind_gust.value|float * 1.609)|round(0)}}'
      pws_wind_speed:
        unit_of_measurement: 'km/h'
        value_template: '{{ (states.sensor.pws.attributes.data.wind.wind_speed.value|float * 1.609)|round(0)}}'

Enjoy!

If somebody can share how to install a really nice weather tile that uses this data, please let me know here.

2 Likes

Good to know how to access Ecowitt’s API.
However, have you tried the HACS custom component that allows for the weather station to push all data locally to Home Assistant. Probably took me less than 15 minutes to set all up.

There is also ecowitt2mqtt

1 Like

Yes, I tried it and another fork of it but they both were broken for me so I looked for another solution. I also tried my wunderground api but it failed too.

I did not know about ecowitt2mqtt. I’ll see if I can install the Docker image on my Synology NAS.

Is there any way to get the Dashboard ecowitt.net into Home Assistant?
Sure i can create an Webpage card but i have to insert login in the Card, and that don´t works.
There only flash the card, because i cant log in.

Any Idea?

Thanks

1 Like

Not that I know sorry… i just used an entity tile.

2 Likes

I’m surprised you had issues. I use the 1100 gateway and it’s been flawless. I wanted something similar to the old barometric gauges that predict weather. This is what I came up with. It’s still a work in progress as I dial in. The red and dark blue lines may get removed later but are helpful markers right now. Above the second dark blue line moving clockwise I have never had precipitation. Each red line as you move down counter clockwise the chance of rain increases. The label “Change” will read Storm, Rain, Change, Sunny, or Dry depending on the pressure.

weather

type: gauge
entity: sensor.absolute_pressure
needle: true
min: 942
max: 1050
segments:
  - from: 940
    color: '#765d91'
    label: Storm
  - from: 964
    color: '#543773'
    label: Rain
  - from: 979
    color: '#ff0000'
    label: Change
  - from: 980
    color: '#543773'
    label: Change
  - from: 982
    color: '#ff0000'
    label: Change
  - from: 983
    color: '#543773'
    label: Change
  - from: 985
    color: '#ff0000'
    label: Change
  - from: 986
    color: '#6cd1f0'
    label: Change
  - from: 988
    color: '#ff0000'
    label: Change
  - from: 989
    color: '#6cd1f0'
    label: Change
  - from: 991
    color: '#ff0000'
    label: Change
  - from: 992
    color: '#6cd1f0'
    label: Change
  - from: 994
    color: '#ff0000'
    label: Change
  - from: 995
    color: '#6cd1f0'
    label: Change
  - from: 1000
    color: '#080182'
    label: Change
  - from: 1001
    color: '#6cd1f0'
    label: Change
  - from: 1003
    color: '#080182'
    label: Change
  - from: 1004
    color: '#6cd1f0'
    label: Change
  - from: 1014
    color: '#f5f176'
    label: Sunny
  - from: 1040
    color: '#fa7f41'
    label: Dry
unit: mb


I tried the new ecowitt module since its been added to the HA core and it still fails for me so this API is still my solution. It has been flawless.

1 Like

When you set up the gateway did you use a local IP address? You don’t want it to have to leave your network and try to make a round trip back in. Port 4199 might get blocked or redirected traversing NAT. I’m not sure if the Ecowhitt device can interpret mDNS either so I would stick with an IP. Personally I prefer avoiding the cloud. I like that the device speaks directly to HA.

Thats all very well if the device speaks to HA but it doesn’t I tried again several times.
The integration says to use data similar to this. The web hook changes every time the integration setup is selected.

Server IP: 192.168.1.29
Path: /api/webhook/f796e0a72913a097455e7d4ab7adxxxx
Port: 8123

So far the external API has been bulletproof. It uses https so no issues with ports.

1 Like

You don’t need to create a webhook to use the integration and you use the port the integration exposes instead of the HA port. I believe the port is always 4199 by default. We must be using different integrations or different versions.

hmm,
there is something going on. This is what I get when installing the integration after a reboot

I can’t see there is anything to uninstall from the past. I dug around some folders
Using 2022.9.1 cos I get an error if I update but thats another story
2022-09-27 19:44:58.491 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547269756480] Error updating Home Assistant Core 'HomeAssistantCore.update' blocked from execution, system is not healthy

SO I tried using the different settings from the screendump above. The integration failed with an error.
In the log I get.

2022-09-27 19:36:26.017 INFO (SyncWorker_1) [homeassistant.loader] Loaded ecowitt from homeassistant.components.ecowitt
2022-09-27 19:38:13.292 INFO (MainThread) [homeassistant.setup] Setting up ecowitt
2022-09-27 19:38:13.293 INFO (MainThread) [homeassistant.setup] Setup of domain ecowitt took 0.0 seconds
2022-09-27 19:38:13.299 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.ecowitt
2022-09-27 19:38:13.302 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.ecowitt
2022-09-27 19:51:47.664 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.ecowitt
2022-09-27 19:51:47.666 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.ecowitt
2022-09-27 19:51:47.670 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Ecowitt for ecowitt
File "/usr/src/homeassistant/homeassistant/components/ecowitt/__init__.py", line 29, in async_setup_entry

Any ideas? I am quite a noob so don’t really know how to clean up errors.

1 Like

That line just points to code that tries to register the new webhook internally, which then apparently fails without giving any reason.
Are there any other error messages in your log, maybe related to setting up webhooks?

1 Like

yeh I saw that. I can’t access that folder.
When I walk the folders one by one, this one is not found in the terminal
/usr/src/homeassistant

I must need root access and I can’t use sudo or su either.

This is where we have to ask questions like how you have HA installed.

Tell us how you installed Home Assistant

Tell us if you’re running Hass.io 199 using an official HassOS image, a Docker install, Hassbian, a venv install, and so on. Things that are often really useful to know include:

What version number of Home Assistant are you running?
How you installed it. If you’re not using Hassbian or a HassOS based 

Hass.io 199 install, remember to tell us the operating system
Any relevant code - correctly formatted

For example:

Home Assistant 0.42.0 using Hass.io 199 with the HassOS image
Home Assistant 0.84.2 in a venv following this guide 13 on Windows 10
Home Assistant 0.90.2 using Hass.io 199 on Ubuntu 18.04 following this guide 23

Please remember that words like latest, current, newest and so on are not version numbers.

Thanks, I’m using the raspberry pi (4b) version of the Home assistant OS.
Version is 2022.9.1
I am stuck there and can’t upgrade further becasue of

[547453715456] Error updating Home Assistant Core 'HomeAssistantCore.update' blocked from execution, system is not healthy
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/hassio/update.py", line 299, in async_install
    await async_update_core(self.hass, version=version, backup=backup)
  File "/usr/src/homeassistant/homeassistant/components/hassio/handler.py", line 45, in _wrapper
    raise HassioAPIError(data["message"])
homeassistant.components.hassio.handler.HassioAPIError: 'HomeAssistantCore.update' blocked from execution, system is not healthy

Seems to be trying to access the same folder

1 Like

Assuming you didn’t change anything in the file system yourself I can’t help but wonder if this is an issue created by failing storage. Are you using an SD card? SD cards give a poorer user experience. I use an inexpensive SSD and a SATA adapter on most of my full size PI boards.

I would definitely make sure I created a backup. Save that backup and a couple of the earlier backups on a different device if you haven’t done so. I make sure the file size matches when manually downloading a backup. You can also open the backup with WinRAR, Winzip, or whatever you like to verify you downloaded the whole file. It may sound paranoid but I have had issues with partial downloads using the manual backup download interface.

hassip:8123//hassio/backups or Settings >> System >> Backups

Then I would consider creating a fresh install on a different storage device if possible. Use the backup to do a restore. I suspect that would eliminate the errors.

Thanks, I doubt its a hardware issue. I solved my upgrade issue

so am now finally running 2022.9.7.
I went and had a look at HACS and deleted a ecowitt repo there, restarted and tried again.
It still showed me webhook info which I entered on the phone app.
Nothing works.
There are a number of people with the same problem on the ecowitt github issues.
I think I will call it a day.
I might try mqtt one day but its not a high priority.

1 Like