2 Temperature Sensons on MQTT

I have an Acurite Tower Temp sensor and a Nexus Pool Temp Sensor

under rtl_433 both are on topic home/rtl_433

here’s configuration.yaml. As you can see I’m playing around with entity_id and unique_id. Nothing is working. The sensor for Acurite is correct however the Nexus is just the C measurement of the Acurite.

How can I differentiate between these two sensors?
I don’t know why my preformatted text isn’t working

sensor:
  • platform: mqtt
    state_topic: ‘home/rtl_433’
    unique_id: ‘12644’
    name: ‘Outdoor Temp’
    unit_of_measurement: ‘F’
    value_template: ‘{{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}’
    sensor 1:
  • platform: mqtt
    state_topic: ‘home/rtl_433’
    name: ‘Outside Humidity’
    unit_of_measurement: ‘%’
    value_template: “{{ value_json.humidity }}”
    sensor 2:
  • platform: mqtt
    name: ‘Hot Tub Temp’
    entity_id: ‘sensor.hot_tub_temp_2’
    state_topic: ‘home/rtl_433’
    unit_of_measurement: ‘C’
    value_template: ‘{{ value_json.temperature_C }}’

Please format your pasted code correctly:

You don’t appear to have an entity_id for the first sensor.

adding an entity id doesn’t seem to affect it. both are reading from “temperature_C” in MQTT

Please format your pasted code correctly.

sensor:
  - platform: mqtt
    state_topic: 'home/rtl_433'
    unique_id: '12644'
    name: 'Outdoor Temp'
    unit_of_measurement: 'F'
    value_template: '{{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}'
sensor 1:
  - platform: mqtt
    state_topic: 'home/rtl_433'
    name: 'Outside Humidity'
    entity_id: 'sensor.outside_humidity'
    unit_of_measurement: '%'
    value_template: "{{ value_json.humidity }}"
sensor 2:
  - platform: mqtt
    name: 'Hot Tub Temp'
    entity_id: 'sensor.hot_tub_temp_2'
    state_topic: 'home/rtl_433'
    unit_of_measurement: 'F'
    value_template: '{{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}'

… and while i was explaining how to format your code, you already it! Good, now it’s easier to read.


Unless you have a special need to use sensor, sensor 1, sensor 2, just leave the first sensor: and delete the other two.

Try this:

sensor:
  - platform: mqtt
    state_topic: 'home/rtl_433'
    unique_id: '12644'
    name: 'Outdoor Temp'
    unit_of_measurement: 'F'
    value_template: '{{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}'

  - platform: mqtt
    state_topic: 'home/rtl_433'
    name: 'Outside Humidity'
    entity_id: 'sensor.outside_humidity'
    unit_of_measurement: '%'
    value_template: "{{ value_json.humidity }}"

  - platform: mqtt
    name: 'Hot Tub Temp'
    entity_id: 'sensor.hot_tub_temp_2'
    state_topic: 'home/rtl_433'
    unit_of_measurement: 'F'
    value_template: '{{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}'

As @123 said you should only have one sensor: block declaration.

I had tried that. Here is the individual dump of the MQTT. Both readings seem to be coming from temperature_C

{"time" : "2019-01-18 00:57:24", "model" : "Nexus Temperature", "id" : 174, "channel" : 1, "battery" : "OK", "temperature_C" : 39.900}

{“time” : “2019-01-18 00:49:51”, “model” : “Acurite tower sensor”, “id” : 12644, “sensor_id” : 12644, “channel” : “A”, “temperature_C” : 7.400, “humidity” : 69, “battery_low” : 0}

I’m far from being a Home Assistant expert but is that valid to specify entity_id in the sensor component’s configuration?

My understanding is that Home Assistant will automatically create the sensor’s entity_id using name. So ‘Outdoor Temp’ becomes sensor.outdoor_temp.

According to the documentation, you can specify a custom entity_id via the UI. I didn’t realize you could also do it in the configuration file.

37%20PM

Obviously the hot tub should be 100 something degrees but it is the same as the outdoor temp

All three sensors have the same state_topic. They get the same message.

{"time" : "2019-01-18 00:57:24", "model" : "Nexus Temperature", "id" : 174, "channel" : 1, "battery" : "OK", "temperature_C" : 39.900}

The humidity sensor parses humidity from the message, but the two temperature sensors parse the exact same temperature. That’s why the show the same temperature.

You will have to create a more sophisticated value_template that also uses id and/or channel to identify the payload for the appropriate temperature sensor.

Yep. How do I set different topics. I catch all 433 transmissions and push to my MQTT server like this:

rtl_433 -F json -M utc | mosquitto_pub -t home/rtl_433 -l -h 192.168.20.6

What identifies each temperature sensor, is it id or channel or both?

You’ll need to use that in the value_template to extract the correct temperature.

For example, id=174 might represent the hot tub’s temperature and id=170 is the outdoor temperature. You need to discover what identifies each physical temperature sensor and use that in the value_template.

one is Channel A and one is Channel 1. Any hints how to do it. I’m stumped. I actually tried that but don’t know much about value template

Try this:

sensor:
  - platform: mqtt
    name: 'Outdoor Temp'
    state_topic: 'home/rtl_433'
    unit_of_measurement: 'F'
    value_template: >
      {% if value_json.channel == 1 %}
      {{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}
      {% endif %}

  - platform: mqtt
    name: 'Outside Humidity'
    state_topic: 'home/rtl_433'
    unit_of_measurement: '%'
    value_template: "{{ value_json.humidity }}"

  - platform: mqtt
    name: 'Hot Tub Temp'
    state_topic: 'home/rtl_433'
    unit_of_measurement: 'F'
    value_template: >
      {% if value_json.channel == "A" %}
      {{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}
      {% endif %}
1 Like

Thanks. I actually got this to work right about the time you posted.

sensor:
  - platform: mqtt
    state_topic: 'home/rtl_433'
    name: 'Outdoor Temp'
    unique_id: '12644'
    unit_of_measurement: 'F'
    value_template: >
      {% if value_json is defined and value_json.id == 12644 %}
        {{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}
      {% else %}
        {{ states('sensor.outdoor_temp') }}
      {% endif %}
  - platform: mqtt
    state_topic: 'home/rtl_433'
    name: 'Outside Humidity'
    entity_id: 'sensor.outside_humidity'
    unit_of_measurement: '%'
    value_template: "{{ value_json.humidity }}"
  - platform: mqtt
    name: 'Hot Tub Temp'
    state_topic: 'home/rtl_433'
    unit_of_measurement: 'F'
    value_template: >
      {% if value_json is defined and value_json.id == 174 %}
        {{ ((value_json.temperature_C * 1.8) + 32)|round(1) }}
      {% else %}
        {{ states('sensor.hot_tub_temp_2') }}
      {% endif %}
1 Like

@123
yours looks more compact and cleaner. I’ll try that as well tomorrow too. Next I tackle alarms.

I think I prefer your choice to use id instead of channel to identify the device. If I’m not mistaken, the 433MHz sensor’s channel can be selected by a physical switch. If the channel is changed then my code will fail to identify the sensor. Unless I’m mistaken, the sensor’s id cannot be modified and is a better choice as a permanent identifier.

I didn’t use an {% else %} because I think it’s not necessary. If the received message is not intended for the temperature sensor then it should just be ignored. The sensor’s existing value remains untouched.

So I seem to have it all wrapped up nicely

16%20AM

And I set an automation to notify me via Pushbullet when the temp goes below 95 F. Took the sensor out of the hot tub and a minute later - got a text.

automation 20:
  alias: Temp Alarm
  trigger:
    platform: numeric_state
    entity_id: sensor.hot_tub_temp_2
    below: 95
  action:
    - service: notify.mypushbullet
      data_template:
        title: "Hot Tub Temp Alarm"
        message: >-
          Hot Tub Temp Alarm, Bruh

Awesome! Been having too much fun with 433 MHz devices this week.