Could someone help me figure out how to setup a sensor/automation that gets a message like below from mqtt, and then returns the temp in F (76.1 in the example)to a specific sensor based on the field channel? So for the mqtt below, I’d want a sensor that reflects the temp when channel=6 and can likely ignore the sensor ID value since that changes when I change sensor batteries but the channel number 6 won’t change.
My old system using 433mhz sensors that didn’t have channel numbers was all ID based which sucked since I had to remap the sensors anytime I changed the batteries.
Set its value_template to extract the value of the temperature_F key from the received payload but only if the channel key’s value is 6 (otherwise make it report its current value).
sensor:
- platform: mqtt
name: Outdoor Temperature
state_topic: whatever/433mhz/gadget
unit_of_measurement: '°F'
device_class: temperature
value_template: "{{ value_json.temperature_F if value_json.channel == 6 else states('sensor.outdoor_temperature') }}"
I have an automation as such, since my rPi running rtl_433 just dumps a bunch of sensors all to a single topic. I tried adding the example code that’s commented out to record more steps for troubleshooting but the automation won’t start if I uncomment those lines, but the config checker didn’t return any errors.
Which I’m hoping republishes the data as a unique topic per sensor(well channel).
Based on my longstanding automation that did this is below, but it created a new topic by the “Id” in the sensor which changes when you change the batteries, and not all my sensors have the channel dip switches I later discovered.
I don’t know if you had a chance to read this but it might give you some ideas if you ever use 433MHz binary sensors (the article is applicable for any MQTT-based 433 MHz receiver, not just the Sonoff RF Bridge).
If you use this to demultiplex the topic’s payload:
If the sensor’s configuration looks exactly the way you posted it, then it has an indentation error. Compare with the example I posted above.
Also, check the appearance of the payload published to home/sensor6. Ideally, check it with an MQTT client like MQTT Explorer. Just noticed you already looked at it.
The sensor’s template can be shortened, like in the recent example I posted, because now it no longer needs to check the channel.
Aha, I had forgotten that I whitelisted sensors in the recorder setup, so it wasn’t displaying on the history graph card I use… worked like a charm now.
Please consider marking my post (above) with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. It will also place a link below your first post that leads to the solution post. All of this helps users find answers to similar questions.
In this case, it’s translating the hex number and looking for the 45034th element; if the key starting with a digit isn’t “translatable” it just breaks: