Control TiVo box over telnet


#162

I’ll update tomorrow and let you know I get on.

Really clever stuff with the guide - did you find an api? Documentation?

I was going to attempt to convert this to a component but you beat me to it


#163

Much as I’d love to take total credit, once I’d worked out from their source that Virgin was using another company for the listings I was able to utilise this:

http://webgrabplus.com/content/hoizontv-all-countrys

That was enough to give me the general URLs to access the guide which was the bit I couldn’t work out. I then needed to work out the Virgin specific calls, which was just trial and error since they aren’t published anywhere. The results are returned as standard JSON, so dead easy to convert to Python objects.

I’ve exposed most of the info as attributes on the Tivo object. There are a couple more I haven’t included but could do if anybody ever wants them. The obvious ones are long description, type of program (e.g. Game Show), adult (ooh er missus), actors, director (seems to be always blank though even for movies) and first air date / year.


#164

I notice that when I turn on my virgin box from home assistant I cannot turn it off and also I cannot control it either. Do you have similar issues?


#165

No, seems to work ok for me. Can you give me more details about what you’re seeing?

  • When you say you cannot turn it off again, do you mean via HA or via the remote?
  • And by control, again do you mean via HA or via the remote?
  • When the box is already on (not via HA), are you able to control it/turn it off?
  • Any errors being reported in the logs?
  • Is it a V6 or original Tivo?

#166

That last update has made it slower mate. There’s definitely an issue around priorities still.

If I use you component from the offset, all is good. If I then want to use my other telnet switches, it doesn’t do anything for 10 seconds, then finally cones in to life!

If I do it the other way with mine first, the sane happens. I can turn the box on/off using your component but as long as I haven’t initiated another telnet connection using my other switches.
In fact, everything works well. Up until I use my other switches …

I’m going to comment out the interval again


#167

It’s fine now iv commented that out from first glance - ill test more.

Also, can you add a play pause button like the other media players? Be good to see if a show was paused aswell…

Can you access the recordings and show what’s being played?

Last channel button? :ok_hand:


#168

I’ll try setting up a telnet switch here to see if I can work out what is going on. Not sure why there would be a problem though - when I’ve changed keep_connected, I can consistently telnet on from a command prompt which is what I’d expect. Never simple…

On the play/pause bit, the component does support the functionality and you can call media_player.media_pause and media_player.media_play. No friggin’ idea why the button doesn’t show. I’ll have a look at it too.


#169

I created an E4 telnet switch as per your example and it works fine for me. Instantly switches and doesn’t cause any blocking. The 10 second thing is strange. The telnet switch should only poll every 30 seconds and won’t if you haven’t defined a state. My component would poll every 10 seconds if switch_interval wasn’t set to something else. Might be worth sticking debug on my component and see if we can get any more info on it. Or maybe send me all your Tivo telnet switches and I’ll check them all in case one is causing a problem.

To add debug stick this into your configuration.yaml:

logger:
  logs:
    custom_components.media_player.virgintivo: debug

I’m afraid I can’t access the recordings as far as I know. Once my Tivo isn’t on live TV, it seems to reject telnet connections. If you know of any way of determining what is actually happening (e.g. http call or something) I can certainly add it.

I could add a last channel service (I think) but not sure how I’d add an extra button to the media player component. I’ve stolen the last/next track buttons for the +1 channel functionality. I could possibly make that a switchable function, i.e. you decide whether you want the +1 functionality or the last channel functionality.


#170

Or just cut to the chase and move to template switches. Might be easier. For example:

switch channel_28:
  platform: template
  switches:
    e4_virgin:
      friendly_name: E4
      value_template: "{{ is_state_attr('media_player.virgin_tivo', 'source', 'E4') or is_state_attr ('media_player.virgin_tivo', 'source', 'E4 HD')}}"
      turn_on:
        service: media_player.select_source
        data:
          entity_id: media_player.virgin_tivo
          source: E4
      turn_off:
        service: media_player.select_source
        data:
          entity_id: media_player.virgin_tivo
          source: E4

#171

Doesn’t that check if the entity is on e4 or e4 hd, if its true, turn on e4? Think its round the wrong way…


#172

I’m not at home to double check, but reasonably sure that what this does is set the value of the switch to on if the source is set to E4/E4HD or off if it is anything else. Turning the switch on will set the source to E4 regardless of what it is currently at. Turning it off also switches to E4, but that’s just because you have to have something in there.

Edit:

Just tried it out and seems to work ok. When Tivo is on ITV, the switch shows as off. When I change to E4 it shows as on. When Tivo is on ITV and I turn the switch on, it goes to E4. I’ve also made a minor change to make it a wee bit easier. I’ve added in a new attribute, base_channel_name that can be used in the state test. It will always show the SD version of the channel, e.g. E4 rather than E4 HD so you don’t need to test for both. I.e

switch channel_28:
  platform: template
  switches:
    e4_virgin:
      friendly_name: E4
      value_template: "{{ is_state_attr('media_player.virgin_tivo', 'base_channel_name', 'E4') }}"
      turn_on:
        service: media_player.select_source
        data:
          entity_id: media_player.virgin_tivo
          source: E4
      turn_off:
        service: media_player.select_source
        data:
          entity_id: media_player.virgin_tivo
          source: E4

#173

Play/pause button now added


#174

I have added the latest version to my home assistant but i get an error while trying to run any commands against my V6 box…

Error executing service <ServiceCall media_player.select_source: entity_id=[‘media_player.virgin1’], source=Comedy Central>
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/core.py”, line 1021, in _event_to_service_call
await service_handler.func(service_call)
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/media_player/init.py”, line 441, in async_service_handler
await getattr(player, method[‘method’])(**params)
File “/usr/lib/python3.5/asyncio/futures.py”, line 380, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.5/asyncio/tasks.py”, line 304, in _wakeup
future.result()
File “/usr/lib/python3.5/asyncio/futures.py”, line 293, in result
raise self._exception
File “/usr/lib/python3.5/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/media_player/virgintivo.py”, line 678, in select_source
idx = self._channels[idx][CONF_HDCHANNEL]
File “/home/homeassistant/.homeassistant/custom_components/media_player/virgintivo.py”, line 361, in tivo_cmd
try:
BrokenPipeError: [Errno 32] Broken pipe


#175

Strange traceback. But the error indicates that the Tivo closed the connection. Try disabling the component and manually making a telnet connection to port 31339 on the V6 box. See if the connection stays up or whether you get kicked off.

Might be worth setting keep_connected to false and see if that improves things at all.


#176

Spot on. Just testing the play/pause stuff.

Any idea how we get this added to. 73?


#177

Tried the following on telnet from command prompt on my laptop:

Command Prompt> Telnet
Telnet> o
to 192.168.0.58 31339
Could not open connection to the host

Not sure if im doing that correctly though. I have also rebooted the tivo internet and pi.

The keep_connected just gives me timeout errors within the log

Is there any settings / changes i can make on the V6? Its connected via wifi, Not sure if that could make a difference.


#178

Had a quick google. For future reference

Home - Help & Settings - Settings - Devices - Network Remote Control - Allow Network-based remote controls

Opens the port needed.

Works a treat. Pause / Play works a treat as well.

Legend mate thank you!


#179

Iv tried the obvious commands for last channel but no luck yet. Let me know if you find anything.

Play/pause all good :+1:


#180

@pegatron89 look closer to home next time :wink:


#181

I’ll tell you now, 9 times out of 10 it’ll be something I’ve mucked up :smile:

Yeah, but it’ll take a while so unlikely to make it in for 73. It has to go through an approval and review process. Not sure that they would particularly want a Tivo component that is so locked to one company. At the moment I think I’m best concentrating on ensuring it works well and then seeing about getting it submitted. There’s no massive advantage for us compared to just having it as a custom component.

Don’t think there is one available, at least not documented. I was intending to just emulate one. I’ll do a bit more digging first just in case.