Mqqt messages to hone assistant

Hello everyone, this is my first time so be gentle,

Just to clarify I am a total noob, I’m not bad at python, but that doesn’t help much here.

I have, I imagine, a fairly simple problem-

I use node red to do all the legwork and really just use ha as a front-end.

So I have Mqtt sensors subscribed to node red and they are battery powered so I want to know when they fail. All that’s fine, I have a flow that publishes if it doesn’t receive a message from one of the sensors after X amount o time. Ha picks up this message fine, but I can’t work out how to manipulate it. Ie the mesage has 2 topics; text-saying battery has failed and a date stamp. I want to say, write a function in ha that, when it receives the messages will show a red battery icon and and the date.

I dont need to know the details, more just point me in the right direction. All I can do at the moment is display the raw payload.

Thank you very much in advance


Hi there, You can create one mqtt binary sensor and another mqtt sensor to achieve this. The binary sensor can be configured as a battery class device but here you have to change the text payload from “battery has failed” to on and off. This is a sample, you have to change the value_json and all

  - platform: mqtt
    name: "Battery Sensor"
    state_topic: "home-assistant/window/contact"
    payload_on: "on"
    device_class: battery
    value_template: "{{ value_json.state }}"

The second sensor is a mqtt sensor which can show the time stamp payload that is published.

  - platform: mqtt
    state_topic: "home/bedroom/temperature"
    value_template: "{{ value_json.state }}"

Here again I wish to say that there are multiple methods to achieve this process even without nodered, its a tad bit complicated than this and we have to build things from scratch. Since you already have a working system we can build on that.