I wanted to build a simple Zigbee based weather station with easily available components.
Hardware:
The CC2530 Zigbee device:
CC2530
BME280 for temperature, humidity & pressure:
bme280
Rain sensor: This device has a clever tipping device and just a simple reed switch:
Rain
Anemometer: This device also has one reed switch!
Anemometer
Hardware wiring:
The wiring of the four components is very simple:
CC2530 Firmware:
The CC2530 need to be programmed. The CC2530 module is flashed with the great PTVO configurable firmware (https://ptvo.info/zigbee-switch-configurable-firmware-v2-210/ 382). Flashing is done with the CC debugger and the free software from TI (FLASH-PROGRAMMER Software programming tool | TI.com 120) not V2.
The settings for the weather station are:
BME280: I just followed the instructions from PTVO on how to connect I2C devices: I2C
For some BME280 devices the address is 119. Try this if 118 does not work,
The Rain reed switch. This reed switch is connected to P05 (Pull-up) so by connecting it to ground the reed is switching P21 on/off. Switch 5 will appear in HA. I used 0.30303mm per switch on/off in the template sensor (see below).
Anemometer reed switch.
For the anemometer we could in theory use the same set-up as for the rain reed. But that causes problems later on. This anemometer reed switches on and off with a frequency of 0-50 Hz in most of the time. When I tried to calculate the wind speed in HA the processor use went up from 10 to 80%. Long story don’t try to copy this. A more elegant solution is available by using the internal clock : Clock.
The Anemometer reed switch is connected to P07. This port when low is starting the counter. With the applied settings the on/off signal from the reed is added up during 60 seconds. Minor bleeps of less than 10 useconds are ignored. As a result sensor L6 which will appear in HA and is refreshed every minute with the count of the Anemometer reed switch. When the reed goes from on to off it generates 2 counts.
One turn is r * 2 * Pi = 0,09 m * 2 * 3.14 = 0,5652 m, Since one turn generate 2 clicks 0,5652 needs to be divided by 2 = 0,2862. This calculation is performed in a template sensor below.
Home assistant integration
Flash CC2530, connect the wires, apply 3,3 V and the data from the CC2530 will appear in HA via zigbee2mqtt. In order to have the values visible in sensors, you need this yaml:
As you can see, in my case the friendly name of the CC2530 is : 0x00124b000633d676.
#########################################################
# #
# BME280 DATA #
# #
#########################################################
- platform: mqtt
name: "Humidity shed"
state_topic: "zigbee2mqtt/0x00124b000633d676"
unit_of_measurement: "%"
value_template: "{{ value_json.humidity_l1| round(0) }}"
availability_topic: "zigbee2mqtt/bridge/state"
payload_available: "online"
payload_not_available: "offline"
json_attributes_topic: "zigbee2mqtt/0x00124b000633d676/attributes"
icon: mdi:water-percent
- platform: mqtt
name: "Pressure shed"
state_topic: "zigbee2mqtt/0x00124b000633d676"
unit_of_measurement: "hpa"
value_template: "{{ ((value_json.pressure_l1| float /100 ) | round (0)) }}"
availability_topic: "zigbee2mqtt/bridge/state"
payload_available: "online"
payload_not_available: "offline"
json_attributes_topic: "zigbee2mqtt/0x00124b000633d676/attributes"
icon: mdi:weight
- platform: mqtt
name: "Temperature shed"
state_topic: "zigbee2mqtt/0x00124b000633d676"
unit_of_measurement: "°C"
value_template: "{{ value_json.temperature_l1| round(1) }}"
availability_topic: "zigbee2mqtt/bridge/state"
payload_available: "online"
payload_not_available: "offline"
json_attributes_topic: "zigbee2mqtt/0x00124b000633d676/attributes"
icon: mdi:thermometer-lines
- platform: template
sensors:
humidity_abs_shed:
value_template: >-
{% set h, t = states('sensor.humidity_shed') | float, states('sensor.temperature_shed') %}
{% if not h or t == 'unknown' -%}
'unknown'
{%- else %}
{% set t = t | float %}
{{ (h*6.112*2.1674*e**((t*17.67)/(t+243.5))/(t+273.15))|round(1) }}
{% endif %}
unit_of_measurement: g/m³
friendly_name: Absolute Humidity shed
- platform: template
sensors:
dewpoint_shed:
friendly_name: "Dewpoint shed"
value_template: >-
{{ (log( states('sensor.humidity_shed')|int / 100 ) + 18.678 * states('sensor.temperature_shed')|float / (257.14 + states('sensor.temperature_shed')|float ) )| round (1) }}
unit_of_measurement: °C
#########################################################
# #
# RAIN METER #
# #
#########################################################
- platform: history_stats
name: Daily rain clicks
entity_id: switch.0x00124b000633d676_l5
state: 'off'
type: count
start: '{{ now().replace(hour=0, minute=0, second=0) }}'
end: '{{ now() }}'
- platform: template
sensors:
rainfall_today:
friendly_name: Rainfall today
unit_of_measurement: mm
value_template: >-
{% set count = states('sensor.daily_rain_clicks') | int %}
{% set mm_per_pulse = 0.30303 %}
{% set mm = count * mm_per_pulse %}
{{ mm|round(1, 'floor') }}
#########################################################
# #
# ANEMOMETER #
# #
#########################################################
- platform: template
sensors:
windspeed:
friendly_name: Wind speed
unit_of_measurement: m/s
# m_per_pulse = (r * 2 * Pi)/2 = (0.09 * 2 * 3.14)/2 = 0.2862 m
value_template: >-
{% set count = states('sensor.0x00124b000633d676_l6') | int %}
{% set m_per_pulse = 0.2826 %}
{% set mps = count * m_per_pulse %}
{{ mps|round(1) }}
- platform: template
sensors:
windforce:
friendly_name: Wind force
icon_template: " mdi:weather-windy"
value_template: "{% set wind = states('sensor.windspeed')|float %}
{% set wind_round = wind|round(1) %}
{% if wind <= 1 %}Bft: 0, Wind stil, {{wind_round}} m/s
{% elif wind <= 5 %}Bft: 1
, Zwak: flauwe wind, {{wind_round}} m/s
{% elif wind <= 11 %}Bft: 2, Zwak, {{wind_round}} m/s
{% elif wind <= 20 %}Bft: 3, Matig: lichte bries, {{wind_round}} m/s
{% elif wind <= 28 %}Bft: 4, Matig: flauwe bries, {{wind_round}} m/s
{% elif wind <= 39 %}Bft: 5, Vrij krachtig, {{wind_round}} m/s
{% elif wind <= 50 %}Bft: 6, Krachtig, {{wind_round}} m/s
{% elif wind <= 62 %}Bft: 7, Hard, {{wind_round}} m/s
{% elif wind <= 75 %}Bft: 8, Stormachting, {{wind_round}} m/s
{% elif wind <= 89 %}Bft: 9, Storm, {{wind_round}} m/s
{% elif wind <= 103 %}Bft: 10, Zware storm, {{wind_round}} m/s
{% elif wind <= 117 %}Bft: 11, Zeer zware storm, {{wind_round}} m/s
{% else %} > 117 %}Bft: 12, Orkaan, {{wind_round}} m/s
{%- endif %}"
- platform: template
sensors:
beaufort:
friendly_name: Beaufort
value_template: "{% set wind = states('sensor.windspeed')|float %}
{% if wind <= 1 %}0
{% elif wind <= 5 %}1
{% elif wind <= 11 %}2
{% elif wind <= 20 %}3
{% elif wind <= 28 %}4
{% elif wind <= 39 %}5
{% elif wind <= 50 %}6
{% elif wind <= 62 %}7
{% elif wind <= 75 %}8
{% elif wind <= 89 %}9
{% elif wind <= 103 %}10
{% elif wind <= 117 %}11
{% else %} > 117 %}12
{%- endif %}"
entity_picture_template: "
{% set state = states('sensor.beaufort') %}
{% set path = '/local/beaufort/' %}
{% set ext = '.jpg'%}
{{[path,state,ext]|join('')|lower}}"
#########################################################
# #
# END OF CONFIGURATION FILE #
# #
#########################################################
I have used the following great posts for inspiration and learning:
Rain Gauge via Zigbee from @parrel
ESPhome weather station @hugokernel
Beaufort from @Mariusthvdb
Wind pulse count
Humidity
That’s all
=========See last post========
I have updated the config files according to the latest HA version
++++++++++++++++++++++++++++++++++++++++++++++++