Hisense TV Control

Ah. I did not know about this. I will look into using this in HA.

With my current setup, I went back to using Nodered instead of the bridge.
No idea why, but my TV would turn off immediately after connecting to HA upon powering on. But powering on a second time within ~10 seconds of it turning off, it would stay on. And it would turn on in the middle of the night… No idea how, nothing was sending wake on wireless. Couldn’t be bothered troubleshooting.

Hi,

I am trying to connect my TV to Hassio, but I do not understand what I should do.

Would anyone have wanted the generosity to do a little tutorial of what to do? My goal is to be able to subsequently control my TV either via Hassio if I can’t fully implement this in jeedom or to have it back up between Jeedom and Hassio. (See Keeping only Hassio afterwards and no longer keeping Jeedom).

Thank you in advance for your feedback.

@vouvrat I have been meaning to do the same sort of thing myself.

I updated the hisensetv python package with a pip release to make it easier to use, and I created a power toggle in home assistant with appdaemon.

yaml configuration:

input_boolean:
  tv: 
    name: TV
    initial: off

Contents of tv.py, (needs hisensetv and wakeonlan in a requirements.txt)

import hassapi as hass
import socket
from hisensetv import HisenseTv
from wakeonlan import send_magic_packet


class TV(hass.Hass):
    def initialize(self):
        self.tv_hostname = "10.0.0.28"
        self.tv_mac = "ff:ff:ff:ff:ff:ff"
        self.log("initialize called")
        self.listen_state(self.power, "input_boolean.tv")

    def power(self, entity, attribute, old, new, kwargs):
        self.log(f"power called, {old=}, {new=}")
        if new == "off":
            self.log("turning TV off")
            try:
                with HisenseTv(self.tv_hostname) as tv:
                    tv.send_key_power()
            except socket.error as e:
                if "host is unreachable" in str(e).lower():
                    self.log("unable to reach TV, likely powered off already")
                else:
                    raise
        elif new == "on":
            self.log("sending magic packet")
            send_magic_packet(self.tv_mac)
        else:
            self.log(f"unknown state {new!r}", level="ERROR")

Can you released it noob proof? :stuck_out_tongue:

I’ll see if I can get it into a custom_component integration.

1 Like

Alrighty, here is the noob-proof version: https://github.com/newAM/hisensetv_hass

Fair warning, I myself am a noob at writing home-assistant components.

If there is enough interest I can look into getting volume, source selection, ect. into this custom component as well, then maybe into home-assistant itself.

7 Likes

Thank you!

So I’m kinda stuck at the beginning, anyone got any ideas to give me a push?

I have MQTT Explorer downloaded to my laptop and I’m trying to create a new connection to my TV as a proof of concept before I attempt to integrate into home assistant.

My settings are as follows:

  • Host: 192.168.XXX.XXX
  • Port: 36669
  • Username: hisenseservice
  • Password: multimqttservice
  • Encryption (tls): ON

If I use the validate certificate option:

  • Validate Certificate: ON
    I get a connection refused error.

ECONNREFUSED

If I do not use the validate certificate option:

  • Validate Certificate: OFF
    I get a disconnected from server error

Disconnected from server

I’m at a loss as to where to try next. I tried to install the Hisense app on my phone, but it wouldn’t even connect to my TV.

Service Code: HU65K5503UW
Software Version: V0000.01.00a.J0730

Anyone got any ideas why that’s happening? My first guess is wrong username/password combo, but is it possible that it might be the certt they’re using since it’s self signed?

Yes please!

1 Like

Thanks for this! What’s it called on HACS, I’ve tried searching for Hisense but getting no results?

1 Like

You need to add this as a new repo in HACS. Go to the setting page and under CUSTOM REPOSITORIES add https://github.com/newAM/hisensetv_hass as an integration repository.

2 Likes

That would be truly amazing!

Source Selection would be great. My Harmony Hub can’t change the sources correctly. :blush:

1 Like

Can you please share you configuration and template for the Hisense TV?

I have installed the python file and can connect to the TV now need to have it in the lovelace hi

Thank you

Here are some of the MQTT commands I’ve found to work on my TV, the 55H8G. Source and app selection works well, although I had to capture it from the RemoteNOW app. Button presses work well, especially if you’re building a remote in the UI. It seems as if MQTT commands get put into a queue if you issue them while the TV is in standby (as in, not completely powered off), and they’ll get executed once the WOL packet is sent.

Button presses are as follows. These work over CEC.

/remoteapp/tv/remote_service/XX:XX:XX:XX:XX:XY$normal/actions/sendkey

Power = KEY_POWER
Back = KEY_RETURNS
Menu = KEY_MENU
Exit = KEY_EXIT
Pause = KEY_PAUSE
Play = KEY_PLAY (play and pause work the same)
Stop = KEY_STOP
Up = KEY_UP
Down = KEY_DOWN
Left = KEY_LEFT
Right = KEY_RIGHT
Fast Forward = KEY_FORWARDS
Backwards = KEY_BACKWARDS
Home = KEY_HOME
Back = KEY_BACK
Menu = KEY_MENU
RGYB Buttons = KEY_RED, KEY_BLUE, etc.
Numkeys = KEY_0, 1, 2, 3, etc.
Channeldot = KEY_CHANNELDOT
Channel Up = KEY_CHANNELUP
Channel Down = KEY_CHANNELDOWN
Closed Captions = KEY_CC

For app launching, here’s an example MQTT publish and the JSON for it. This launches the app immediately, from every screen and input I could try.

/remoteapp/tv/ui_service/XX:XX:XX:XX:XX:XY$normal/actions/launchapp

{
  "appIcon": "",
  "appId": "",
  "has_detail_page": 0,
  "isLocalApp": 1,
  "name": "Plex",
  "storeType": 0,
  "type": 0,
  "url": "com.plexapp.android",
  "urlType": 0
}

Sources basically work identically to the app launching. You can just copy and paste the JSON and change HDMI 1 to the other numbers, they’re identical. I don’t use OTA or cable TV, so I cannot test channel inputs, though it would probably work okay with the remote codes above.

/remoteapp/tv/ui_service/XX:XX:XX:XX:XX:XY$normal/actions/changesource

{"displayname":"HDMI 1","hotel_mode":"","isDemo":false,"is_lock":"","is_signal":"","sourceid":"3","sourcename":"HDMI 1"}

Volume changing took a bit, because I just couldn’t understand how it worked. This is partially due to me using ARC, it doesn’t allow for arbitrary volume settings, only +1 or -1 per MQTT publish. If you’re using TV audio, I would assume that the value you publish would be the new setting. The TV will always return a JSON response here, formatted like so. This allows you to get the current volume setting.

/remoteapp/mobile/broadcast/platform_service/actions/volumechange
{"volume_type":1,"volume_value":11}

Volume type appears to be TV Audio, ARC, or Bluetooth (on my TV), with a value of 0, 1, or 2.

This is not how you set volume, nor does sending remote codes seem to work consistently. The best way I’ve found is as follows.

/remoteapp/tv/platform_service/XX:XX:XX:XX:XX:XY$normal/actions/changevolume

Just send a value between 0 - 100 – no formatting needed. If you’re using ARC (at least in my testing), a value above your current volume will increment up by one, and down by one if you’re sending a lower value. If you’re not using ARC, it seems as if it just sets it to that volume. I have yet to find a way to mute with ARC, as I can’t find a key command that works as a mute button.

Here’s one I have yet to find actually useful, but it’s worth putting in here. You can send keyboard inputs, including delete, enter, space, and special characters. The formatting for some of the special characters does make sense (@ is SHIFT_2), but it’s unwieldy, to say the least. Here’s the topic.

/remoteapp/tv/remote_service/XX:XX:XX:XX:XX:XY$normal/actions/input

Here’s one that seems to list known channels, but like I said, I don’t use OTA antennas so YMMV.

/remoteapp/mobile/XX:XX:XX:XX:XX:XY$normal/platform_service/data/getchannellistinfo

This will return a JSON response with all installed apps, makes it easy to format the app changing commands above.

/remoteapp/mobile/XX:XX:XX:XX:XX:XY$normal/ui_service/data/applist

Here’s one for known sources

/remoteapp/mobile/XX:XX:XX:XX:XX:XY$normal/ui_service/data/sourcelist

That’s all I’ve been able to mess with the last day or two. Hope this helps someone out!

4 Likes

Is someone with a lovelace remote for hisensetv can share the yaml?

Hey foks - I thought I would share some additional information. It seems there is a way to get telnet and root access to the TV. requires you get UART connection to the service port.

I was poking around the moquitto config and found out that port 10001 is a mqtt websockets port if that helps anyone trying to integrate to the hisense tv.

1 Like

My Hisense 75P7 doesnt use TLS for MQTT and I cant see anything in the mosquitto directories with certificates. let me know if you need anything else off the tv. I have full root access.

Hi.

Every time the TV is off, the mosquitto broker gets this constant error, filling the log to a huge one after some hours.

1592744733: Connecting bridge hisensemqtt (192.168.5.6:36669)
1592744736: Socket error on client local.HomeAssistant, disconnecting.

Is there a way to avoid showing this error or maintaining the TV mqtt broker accessible?

Thanks.

This is my successful experience getting this to work, with a TV Hisense H43B7320, with its firmware version V0000.01.00a.K0117.

In: https://github.com/tiagofreire-pt/tv_hisense_home_assistant/

1 Like