Background
If you are coming from the Handling data from Ambient Weather WS-2902C API to MQTT post, you are ready to proceed! If not, you’ll need to follow the steps in that post to get your Ambient Weather WS-2902C data into MQTT.
In short, we set up a Python script that listens on port 80 for data coming from the Ambient Weather base station. It then takes the data and publishes it to various MQTT topics. We can subscribe to those topics to receive new data as soon as it arrives.
Available Data
I’ll re-post the list of available data/topics from my last post:
Topic | Value | Comment |
weather/ws-2902c/PASSKEY | aa:bb:cc:dd:ee:ff | MAC address |
weather/ws-2902c/dateutc | 5/15/2021 | date |
weather/ws-2902c/tempinf | 70.7 | temp at the base station |
weather/ws-2902c/humidityin | 36 | humidity at the base station |
weather/ws-2902c/baromrelin | 29.675 | adjusted barometric pressure (in Hg) |
weather/ws-2902c/baromabsin | 24.531 | absolute barometric pressure (in Hg) |
weather/ws-2902c/tempf | 66.2 | temp at the weather station |
weather/ws-2902c/battout | 1 | battery status at the weather station? |
weather/ws-2902c/humidity | 26 | humidity at the weather station |
weather/ws-2902c/winddir | 207 | wind direction in degrees azimuth |
weather/ws-2902c/windspeedmph | 0.2 | wind speed |
weather/ws-2902c/windgustmph | 1.1 | wind gust (shows peaks between updates) |
weather/ws-2902c/maxdailygust | 3.4 | max daily wind gust |
weather/ws-2902c/hourlyrainin | 0 | hourly rain fall |
weather/ws-2902c/eventrainin | 0 | event rain fall (resets after 24 hours of no rain) |
weather/ws-2902c/dailyrainin | 0 | daily rain fall |
weather/ws-2902c/weeklyrainin | 0 | weekly rain fall |
weather/ws-2902c/monthlyrainin | 0 | monthly rain fall |
weather/ws-2902c/totalrainin | 0 | total rain fall since power on? |
weather/ws-2902c/solarradiation | 697.92 | solar radiation in watts per square meter |
weather/ws-2902c/uv | 6 | UV intensity index |
weather/ws-2902c/batt_co2 | 1 | ? |
This is a lot of data. How much/little you want to use is up to you! I believe I added every topic to my Home Assistant so they’d would be available if I ever wanted to use them.
Adding the MQTT topics to Home Assistant
If you don’t have the MQTT line in your base configuration, make sure you add it. I also am using secrets here so it goes and grabs the broker IP address from my secrets file.
For my configuration.yaml file, showing the relevant lines (MQTT sensors and the sensor file)
homeassistant@ha-new:~/.homeassistant$ cat configuration.yaml mqtt: broker: !secret mqtt_broker sensor: !include sensor.yaml
For the secrets.yaml file:
homeassistant@ha-new:~/.homeassistant$ cat secrets.yaml mqtt_broker: mqtt.home.fluffnet.net
The way the secrets file works means it looks like this in configuration.yaml:
mqtt: broker: mqtt.home.fluffnet.net
If you haven’t worked with .yaml in Home Assistant before, it is very picky about spacing. Ensure the spacing is correct (usually 2 spaces per indentation).
With the MQTT line added, we can turn to the sensors file (sensors.yaml). This is where the magic happens! I’ve only added a subset of the topics:
homeassistant@ha-new:~/.homeassistant$ cat sensor.yaml [snip non-ambient weather sensors] - platform: mqtt state_topic: "weather/ws-2902c/tempinf" name: "real kitchen temp" unit_of_measurement: "F" - platform: mqtt state_topic: "weather/ws-2902c/tempf" name: "real outside temp" unit_of_measurement: "F" - platform: mqtt state_topic: "weather/ws-2902c/humidityin" name: "real kitchen hum" unit_of_measurement: "%" - platform: mqtt state_topic: "weather/ws-2902c/humidity" name: "real outside hum" unit_of_measurement: "%" - platform: mqtt state_topic: "weather/ws-2902c/solarradiation" name: "solar radiation" unit_of_measurement: "W/m2" - platform: mqtt state_topic: "weather/ws-2902c/dailyrainin" name: "daily rain" unit_of_measurement: "in" - platform: mqtt state_topic: "weather/ws-2902c/windspeedmph" name: "wind speed" unit_of_measurement: "mph" - platform: mqtt state_topic: "weather/ws-2902c/windgustmph" name: "wind gust" unit_of_measurement: "mph"
Restarting Home Assistant
With those lines added to the sensor.yaml file, restart Home Assistant. I love Home Assistant but needing to restart it for basically any configuration change is a huge pain.
sudo systemctl restart [email protected]
Adding the new Ambient Weather WS-2902C sensors to your Home Assistant screens
With the new sensors activated, you can add them to any of your Home Assistant pages!
First click the edit button then Add Card:
Next up we need to select what kind of card we want to add. For most of these, they’re time series, so History Graph will be the best choice. I do not know why Home Assistant is recommending the sun position in this screenshot.
Now that the History Graph is selected, we can pick any of the new sensors we added in the entity drop down. In this screenshot we see most of what I added. The others are sorted elsewhere (there are 100+ entities available in my entities drop down).
With sensor.real_outside_temp selected, I added 60 for the refresh interval, which means the graph will refresh itself every 60 seconds.
Now the graph is added to the page! You can repeat with all the other sensors you want to view. In the below screenshot, we have successfully added the outside temperature from the Ambient Weather WS-2902C to Home Assistant.
My full weather tab
I’ve added a number of sensors from my Ambient Weather WS-2902C to my Home Assistant. Below you can see I have solar radiation, daily rain, real outside humidity, real outside temp (I have another sensor labeled “outdoor temp” that is a floating sensor that is no longer outdoors), and the wind data. I also have the badges up top with just the current numeric value. You can add more or less, it’s totally up to you!
Conclusion
With this series, we have connected the Ambient Weather WS-2902C to our own Linux container to read the data, publish it to MQTT, and then view it in Home Assistant. I hope you’ve found this helpful!