I designed the sensor node working on ESP8266 connected DHT11 temp&humid sensor and BMP085 temp&pressure sensor.
This node publishes mqtt data on json format respectively for DHT sensor values and BMP sensor values, like the following;
Both published to the same topic; sensor/feeds/values
On frontend of Home Assistant, first published data disappeared and only second data shows.
Would anybody like to give me any hints to resolve this issue?
I can’t try it right now but you could try to separate it into the two sensors. One for each value published.
My guess is that HA reads each message and since the last one is “blank” for the value it tries to read it assumes the sensor doesn’t have a value.
Another workaround would be to post each of the parts to different topics.
I’m not certain this will work but I would be interested in the results.
If you get a working setup and feel like it please also share the code you used with your esp8266
We might be able to workaround this with some templating. Check if the value is defined and if not don’t update it.
I’ll have to continue this when I have access to a HA install but I’m fairly certain we can do it.
Can just confirm that I have the same issue. If you try to read different json keys sent in multiple messages over MQTT then you will face this issue. Mine are sent with a delay of about 100ms and you can see the frontend flicker when the “old” values go blank since they are not part of that message.
In steps:
{“key1”:1, “key2”:3} sent over MQTT on topic “home/topic”
{“key3”:1, “key4”:3} send over MQTT on topic “home/topic”
Once 2. is read then the values for 1. will go blank in the frontend.
Is it possible to exclude updating the GUI for values not present in the message fro that topic? Guess the event sent over websocket need be updated, or how it is handled in the GUI.
Is this still the only way to accomplish this?
I’m trying to integrate with Sleep As Android https://docs.sleep.urbandroid.org/services/automation.html#events and it’ll send events in a JSON payload, like {event: sleep_tracking_started} and {event: sleep_tracking_stopped}, among others. So the template could still work, using if/elif/else/endif:
value_template: "{% if value_json.event == 'sleep_tracking_started' %} on {% elif value_json.event == 'sleep_tracking_stopped' %} off {% else %} {{ state.state }} {% endif %}"
but it would really be nice if there were a better way. The only other way I can think of is to use a mqtt automation trigger for the single topic, and manually toggle switches based on what the incoming JSON $.event is. But that requires a toggleable switch, rather than a binary_sensor.