Adding a Bresser 5 in 1 sensor to Home Assistant |
||||||||
|
||||||||
|
|
|||||||
Adding a Bresser 5 in 1 sensor to Home AssistantAs part of an ongoing home automation project I want to have my own weather station and use it in Home Assistant. Hardware
After some asking around I was told that the Bresser 5-in-1 would be a good choice. This sensor comes in several flavours, that only differ in functionality of the base station. Since I had no intentions of using the base station much, I ordered the cheapest flavour I could find from Amazon. The sensor is called 5 in 1 since it has 5 sensor functions: temperature, humidity, wind, rain and pressure. However, the pressure is not measured by the sensor, but by the base station. There are newer models, the 6 in 1, that also measures the amount of ultra-violet light, and the 7 in 1 that also measures the amount of light. This article is based on an 5 in 1, but almost everything applies to the other models too.
The sensor transmits the data via a radio signal. I purchased this USB2.0 DAB FM Radio DVB-T RTL2832U R820T2 RTL SDR TV Stick Dongle Digital USB TV HDTV Tuner Receiver IR Remote with Antenna from Ali Express. It has a Rafael Micro r820t chip that is known to work fine with most systems.
Never mind the CD and remote, I am not going to use it. Warning: This dongle draws about 250mA. If you are going to plug it in a RaspberryPi make sure your power supply is sufficient. Note: While this dongle works, it is “[…] misusing a broadband FM
device for listening for a couple of bits. It's like driving a semi
truck to the grocery store and wondering about fuel economy.”
As may be expected, the sensor works out of the box after inserting the batteries in both the sensor and the base station. Softwarertl_433To use the dongle there is a nifty tool called rtl_433. It is a general purpose digital radio receiver that, despite the name, can receive almost all frequency bands that are in use for digital communication. To get this tool see GitHub. The tool needs to be told what frequency to receive. The Bresser 5-in-1 sensor uses a frequency of 868.30Mhz. And it is dead simple. I inserted the dongle in my (linux) PC and started the tool: rtl_433 -c /dev/null -f 868.3M And lo and behold! After a couple of seconds it reported: time : 2022-05-30 21:01:39 model : Bresser-6in1 id : 14100077 channel : 0 Battery : 1 Temperature: 14.5 C Humidity : 61 Sensor type: 1 Wind Gust : 0.0 m/s Wind Speed: 0.0 m/s Direction : 90 UV : 0.0 Flags : 0 Integrity : CRC Wow, this went fast. This is really a nifty tool. One of the first things to remark is that this Bresser 5-in-1 reports itself as speaking the newer 6-in-1 protocol. Good. So there's a bogus UV value included. Battery value 1 means the batteries are still good. Channel, sensor type, flags and integrity have a purpose but not as far as I'm concerned. The other measurements are familiar: temperature (in degrees Celcius), humidity (in percent), wind gust and (average) speed (in meters/second) and wind direction (in degrees). The values are reported periodically, once per 12 seconds according to the rtl_433 docs but often it may take longer. Note that the wind direction is reported in 16 discrete steps: 0
(N), 22, 45, 68, 90 (E), 112, 135, 158, 180 (S), 202, 225, 248, 270
(W), 292, 315, and 338.
If you have a 6-in-1 sensor there is also an ultra-violet value, a floating point number. The 7-in-1 sensor reports the light value in both lux and kilolux. rtl_433 is capable of sending the information to an MQTT server where Home Assistant can pick it up. This led to the following configuration for rtl_443: gain 0 frequency 868.30M ppm_error 0 report_meta time:tz protocol 172 # Bresser Weather Center 6-in-1 (newer 5-in-1) protocol 173 # Bresser Weather Center 7-in-1 output mqtt=http://my mqtt server,retain=1,devices=rtl_433/bresser51 After restarting rtl_433 I could see the messages flowing in using MQTT Explorer. Home Assistant SensorsIn Home Assistant I defined a new package file bresser51.yaml (Full info at end.) The basic definition for each of the sensor values is: sensor: - platform: mqtt name: Bresser51 Temperature state_topic: rtl_433/bresser51/temperature_C unique_id: bresser51_temperature_C unit_of_measurement: "°C" device_class: temperature For the battery status I used a binary sensor: binary_sensor: - platform: mqtt name: Bresser51 Battery state_topic: rtl_433/bresser51/battery_ok unique_id: bresser51_battery_ok payload_on: "0" payload_off: "1" device_class: battery Note that for the battery class, on means that the batteries are low and must be replaced. To get a nice, symbolic name for the wind direction I added a template sensor: template: sensor: # Map heading in degrees to symbolic name. # Note that the bresser sensor returns discrete values! # 0 22 45 68 90 112 135 158 180 202 225 248 270 292 315 338 360 - name: Bresser51 Wind Direction Name icon: mdi:compass-rose state: | {%- set dir = states('sensor.bresser51_wind_direction') | float -%} {% set names = "N NNO NO ONO O OZO ZO ZZO Z ZZW ZW WZW W WNW NW NNW N".split() %} {{ names[( dir / 22 ) | int ] }} For the rain meter I added statistical sensors. sensor: - name: Bresser51 Rain 1H platform: statistics unique_id: bresser51_rain_1h entity_id: sensor.bresser51_rain sampling_size: 200 state_characteristic: change max_age: hours: 1 Similar for 24 hours and 7 days (168 hours). The Bresser 5-in-1 reports max. 6 times per minute, so the sampling size should be chosen sufficiently large to hold all the samples for the desired period. But… It turns out that statistics sensors, while doing a great job in most cases, are less suitable for this purpose. Consider the situation that the accumulated amount of rain is 50mm at 10:00 yesterday, 60mm at 06:00 today. Niw it is 08:00. The statistics sensor will report the difference between the current value, 60mm, and the first reading within the 24-hour interval, which is also 60. So it reports zero. For all practical purposes, it should report 10mm, since the value 24 hours ago was 50mm. So a better approach is to use an SQL sensor to retrieve the last value before the interval and use that instead of the first value in the interval. sensor: - platform: sql db_url: !secret recorder_db queries: - name: Bresser51 DB Rain 1H query: >- SELECT * FROM states WHERE entity_id = 'sensor.bresser51_rain' AND last_updated < CURRENT_TIMESTAMP - INTERVAL '1 hour' ORDER BY last_updated DESC LIMIT 1; column: state unit_of_measurement: mm Unfortunately the Home Assistant developers decided to remove the possibility to define an SQL sensor using YAML, so it must be done now, tediously and prone to errors, via the UI. LovelaceFull data at end. I use an entities card for most purposes. I use a custom:multiple-entity-row to combine temperature and humidity, and I do the same with wind gust, average and direction. - type: entities title: Weerstation state_color: true entities: - entity: sensor.bresser51_temperature type: custom:multiple-entity-row name: Temperatuur icon: mdi:thermometer show_state: false entities: - entity: sensor.bresser51_temperature name: false - entity: sensor.bresser51_humidity name: false Since I do not have values for the air pressure, this is measured by the base station, I 'borrow' this from weather.openweathermap. - entity: weather.openweathermap icon: mdi:gauge type: custom:template-entity-row name: Barometer state: > {{ state_attr('weather.openweathermap','pressure') }} hPa Finally, I suppress the battery state if it is normal. - type: conditional conditions: - entity: binary_sensor.bresser51_battery state: "on" row: entity: binary_sensor.bresser51_battery show_active: true name: Batterij The final result. Well, for now.
Appendices.homeassistant/packages/bresser51.yaml.homeassistant/dashboards/default.yaml (section)views: - cards: - type: entities title: Weerstation state_color: true entities: - entity: sensor.bresser51_temperature type: custom:multiple-entity-row name: Temperatuur icon: mdi:thermometer show_state: false entities: - entity: sensor.bresser51_temperature name: false - entity: sensor.bresser51_humidity name: false - entity: weather.openweathermap icon: mdi:gauge type: custom:template-entity-row name: Barometer state: > {{ state_attr('weather.openweathermap','pressure') }} hPa - entity: sensor.bresser51_wind_speed type: custom:multiple-entity-row name: Wind icon: mdi:weather-windy show_state: false secondary_info: entity: sensor.bresser51_wind_direction_name name: false entities: - entity: sensor.bresser51_wind_gust name: vlaag unit: false - entity: sensor.bresser51_wind_speed name: gem. - entity: sensor.bresser51_wind_beaufort name: Bft unit: false - entity: sensor.bresser51_rain type: custom:multiple-entity-row name: Neerslag show_state: false secondary_info: entity: sensor.bresser51_rain name: false entities: - entity: sensor.bresser51_rain_168h name: 168u hide_unavailable: true hide_if: 0 - entity: sensor.bresser51_rain_24h name: 24u hide_unavailable: true hide_if: 0 - entity: sensor.bresser51_rain_1h name: uur hide_unavailable: true hide_if: 0 - type: conditional conditions: - entity: binary_sensor.bresser51_battery state: "on" row: entity: binary_sensor.bresser51_battery show_active: true name: Batterij It may be worth investigating a compass card, e.g. custom:compass-card. - type: custom:compass-card header: false language: nl indicator_sensors: - sensor: sensor.bresser51_wind_direction indicator: type: arrow_inward value_sensors: - sensor: sensor.bresser51_wind_beaufort A full dashboard with everything. .config/rtl_433/rtl_433.confgain 0 frequency 868.30M ppm_error 0 report_meta time:tz protocol 172 # Bresser Weather Center 6-in-1 (newer 5-in-1) protocol 173 # Bresser Weather Center 7-in-1 output mqtt=http://mqtt.squirrel.nl,retain=1,devices=rtl_433/bresser51 Don't bother trying to get to mqtt.squirrel.nl. It is a LAN host. /etc/systemd/system/rtl433.service[Unit] Description=RTL 433 Receiver After=network-online.target Wants=network-online.target Before= [Service] User=jv Environment="PATH=/usr/bin:/sbin" ExecStart=/usr/bin/rtl_433 -c /home/jv/.config/rtl_433/rtl_433.conf Restart=always RestartSec=60s [Install] WantedBy=multi-user.target |
||||||||
|
|
|||||||
© Copyright 2003-2023 Johan Vromans. All Rights Reserved. |