Krazy998 / mqtt-hisensetv

Details to connect to Hisense Smart TV MQTT broker for home automation
MIT License
118 stars 12 forks source link

Hisense H8 display connection #2

Open supagold opened 4 years ago

supagold commented 4 years ago

Hi, I spent a lot of time trying to figure out how to get this working on my H8 display, and I wanted to share with anyone else who might be trying to make it work. It looks like they've moved to an encrypted MQTT session (still on port 36669). I'm using MQTT Explorer for testing, and the options for encryption=on and validate=off (they're using a self-signed cert), with the same username and password as in the main doc, are working for me. (Sure wish I'd tried just playing with those switches before setting up an android emulator and wireshark...)

I'm still working on getting control functioning, but I can't tell if that's just inexperience or other changes to this display yet...

newAM commented 4 years ago

Thanks! You saved me some time making the same discovery. Here's some sample python for the next guy.

#!/usr/bin/env python3.8

import logging
import paho.mqtt.client as mqtt
import ssl

def on_connect(client, userdata, flags, rc):
    """ Connection callback for MQTT client. """
    print(f"connected with code {rc!r}")

    print("subscribing to #")
    client.subscribe("#")

def on_message(client, userdata, msg):
    """ Message callback for MQTT client. """
    topic = msg.topic
    payload = msg.payload.decode("ascii", errors="backslashreplace")
    print(f"new message on {topic!r} with payload {payload!r}")

def main():
    logging.basicConfig(level=logging.DEBUG)
    client = mqtt.Client()
    client.username_pw_set(
        username="hisenseservice", password="multimqttservice"
    )
    client.enable_logger()
    client.tls_set_context(context=ssl._create_unverified_context())
    client.tls_insecure_set(True)
    client.on_connect = on_connect
    client.on_message = on_message
    client.connect("10.0.0.186", 36669)
    client.publish("/remoteapp/tv/ui_service/HomeAssistant/actions/gettvstate")
    client.loop_forever()

if __name__ == "__main__":
    main()

Upon running this a popup will appear on the TV with "Please enter the 4-bit password on the RemoteNOW of you mobile phone."

I tried to go further and install the app, but it cannot discover my TV; and from the reviews of the app it seems like this is a common problem.

UncleLeoTheDad commented 2 years ago

@newAM : this is very helpful! I have an H8G and have been trying to connect to it via MQTT explorer and now via your script, but nothing seems to work. Here is the result when I execute your script, using my TV's IP address:

Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\HomeAssistant\ConnectToHisenseTVMQTT> & C:/Python39/python.exe c:/HomeAssistant/ConnectToHisenseTVMQTT/ConnectToMQTT.py Traceback (most recent call last): File "c:\HomeAssistant\ConnectToHisenseTVMQTT\ConnectToMQTT.py", line 40, in main() File "c:\HomeAssistant\ConnectToHisenseTVMQTT\ConnectToMQTT.py", line 34, in main
client.connect("192.168.1.17", 36669) File "C:\Python39\lib\site-packages\paho\mqtt\client.py", line 914, in connect
return self.reconnect() File "C:\Python39\lib\site-packages\paho\mqtt\client.py", line 1044, in reconnect sock = self._create_socket_connection() File "C:\Python39\lib\site-packages\paho\mqtt\client.py", line 3685, in _create_socket_connection return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source) File "C:\Python39\lib\socket.py", line 843, in create_connection raise err File "C:\Python39\lib\socket.py", line 831, in create_connection sock.connect(sa) socket.timeout: timed out PS C:\HomeAssistant\ConnectToHisenseTVMQTT>

Here's the code:

#!/usr/bin/env python3.8

import logging
import paho.mqtt.client as mqtt
import ssl

def on_connect(client, userdata, flags, rc):
    """ Connection callback for MQTT client. """
    print(f"connected with code {rc!r}")

    print("subscribing to #")
    client.subscribe("#")

def on_message(client, userdata, msg):
    """ Message callback for MQTT client. """
    topic = msg.topic
    payload = msg.payload.decode("ascii", errors="backslashreplace")
    print(f"new message on {topic!r} with payload {payload!r}")

def main():
    logging.basicConfig(level=logging.DEBUG)
    client = mqtt.Client()
    client.username_pw_set(
        username="hisenseservice", password="multimqttservice"
    )
    client.enable_logger()
    client.tls_set_context(context=ssl._create_unverified_context())
    client.tls_insecure_set(True)
    client.on_connect = on_connect
    client.on_message = on_message
    client.connect("192.168.1.17", 36669)
    client.publish("/remoteapp/tv/ui_service/HomeAssistant/actions/gettvstate")
    client.loop_forever()

if __name__ == "__main__":
    main()

Anything obvious I'm doing wrong?

newAM commented 2 years ago

That looks correct. I'm not sure what would be going on if it connects with MQTT explorer. If you're familiar with wireshark that would be a good next step for debugging.

UncleLeoTheDad commented 2 years ago

@newAM It does NOT connect with MQTT-explorer either. I'll look into wireshark. Was there anything on the TV itself you needed to enable in order for this to work?

newAM commented 2 years ago

Oh, sorry, I misread. In that case check with nmap if the port is open on the TV before wiresharking. You do have to enable support for the Hisense app on the TV for this to work.

UncleLeoTheDad commented 2 years ago

@newAM That was the problem! I didn't have content sharing support enabled and I hadn't tried the app. Somehow missed those steps. I'm able to connect now. Thanks!

rogersmj commented 1 year ago

I can't get connected to my H8 with any MQTT app. How did you guys make this work?

I have enabled all the IP and content sharing settings on the TV:

I can control it using the RemoteNOW app on iOS.

I have found the key files from d3nd and have them setup in MQTT Explorer:

image

image

But it just will not connect. I have tried with and without encryption. Any ideas?