I have a weather station output the below JSON via MQTT. I have 2 temp sensors reporting in 2 channels, each channel for each room. Since the weather station output is for 2 channels, I need to compare the channel and find out the room temperature.
But the homeassistant shows only 1 output, which it got the latest. For example if the 1st one’s output is 29.3C then it shows 29.3 and 2nd one’s output is 32.1C then it shows 32.1
Even-though both are different sensors, the output of both is same.
Any help on fixing the config is much appreciated.
I am using this version of rtl_433
rtl_433 version 18.12-88-ga9a327d branch master at 201902080905
I run this command to send the data to my mqtt broker (server) rtl_433 -R 40 -R 12 -F json -M utc | mosquitto_pub -h mqtt_ip-address -p mqtt-port -u mqtt-username -P mqtt-password -t home/rtl_433 -l
In HA, I have a directory called sensors.
Inside that, I seprated each sensor:
OregonRain.yaml
- platform: mqtt
state_topic: 'home/rtl_433'
name: 'Rain Total'
unit_of_measurement: ''
value_template: >
{% if value_json is defined and value_json.id == 151 %}
{{ value_json.rain_total }}
{% else %}
{{ states('sensor.rain_total') }}
{% endif %}
- platform: mqtt
state_topic: 'home/rtl_433'
name: 'Rain Rate'
unit_of_measurement: 'in/hr'
value_template: >
{% if value_json is defined and value_json.id == 151 %}
{{ value_json.rain_rate }}
{% else %}
{{ states('sensor.rain_rate') }}
{% endif %}
OregonTemp.yaml
- platform: mqtt
state_topic: "home/rtl_433"
name: "Outdoor Humidity"
unit_of_measurement: '%'
value_template: >
{% if value_json is defined and value_json.id == 55 %}
{{ value_json.humidity }}
{% else %}
{{ states('sensor.outdoor_humidity') }}
{% endif %}
- platform: mqtt
state_topic: "home/rtl_433"
name: "Outdoor Temperature"
unit_of_measurement: '°C'
value_template: >
{% if value_json is defined and value_json.id == 55 %}
{{ value_json.temperature_C }}
{% else %}
{{ states('sensor.outdoor_temperature') }}
{% endif %}
OregonWind.yaml
- platform: mqtt
#wind gust
state_topic: "home/rtl_433"
name: "Wind Gust"
unit_of_measurement: 'm/s'
value_template: >
{% if value_json is defined and value_json.id == 187 %}
{{ value_json.gust }}
{% else %}
{{ states('sensor.wind_gust') }}
{% endif %}
- platform: mqtt
state_topic: 'home/rtl_433'
name: 'Wind Direction'
unit_of_measurement: ''
value_template: >-
{% if value_json is defined and value_json.id == 187 %}
{% set wd = value_json.direction | int %}
{% if wd <= 11 or wd > 348 %}North
{% elif wd >11 and wd <=34 %}North North East
{% elif wd >34 and wd <=56 %}North East
{% elif wd >56 and wd <=79 %}East North East
{% elif wd >79 and wd <=101 %}East
{% elif wd >101 and wd <=124 %}East South East
{% elif wd >124 and wd <=146 %}South East
{% elif wd >146 and wd <=169 %}South South East
{% elif wd >169 and wd <=191 %}South
{% elif wd >191 and wd <=214 %}South South West
{% elif wd >214 and wd <=236 %}South West
{% elif wd >236 and wd <=259 %}West South West
{% elif wd >259 and wd <=281 %}West
{% elif wd >281 and wd <=304 %}West North West
{% elif wd >304 and wd <=326 %}West North West
{% elif wd >326 and wd <=348 %}North North West
{% endif %}
{% else %}
{{ states('sensor.wind_direction') }}
{% endif %}
then you will get individual copics for each ID and Channel, creating sensor for each is simple as adding the id or channel to the end of the sensor setting e.g.