[SOLVED] I'm not understanding MQTT sensor always showing 'unknown'

I’m working on something to send TurnTouch remote info via MQTT. Right now, the topics look like this:

turntouch/battery 80
turntouch/mode lights

I’ve set up two sensors as such:

sensor:
  - platform: mqtt
    state_topic: 'turntouch/mode'
    name: turntouch_mode
    unique_id: turntouch_mode
    value_template: '{{ value_json }}'
  - platform: mqtt
    state_topic: 'turntouch/battery'
    name: turntouch_battery
    unique_id: turntouch_battery
    unit_of_measurement: '%'
    value_template: '{{ value_json }}'
    device_class: battery

The battery info works great! But the mode sensor is either blank or ‘unknown’.

I can see the data coming in the debug log:

2020-04-29 10:43:31 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on turntouch/battery: b'31'
2020-04-29 10:44:44 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on turntouch/mode: b'media'
2020-04-29 10:44:48 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on turntouch/mode: b'lights'

So I think I’m missing something conceptual here. I was hoping the sensor would show changes in the mode. I’ve tried mode both with and without the RETAIN flag. The end goal is to be able to trigger changes based on the current state.

Is there some smarter way I should be trying to accomplish this?

Thank you for your help!

Where do you see json in that topic ? Still you use

value_template: '{{ value_json }}'

If you can tell me what else to put there, I’ll try it. I’ve also tried leaving the value_template key out entirely and it doesn’t work. Nice avatar, btw!

That should be enough

  - platform: mqtt
    state_topic: "turntouch/mode"
    name: turntouch_mode
    unique_id: turntouch_mode

Well holy moley. That did it. Thank you!

Hi, sorry to dig out this old thread but that’s the only mention I found of integrating turntouch with HA. Did you ever get somewhere @robbie.huffman ?

I have thit nice piece of wood on y desk for ages and I’d love to be able to actually do something with it eventually :slight_smile:

Yes, I had some success with it. I’ll find my code and post it to github later today.

This might be enough to get you going. You’ll need the python-turntouch and paho-mqtt libraries installed to run it. I hadn’t yet parameterized it in any way, so you’ll need to plug in your TT’s MAC and your Home Assistant hostname.

Awesome, thanks ! I’ll give it a try.