Almost after 3 months from my last article about Weather Station project I finished next version of my weather station device code. The main goal for that version was to enable communication with HomeAssistant.
New version v3.0.0 has fixed some small bugs, but has one main feature. Now you are able to use HTTP or MQTT protocol to send your weather station data to server. As I mansion above I did that because I need send data to Home Assistant instance. Also another benefit of such change is that Weather Station device send data to MQTT server and it propagate it to all subscribers. So in that way I’m able to send data to Home Assistant and also to my own application where I store historical data. I don’t have made two different request, I don’t make different dependencies I just send data and forget about it.
Of course using any of above protocols checks if server response. If “No” it store data in local file, if “Yes” it sends data and all data stored in local file. The log file as previously can store up to 150 data records, after that it will remove the oldest one and add new one.
To all of those who would like to connect such device to Home Assistant I show below small configuration (sensors.yaml):
platform: mqtt
name: "Test Temp"
state_topic: "ws/00FF00_0/SENSOR"
unit_of_measurement: '°C'
value_template: "{{ value_json.payload.temp }}"
device_class: "temperature"
unique_id: "00FF00_temp"
force_update: trueplatform: mqtt
name: "Test Hum"
state_topic: "ws/00FF00_0/SENSOR"
unit_of_measurement: '%'
value_template: "{{ value_json.payload.hum }}"
device_class: "humidity"
unique_id: "00FF00_hum"
force_update: true
The most important things in that configuration is:
- unique_id – each device should have different one DEVICE_ID + SENSOR_TYPE
- state_topic – each device should have different, it is done on the Weather Station device code and is equal ws/DEVICE_ID + SENSOR_NUMBER/SENSOR (SENSOR_NUMBER – number of the sensor, possible values is 0 or 1)
If you have any questions about how the Weather Station works or how to connect it to Home Assistant please do not hesitate to contact me via email or in comments below.