Hisense U6G (and possibly other) Android TV Control

the TV has been out 8 months, and there was only one update 6 months ago. I don’t think I’m in danger of too many future updates lol

Is there a way to set retain true just for the Hisense MQTT server, without setting retain true for everything going through my mosquitto broker?

I use my mosquitto broker for a number of other integrations, and prefer retain: false, but since the Hisense MQTT server doesn’t publish frequently, I prefer retain true just for Hisense.

For Publishing:
Do a script with action mqtt.publish, there you can check box retain and also flip the switch. The have HA call the script for any actions you want to do.

DO NOT do this for all topics, especially for the topic for sending button commands like volume, power etc. Otherwise you will get repeating commands and a TV that will turn itself right back off.

For listening:
If you need to retain a variable sent from the tv, then you need to do what I did with volume and input. Create sensor that is listening to topic, create an input helper and then have a automation update the input helper when the value of the sensor changes.

1 Like

I have a working TV power sensor now that requests the TV power state upon HA startup.

Sensor for TV power state

binary sensor
  - platform: mqtt
    name: "Hisense TV Power"
    device_class: power
    state_topic: "/remoteapp/mobile/broadcast/platform_service/data/picturesetting"
    value_template: >-
      {% if  value_json.menu_flag == -1 and value_json.menu_id == 11 %}
        {{'ON'}} 
      {% elif value_json.menu_flag == 1 and value_json.menu_id == 11 %}
        {{'OFF'}}
      {% elif value_json.menu_info[10].menu_flag == -1 %}
        {{'ON'}}
      {% elif value_json.menu_info[10].menu_flag == 1 %}
        {{'OFF'}}
      {% endif %}

TV power switch

switch:
  - platform: template
    switches:
      hisense_tv:
        icon_template: >
          {% if is_state('switch.hisense_tv','on') %}
            {{ 'mdi:television-classic' }}
          {% else %}
            {{ 'mdi:television-classic-off' }}
          {% endif %}
        friendly_name: 'Hisense TV'
        value_template: "{{ is_state('binary_sensor.hisense_tv_power', 'on') }}"
        turn_on:
          service: mqtt.publish
          data:
            topic: '/remoteapp/tv/remote_service/MY_PHONE_MAC$normal/actions/sendkey'
            payload: 'KEY_POWER'
        turn_off:
          service: mqtt.publish
          data:
            topic: '/remoteapp/tv/remote_service/MY_PHONE_MAC$normal/actions/sendkey'
            payload: 'KEY_POWER'

Request TV power state on HA startup automation

alias: Get Hisense TV power state on HA startup
trigger:
  - platform: homeassistant
    event: start
action:
  - service: mqtt.publish
    data:
      topic: '/remoteapp/tv/platform_service/MY_PHONE_MAC$normal/actions/picturesetting'
      payload: ' {"action":"set_value","menu_id":11,"menu_value":3,"menu_value_type":"int"}'
mode: single

This seems work well, and it’s fast since there is no polling/pinging. One little kink is that when the TV switches between HDR and SDR the power state momentarily registers as off, due to the AspectRatio menu_flag flipping to 1 during that 0.5-1s transition time between SDR-HDR.

You could have an automation trigger from the binary sensor going off. Have it reset a helper variable, pool a topic on tv to see if it gets a response (and then changes that variable’s value. If not changed then change your switch to off (and remove your if for if binary sensor off).

Can someone help, this doesn’t work at all for me with a 55U6G. I can’t get the remote now app to even see the TV, when I use openssl (installed on windows) I just get an error message, I’m just trying to get a simple mosquitto command to change power state working from windows, but it just refuses any commands.

On your TV, in the menu under Device Control, make sure IP Control Port is turned on.

Do you have your TV connected to your home network (and phone/device using remotenow on the same wifi network)?

What troubleshooting steps have you taken? have you verified you can ping the IP of the TV?

I am not sure if windows openssl will work.
Are you running HA OS on a pi, or as a docker on debian or how are running home assistant? should be able to run that openssl command from the terminal (from the OS, not from inside Home Assistant).

I apologize if this isn’t the proper place to ask, but it appears to be the biggest group of Hisense users on the forum, and I’m wondering if this integration can help in any way.

I can’t get my u6G’s to display cover art in any media player card. Has anyone been able to get this to work or is it a limitation of these TV’s? It appears they are trying to display but on certain media cards (mushroom) it give a broken image icon. My understanding is that at least some apps (disney+, Hulu, Netflix) should be able to supply screen scrapes of what is being shown. I can get cover art from other sources (i.e. my Echo’s when playing music).

The integration instructions I provided in here does not correlate to a Media Player in HA.

I would first try setting up a generic Android TV integration and then see if its Media Player card works for you (fyi things like the power button wont work without custom configuration).

If that does not work then you will need to setup MQTT explorer and see if there is even info/thumbnail output in the MQTT
If there is MQTT data for it: then you can subscribe to the proper topics in the HA config file, then use the universal media player card to create your own. I have never used the universal media player so I have no experience on setting it up.

On an unrelated note, what kind of car is your Turbo4Door? I have a Stinger GT.

1 Like

Thanks for the reply. All the other controls work as expected, so that’s why I’m a little thrown off as to why this particular aspect doesn’t work. Unrelated, it was a Subaru WRX. Unfortunately it’s now gone to someone else after many years and mods with me :slight_smile:

Hi all, I have a U6G and I’m really struggling to get Mosquitto (official HA addon) connected to it. I can connect to the TV in MQTTX (desktop app) using the same hisense.crt file I’m attempting to use here as my CA file.

Here is my hisense.conf file that’s being loaded by Mosquitto:

connection hisensemqtt
address 192.168.1.218:36669
username hisenseservice
password multimqttservice
clientid HomeAssistant
bridge_cafile /share/mosquitto/hisense.crt
bridge_insecure true
bridge_tls_version tlsv1.2
try_private false
start_type automatic
topic /remoteapp/# both 0 office ""

(Note that I’ve tried using my phone’s MAC address as the clientid, it didn’t make a difference to the below.)

In the Mosquitto logs, there’s this over and over:

1661376365: Connecting bridge (step 1) hisensemqtt (192.168.1.218:36669)
1661376365: Connecting bridge (step 2) hisensemqtt (192.168.1.218:36669)
1661376365: OpenSSL Error[0]: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
1661376365: Client local.HomeAssistant disconnected: Protocol error.
1661376378: Connecting bridge (step 1) hisensemqtt (192.168.1.218:36669)
1661376378: Connecting bridge (step 2) hisensemqtt (192.168.1.218:36669)
1661376378: OpenSSL Error[0]: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
1661376378: Client local.HomeAssistant disconnected: Protocol error.
1661376384: Connecting bridge (step 1) hisensemqtt (192.168.1.218:36669)
1661376384: Connecting bridge (step 2) hisensemqtt (192.168.1.218:36669)
1661376384: OpenSSL Error[0]: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
1661376384: Client local.HomeAssistant disconnected: Protocol error.

Again, this same crt works when I use it from a desktop MQTT app. Here is the connection configuration in the MQTTX app that works:

I cannot figure out what the problem is and I’ve been banging my head on this for hours. If anyone has any suggestions, I’d appreciate it.

Few things I noticed.

  • You put the ca file in a different directory than the ssl folder.
    If I remember correctly that does make a difference in HA processing it.

  • For topic (in your .conf file) you did not put in the + wildcard at the beginning (which is needed), also not sure why at the end you have: 0 office ""

clientid needs to be the id of a device that is already authenticated on the TV. This is why you have to use remotenow initially. Since that mqttx_76a978fe works then that MIGHT work for you.
Also did you read about having android use real mac address on wifi connection when doing the remotenow registration/authentication with your TV?

You also did not mention if you verified your mosquito broker config, nor if you copied both keys to the .crt file.

I tried moving it to /ssl/hisense.crt, that didn’t resolve it.

I’ve set it up that way per the documentation for the Hisense TV integration I’m trying to use; because I have multiple Hisense TVs I need a prefix. Whether or not this part is correct I’m not sure, because I can’t get past this SSL protocol error.

I’m not sure what you mean by verified the broker config…I use Mosquitto for lots of other things, and it works, if that’s what you mean. I just have not been able to get it to bridge to the Hisense TV.

Solution: I didn’t have both keys in my crt file – just the first one. I think I had been following someone else’s guide earlier, and got it to work in my desktop MQTT app with only the one cert in that file and stopped there. Figured since an MQTT desktop app could connect using that CRT file, so could Mosquitto. Nope! Once I added both keys to the CRT file, I stopped getting errors in the Mosquitto log and successfully observed remote events on the TV in MQTT Explorer:

image

Looks like my topic prefix is working too.

Thanks for your help @jeremylee_7 !

Well, I might not be completely out of the woods. Without touching anything, it stopped working sometime overnight, my logs are filled with the same protocol error, and the TV won’t respond/doesn’t communicate through the MQTT broker. I restarted Mosquitto, and now it’s working again, without changing any configuration.

Haven’t been able to explain why it would stop working.

EDIT: It’s consistent. It works fine for a few minutes after a Mosquitto restart, then it breaks and fills the log with the same protocol error as in my previous post. How can it handshake at first, and then break?

Good Day

I have downloaded and installed your repository however I am struggling to obtain the .cert file for my hisense tv. I have followed the documentation from other sites but it just does not work. Any guid from your side perhaps? Any help will be highly appreciated.

Downloaded my repository? I posted examples of what to put in the files, but I never put the files into a repository.
Are you referring to the github link? If so that was to provide credit for another user’s work that enabled me to then figure out the newer TVs. If you downloaded the files from the other user’s repository, then they will not work to connect to U6G/U7G/U8G models.

The fullchain.pem and privkey.pem from step 5 of my instructions should have already been made by the mosquito broker addon in Home Assistant.

You get your TV cert keys using the command in step 6.

openssl s_client -host TV_IP_ADDRESS -port 36669 -showcerts

This needs to be done on a computer with linux OS. This will not work from a terminal within Home Assistant. If you are running HA in docker or python then you can use a terminal from the linux OS. Otherwise you will need to run this command from a completely different computer. If you dont have linux on any other system then you can run linux in a VM or as a “live cd” on any windows PC.

Then use the template from step 8 of my instructions, paste the certs output into it and save it as hiseense.crt and put that file in the /ssl/ folder on your HA samba share.

I was going to implement your scheme for detecting power on/off state but my TV doesn’t have that particular topic, nor one that matches the JSON.
But I found that another topic has statetype of ‘fake_sleep_0’ when the TV is off so I just amended Jeremy’s template getting rid of the device tracker, which didn’t work for me either, and replaced it with

mqtt:
  sensor:
    - name: "TV - State Type"
      state_topic: "/remoteapp/mobile/broadcast/ui_service/state"
      value_template: "{{ value_json.statetype }}"

and the template in Jeremy’s code (the hisense_tv switch) became

          {{ not is_state('sensor.tv_state_type', 'fake_sleep_0') }}

Seems to work for me, with the UI switch correcting itself to on after a few seconds.
My TV is a new (Jan 23) 50A7HQTUK (Curry’s - UK)

Glad you found something that works for your TV. These little (but highly relevant) discrepancies between models sure is getting annoying.
I will try to stay on top of putting info/links in the top thread in order to infortm others.

Hi, your Step 4. I don’t have a /share/mosquitto/. I have share when samba into home assistant, but no subfolder called mosquitto. I do have MQTT running as I use it for Zigbee2mqq devices.

Are you using Mosquito broker for MQTT or are you using a different addon/plugin?

Using Mosquito broker. I had to create a folder in the share called mosquito in the end.

Eventually last night, using your initial post insight, I used a very different method to your steps (in case anyone comes across this) to get my Hisense 65u8hqtuk into Home Assistant with control.

No need for remotenow and known devices or the other stuff you mentioned in Yaml. (Though I did learn a lot about MQTT explorer because of your post, thank you!)

Post by Neeeb resolved it for me Hisense TV Control - #242 by NeeeeB