Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95919

Multi sensor using same MQTT topic

$
0
0

@gigitek wrote:

I’m having trouble setting up two sensors which read the value from same MQTT topic.
Data must be interpreted based on a parameter, e.g type
The HW sensor/device provides temperature and humidity on the same topic, something like:

type=0x01 unit=0 valueF=24.75

If type is 1 => valueF is the temperature, if type is 0x05 => valueF is the humidity
In my configuration.yaml I tried the following, but with no success:

sensor:
  - platform: mqtt
    state_topic: "/response/node/7/class/sensor/status"
    name: "Temp"
    unit_of_measurement: '°C'
    value_template: "{% if value.split(' ')[0] == \"type=0x01\" %}{{ value.split(' ')[2].split('=')[1]  }}{% else %}{{ states('sensor.laststate') }}{% endif %}"
  
- platform: mqtt
    state_topic: "/response/node/7/class/sensor/status"
    name: "Humidity"
    value_template: "{% if value.split(' ')[0] == \"type=0x05\" %}{{ value.split(' ')[2].split('=')[1]}}{% endif %}"

Neither of the above is working correctly.
I tried with an else branch in order to keep the last value, because it was not working correctly without it, e.g. empty value in the UI

Posts: 3

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 95919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>