Custom MQTT sensor is discovered but shows no data

I created a Windows program that tracks the total time someone is using the computer. I’m sending the sensor information to Home assistant via MQTT. Discovery is working and the device and sensor show up, but the sensor information is not being captured and it’s showing as Unknown.

What am I missing to show the sensor information ?
I’ve been reading MQTT Sensor - Home Assistant (home-assistant.io) and MQTT Discovery - Home Assistant (home-assistant.io) and many community posts, but I’m failing to understand what is wrong. Any help is appreciated. Thanks in advance!

Discovery part for one of the sensors:
topic: homeassistant/sensor/V-TIAGOAND-LP3_REDMOND_tiagoand_Time/config

{
  "~": "wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/",
  "object_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "name": "V-TIAGOAND-LP3/REDMOND_tiagoand Total Time in minutes",
  "avty_t": "~STATE",
  "pl_avail": "ON",
  "pl_not_avail": "OFF",
  "stat_t": "~SENSOR",
  "value_template": "{{ value_json.time }}",
  "unique_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "dev_cla": "duration",
  "dev": {
    "identifiers": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "manufacturer": "Wellbeing",
    "name": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "model": "Windows"
  }
}

State is set to ON
topic: wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/STATE

ON

Payload of sensor data
topic: wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/SENSOR

{"idle":False, "time":108}

Discovery is working fine as the device and sensors shows up:

Home Assistant is seeing the information per the MQTT debug info:
MQTT Info for this sensor:
image

With more details

What I see in MQTT Explorer:

Doesn’t seem to like the unquoted false

works as 
{"idle":"False", "time":109}

or 
{"time": 108}

Not sure how you fix the value template for that though sorry.

You rock! thanks for the extra pair of eyes that made the difference :slight_smile:

1 Like

Thanks for your help @hasQT. I made a change and I’m back to not understanding why one of sensors is now unavailable … Any way to more easily debug these issues ? it’s so easy to mess up …

Payload
topic: homeassistant/sensor/V-TIAGOAND-LP3_REDMOND_tiagoand_Time/config

{
  "~": "wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/",
  "object_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "name": "V-TIAGOAND-LP3/REDMOND_tiagoand Total Time in minutes",
  "avty_t": "~STATE",
  "payload_on": "ON",
  "payload_off": "OFF",
  "stat_t": "~SENSOR",
  "value_template": "{{value_json.time}}",
  "unique_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Time",
  "dev_cla": "duration",
  "dev": {
    "identifiers": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "manufacturer": "Wellbeing",
    "name": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "model": "Windows"
  }
}

Other topic:
image

How HA sees it
image

It should pop an error in the logs if it’s failing the parser.

Did you create a new topic? This looks like it’s still for time?

You basically need a topic and message for each sensor.

The stuff nested under
Dev:

Is what links them together as a device

The sensors show up under the same device, so that mapping to the device is working well.
The problem is still regards time, yes. I do have one topic and messages for each sensor.
In what log will the parser errors show up ? The MQTT debug log is not showing any error…
thanks again for your help.

The HA core logs. (the main log)

Post both sensors

HA Core Logs as no issue related to these MQTT sensors.

Here is more info:

topic: homeassistant/binary_sensor/V-TIAGOAND-LP3_REDMOND_tiagoand_Active/config

{
  "~": "wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/",
  "object_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Idle",
  "name": "V-TIAGOAND-LP3/REDMOND_tiagoand Active or not",
  "stat_t": "~IDLE",
  "payload_on": "True",
  "payload_off": "False",
  "unique_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Idle",
  "dev_cla": "presence",
  "dev": {
    "identifiers": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "manufacturer": "Wellbeing",
    "name": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "model": "Windows"
  }
}

Topic: homeassistant/sensor/V-TIAGOAND-LP3_REDMOND_tiagoand_Time/config

{
  "~": "wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/",
  "object_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "name": "V-TIAGOAND-LP3/REDMOND_tiagoand Total Time in minutes",
  "avty_t": "~STATE",
  "payload_on": "ON",
  "payload_off": "OFF",
  "stat_t": "~SENSOR",
  "value_template": "{{value_json.time}}",
  "unique_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Time",
  "dev_cla": "duration",
  "dev": {
    "identifiers": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "manufacturer": "Wellbeing",
    "name": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "model": "Windows"
  }
}

MQTT Explorer:

image

HA MQTT Device info

You may find it easier to use the full names on the “keys”. Makes it a bit easier to read. The only reason to use the short version is if you are hitting the max length/bytes on messages.

state_topic
availability_topic:
etc

You are trying to send the state ON/OFF payloads to the state topic ~SENSOR… instead of the availability topic ~STATE (LWT would be more appropriate)

So it doesn’t know if ON or {“time”: 12} is the correct message

This message works for time config message.

{
  "~": "wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/",
  "object_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "name": "V-TIAGOAND-LP3/REDMOND_tiagoand Total Time in minutes",
  "stat_t": "~SENSOR",
  "value_template": "{{value_json.time}}",  ## this might need to be "{{value_json.time | defautl(none)}}"
  "unique_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Time",
  "dev_cla": "duration",
  "dev": {
    "identifiers": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "manufacturer": "Wellbeing",
    "name": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "model": "Windows"
  }
}

This is probably what you want…
Actually the above topic probably works better if IDLE is essentially working as LWT… (last will and testament)

{
  "~": "wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/",
  "object_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "name": "V-TIAGOAND-LP3/REDMOND_tiagoand Total Time in minutes",
  "avty_t": "~LWT",    ### payloads would be offline or online
  "stat_t": "~SENSOR",
  "value_template": "{{value_json.time}}",
  "unique_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Time",
  "dev_cla": "duration",
  "dev": {
    "identifiers": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "manufacturer": "Wellbeing",
    "name": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "model": "Windows"
  }
}

You can just post all the messages in mqtt_explorer for testing if you didn’t know that already.
You may need to delete the device/retained messages between tests though.

This is so frustrating! Thanks for your support!
Don’t understand what you say by “You are trying to send the state ON/OFF payloads to the state topic ~SENSOR… instead of the availability topic ~STATE (LWT would be more appropriate)”. The “Idle” sensor is working fine. The “Time” sensor is the one that is showing “Unavailable” and it has “avty_t”: “~STATE”.

I’ve followed your suggestions: Moved State topic to LWT, and included the full key description, but nothing changed. Idle is still working and Time sensor is still unavailable :sob:
I’m sure this is just fixing a very small thing, as this was working last night before I changed something.

topic: homeassistant/sensor/V-TIAGOAND-LP3_REDMOND_tiagoand_Time/config

{
  "~": "wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/",
  "object_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "name": "V-TIAGOAND-LP3/REDMOND_tiagoand Total Time in minutes",
  "availability_topic": "~LWT",
  "payload_on": "Online",
  "payload_off": "Offline",
  "state_topic": "~SENSOR",
  "value_template": "{{value_json.time | default(none)}}",
  "unique_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Time",
  "dev_cla": "duration",
  "dev": {
    "identifiers": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "manufacturer": "Wellbeing",
    "name": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "model": "Windows"
  }
}

image

Stop sending payload on/off
You don’t need it

1 Like

I already took it, but issue is the same :frowning:

topic: homeassistant/sensor/V-TIAGOAND-LP3_REDMOND_tiagoand_Time/config

{
  "~": "wellbeing/V-TIAGOAND-LP3/REDMOND_tiagoand/",
  "object_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "name": "V-TIAGOAND-LP3/REDMOND_tiagoand Total Time in minutes",
  "availability_topic": "~LWT",
  "state_topic": "~SENSOR",
  "value_template": "{{value_json.time | default(none)}}",
  "unique_id": "V-TIAGOAND-LP3_REDMOND_tiagoand_Total",
  "device_class": "duration",
  "dev": {
    "identifiers": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "manufacturer": "Wellbeing",
    "name": "V-TIAGOAND-LP3_REDMOND_tiagoand",
    "model": "Windows"
  }
}

image

image

Which one should I use unique_id or object_id ? using both can lead to naming problems … I think I’ve tried multiple combinations now …

I’d drop object_id
Unique_id makes more sense to me.

Both those examples I posted earlier worked when I tried them.

LWT = online

Not
LWT = Online

Mqtt is case sensitive in lots of things

1 Like

Once more, you rock! Thanks for the support and patience @HasQT
I wish it was easier to debug these issues.

1 Like