I apologize for yet another one of these threads, but I’ve reached the bottom of my debug barrel…
SETUP
RPi4 with home assistant installed
MQTT server installed through HA supervisor
RPi Zero w/ SDR dongle attached and an rtl_433 server installed/running tuned to 345mhz AND publishing sensor data through MQTT
Honeywell 5800 open/close and PIR sensors
ISSUE
I’m able to verify that the rtl_433 server on the RPi0 is properly reading the broadcast signal from my Honeywell devices. I can also verify that the MQTT data is being published from the rtl_433 server. I am able to successfully listen for the specific device topics through the MQTT integration inside HA.
What I can’t seem to figure out is how to properly create and connect a device or entity inside HA to read the necessary data. The closest attempt I have at the moment is this entry in my sensor.yaml for my open/close sensor:
With this I at least have an entity showing up in HA, but it always in an ‘unknown’ state. My guess is I’m goofing something in the value_template area? I’ve combed through other threads trying to Frankenstein together some combination of parameters in hopes this will magically start to work, but it might be better if I could get some help understanding the fundamentals of how this type of thing should be set up.
Right off the bat I clearly had the name of the sensor wrong. I’ve corrected that, and after looking at the two other threads you posted, took a couple new attempts at reading in a useful value. No dice, still ‘unknown’. Here’s my latest attempt:
- platform: mqtt
state_topic: 'rtl_433/security/devices/Honeywell-Security/8/81290/state'
unique_id: 'door_sensor_patio'
name: 'Patio Door'
qos: 0
value_template: >
{% if value_json is defined and value_json.state == 40 %}
{{ value_json.state }}
{% else %}
{{ states('sensor.patio_door') }}
{% endif %}
I think I just fundamentally misunderstand the syntax involved. Based on my value_json, I’m assuming I can call any one of those pieces using ‘value_json.’ (value_json.state, value_json.alarm, value_json.tamper)? So with that assumption, my hope would be that calling ‘{{value_json.state}}’ would return either ‘open’ or ‘closed’.
No, i mean the MQTT integration in Settings > Devices & Services > MQTT > Configure.
Paste your state_topic and ‘Start Listening’.
If the value_json is correct, your value_template is wrong, because the state is ‘open’ and you’re testing for ‘40’.
Try:
value_template: >
{% if value_json is defined and value_json.id == '13d8a' %} # with and without quotes
{{ value_json.state }}
{% else %}
{{ states('sensor.patio_door') }}
{% endif %}
Tried your snippet. Without quotes HA barks, but even with quotes I’m still getting a perpetually ‘unknown’ state.
Here’s the output listening to the state topic through the MQTT integration:
Message 24 received on rtl_433/security/devices/Honeywell-Security/8/81290/state at 10:37 AM:
open
QoS: 0 - Retain: false
Message 23 received on rtl_433/security/devices/Honeywell-Security/8/81290/state at 10:37 AM:
closed
QoS: 0 - Retain: false
I made sure to include the output from both an open and closed just to make the point that it is reading a change in state when I move the magnet away from the sensor.
Oh wow. Yup that did it. It’s now reporting open/closed.
How would I go about referencing the other data the sensor is reporting?
Also, I totally agree about it being better as a binary sensor, however, I can’t seem to copy/paste this code from sensor.yaml to binary_sensor.yaml. Is there something special I need to do to make that work?
That example still comes back as ‘unknown’…
Again, I’m sure this is just a blind spot in my knowledge of reading/processing mqtt sensor data.
I did install MQTT Explorer, but at first glance the data coming out of that feels very reminiscent of the data I was already getting through HA. Do I need to keep digging around there to find what I’m looking for?