Missing value with mqtt (only last data set is shown?)

i receive values from a 433mzh antenna, and feed those to my mqtt server.
hass version 0.65.2.

i can’t remember when this changed, but some values just seem to disappear. or maybe that’s not correct. it seems that when no values are shown, there weren’t sent any.

but i’d wish to at least show the last known value. how would i do that?
in the pic you can see that there were some value until 20:45 and then nothing, and then one value at 21:03. different values are caused because i moved the thermometer from inside to outside.

image

- platform: mqtt
  name: "Pooltemperatur"
  state_topic: "sensors/rtl_433"
  value_template: "{{ value_json.temperature_C }}"
  unit_of_measurement: "C"

here you can see it again, and now “power wattage” is missing, which got a lot of values regarding to the history.

image

image

something i observed as well: this happens with ALL my mqtt sensors.
the values appear once they are published by the sensor UNTIL any other sensor sends some data. then THIS data is shown, and the other data disappear.

so let’s assume there are two sensors: one measure POWER, the other measured temperature.
the both come from the same topic: sensors/rtl_433

but from different sensors. one is an energy meter, the other one a thermometer.

08:50:09 /home/homeassistant/.homeassistant# mosquitto_sub -u mqtt -P mqtt -t sensors/rtl_433
{"time" : "2018-03-18 20:50:45", "model" : "Nexus Temperature/Humidity", "id" : 69, "battery" : "OK", "channel" : 1, "temperature_C" : -2.300, "humidity" : 20}
{"time" : "2018-03-18 20:50:49", "brand" : "OS", "model" : "CM160", "id" : 11, "power_W" : 917}
{"time" : "2018-03-18 20:51:42", "model" : "Nexus Temperature/Humidity", "id" : 69, "battery" : "OK", "channel" : 1, "temperature_C" : -2.300, "humidity" : 20}
{"time" : "2018-03-18 20:51:49", "brand" : "OS", "model" : "CM160", "id" : 11, "power_W" : 950}
{"time" : "2018-03-18 20:52:39", "model" : "Nexus Temperature/Humidity", "id" : 69, "battery" : "OK", "channel" : 1, "temperature_C" : -2.300, "humidity" : 20}
{"time" : "2018-03-18 20:52:49", "brand" : "OS", "model" : "CM160", "id" : 11, "power_W" : 933}
{"time" : "2018-03-18 20:53:14", "brand" : "OS", "model" : "CM160", "id" : 11, "power_W" : 901}
{"time" : "2018-03-18 20:53:26", "brand" : "OS", "model" : "CM160", "id" : 11, "power_W" : 853}
{"time" : "2018-03-18 20:53:36", "model" : "Nexus Temperature/Humidity", "id" : 69, "battery" : "OK", "channel" : 1, "temperature_C" : -2.300, "humidity" : 20}
{"time" : "2018-03-18 20:53:37", "brand" : "OS", "model" : "CM160", "id" : 11, "power_W" : 853}

every new line triggers what is show.

what causes this effect, and how would i solve this??

ok. i found the solution myself.
there is only one topic which is parsed by HA, and then search for keywords. if the keyword can not be found it’s set to undefined/empty.

jinja2 doc states:

If a variable or attribute does not exist, you will get back an undefined value. What you can do with that kind of value depends on the application configuration: the default behavior is to evaluate to an empty string if printed or iterated over, and to fail for every other operation.

so all i had do was to add an ELSE statement, setting the value to state.state which represents the current state.

- platform: mqtt
  name: "Aussenluftfeuchtigkeit"
  state_topic: "sensors/rtl_433"
  value_template: "{% if value_json.model == 'Nexus Temperature/Humidity' %} {{ value_json.humidity }} **{% else %} {{ state.state }}** {% endif %}"
  unit_of_measurement: "%"
  retain: true

- platform: mqtt
  name: "Stromverbrauch"
  state_topic: "sensors/rtl_433"
  value_template: "{% if value_json.model == 'CM160' %} {{ value_json.power_W }}  {% else %} {{ state.state }} {% endif %}"
  unit_of_measurement: "W"

hmmm… i just noticed that it partly works. the outcome is ok, but not the way it’s acchieved:

so i will need to investigate more.

what app are you using to read CM160, because I have one and I can’t get to read the values. I’m using rtl_433. If you are using that could you please tell me the command that you do?

Thank you.

Best regards,

Alberto

{{ state.state }} is not correct. You should use {{ state(‘sensor.Aussenluftfeuchtigkeit’) }}

Hi,

Can you please tell me the comand that you do (frequency, etc) to get the data from CM160? Because I can’t get the data from mine. I know that rtl_433 is working because i’m getting the data from another sensor.

Thank you

Iz3man

My understanding is
HA Seeing thos topic and does not have a sensor for it

it was

sudo rtl_433 -g 7 -F json | mosquitto_pub -i -l -h localhost -u USERNAME -P PASSWORD -t sensors/rtl_433 &

it now is

sudo python3 /usr/local/bin/rtl_433_mqtt_relay.py &
sudo rtl_433 -g 7 -F syslog:127.0.0.1:1433 &

Thank you for you awnser! Still not working :frowning:
If possible could you execute the command: rtl_433 -a
then check if you can see the data from the CM160. If so, could you see the start information of rtl_433 and look for a information like this:
trying device 0: Realtek, RTL2838UHIDIR, SN: 00000001
Detached kernel driver
Found Rafael Micro R820T tuner
Using device 0: Generic RTL2832U OEM
Exact sample rate is: 250000.000414 Hz
[R82XX] PLL not locked! (Please check is locked or not locked)
Sample rate set to 250000.
Bit detection level set to 0 (Auto).
Tuner gain set to Auto.
Reading samples in async mode…
Tuned to 433920000 Hz.

If it’s locked can you please the brand of your receiver stick, and where did you get it from?

Thank you so much!
Best regards

https://www.aliexpress.com/item/New-arrival-USB-DVB-T-RTL-SDR-Realtek-RTL2832U-R820T-DVB-T-Tuner-Receiver-MCX-Input/32733244909.html?spm=a2g0s.9042311.0.0.27424c4ddeCce4