How To Automatically Show Security Feed on any TV with PIP

lucky
Tags: #<Tag:0x00007f0156891580>

(Lucky) #1

This how-to shows how to automatically show your security camera feed to your TV. In this tutorial, I am using a Samsung TV, but should be applicable to other TVs with minor changes here and there. I am also using Orange Pi

Flow (Super quick summary):

  1. Camera motion triggered -> Send to openHAB
  2. openHAB triggers PIP on TV
  3. PIP video feed comes from the Orange Pi through the COAX cable.

SOME NOTES

For my TV (and any other TVs I have owned), you can only PIP with a digital signal and an analog signal. In the case of my TV, the primary display is the HDMI feed, and the PIP display comes from the COAX feed. Most TVs work this way. I still yet to find and own a TV that PIPs two HDMI signals at once.

I have been asked many times (forum, and in person) how I am able to do this Automatic PiP. My initial setup was actually different than this HOW-TO. Instead of using Samsung TV Binding, I am controlling the PiP using my Samsung TV’s EXLINK port. The EXLINK port is a support/developer port in RS232 (UART). I have an ESP8266 connected to this UART port using correct TTL levels. Whenever I explain this to whoever asks, they have no idea what I am talking about. So I recreated the Automatic PIP on my other TV, but instead I am using Samsung TV Binding as demonstration/POC.


1. Requirements

A. Hardware

Note: Get them wherever you can get them the cheapest. I already had them laying around. I just went to Amazon for a quick search and pasted the first link I could find so you know which ones I am talking about.

  1. Samsung TV
  2. (OPiZero) Orange Pi Zero
    I am using Orange Pi zero since it’s more lightweight than the bigger Raspberry Pi. It also has an ethernet jack unlike the rPi zero.
  3. Orange Pi Zero Expansion board (OPTIONAL) such as this
  4. Video to CoAx such as this
  5. 3.5mm RCA cable such as this
  6. Camera with a network-based stream (RTSP, H264, MJPEG, etc)
  7. Micro SD Card for your OPi

B. Software

  1. Armbian for Orange Pi Zero
    Or any ARM-based OS that can run on the orange pi
  2. Desktop Software for your hardware. I used XFCE
  3. Chromium for ARM
  4. OpenHAB Samsung TV Binding
  5. Blue Iris (Optional)

2. Setup

A. Software

  1. Flash your OPiZero with the armbian image
    a. Enable SSH

  2. Install XFCE

  3. Install Chromium

  4. Add Chromium to automatically start on boot
    a. Parameterize chromium with your Blue IRIS stream URL
    Now, whenever your OPiZero starts/boots, it should open chromium and display the feed.

    Notes:
    For my setup, I am not just using a blue iris feed, my URL points to a small web page with a few scripts. This small web app has a websocket connection to OH to trigger what shows on the web page. For example, based on a rule, instead of displaying the feed, I display a caller ID whenever someone calls. If you are not familiar with javascript/web, I suggest just using HABPanel as the URL for step 2.A.4.a. This is optional. You can always just use your webcam/blueiris feed.

    You can also use something else than chromium. I was initially using mplayer to play the Blue Iris stream on a headless OPiZero, but I figured chromium is better since I can easily create the web page.

Setup/How-to

  1. Install and Configure your Samsung TV Binding
    a. Properly link channels

  2. Security Camera is triggered through my Blue Iris Server
    a. Configure your camera(s)

  3. Configure Blue Iris or your camera to send a post when triggered.
    Blue Iris sends a POST request to my OpenHAB when triggered:

    image

    You can use MQTT if you have the latest version of Blue Iris

tv_pip_frontdoor_motion is just a Switch Item:

3. Items

Group:Switch gTvPip "TV PiP" (All)
Switch tvpip_familyroom_switch "TV PiP FamilyRoom" (gTvPip)
Switch tvpip_familyroom_switch_noscript "(noscript) TV PiP FamilyRoom" (gTvPip)
Switch tvpip_frontdoor_motion "TV PiP FrontDoor Motion" (gTvPip)

tvpip_familyroom_switch_noscript is just another item I can toggle without triggering any rule.

Some caveats with Samsung TV Binding
When you send a PIP command, you cannot tell if it was successful or not. Usually it is. The issue here is that if there’s any timing issue with your Blue Iris or you already have the PIP on. What happens is BlueIRIS will still send the POST request, OH will issue the PIP command, and PIP will instead turn off (assuming PIP was already ON). With EXLINK, when you send a PIP, it gives you feedback/response through the UART port. The issue is mitigated/handled by the rule.

4. Rule

Note how we do not process the OFF state. We do this in a timer. This way, our item can receive multiple "ON"s and we only process it if the timer is not running already.

tvpip_familyroom_switch is used by my HABPanel.

var Boolean isRuleEnabled = true
var Timer autoPipOffTimer = null
val autoPipOffTimerSeconds = 30
var Boolean isIgnoreCommand = false

rule "TV PIP On Off"
when
	Item tvpip_familyroom_switch received command
then
	if (isRuleEnabled) {
		sendCommand(samsungtv_tv_familyroom_keyCode, "KEY_PIP_ONOFF")
		if (receivedCommand === ON) {
			logInfo("TVPIP", "Received ON. Will turn off in " + autoPipOffTimerSeconds.toString + " secs.");
			if (autoPipOffTimer !== null) {
				autoPipOffTimer.reschedule(now.plusSeconds(autoPipOffTimerSeconds));
			} else {
				autoPipOffTimer = createTimer(now.plusSeconds(autoPipOffTimerSeconds), [|
					if (tvpip_familyroom_switch.state == ON) {
						tvpip_familyroom_switch.sendCommand(OFF);
						logInfo("TV PIP", "Auto Off")
					}
					autoPipOffTimer = null;
				]);
			}		
		}
	}
end

rule "TV PIP Frontdoor rule"
when 
	Item tvpip_frontdoor_motion changed to ON
then
	sendCommand(tvpip_familyroom_switch, ON)
end	

rule "TV PIP On Off (NO SCRIPT)"
when
	Item tvpip_familyroom_switch_noscript received command
then
	sendCommand(samsungtv_tv_familyroom_keyCode, "KEY_PIP_ONOFF")
end	

I highly recommend everyone to use isRuleEnabled as I did above. This allows me to enable/disable a rule with just a variable value change.

The BlueIRIS “OFF” configuration (screenshot above) is for demonstration purposes only. My OH do not process the OFF at all. I do this from the rule above… But I can see this useful for other people. BlueIRIS can send a POST request once the motion has “ended”

5. Hardware Setup

  1. Attach your 3.5mm cable to orangePi TV OUT jack
  2. Attach the other end of this cable to your CoAX converter
  3. Attach coax to your tv coax.
  4. Test pip work (even without signal)

Notes on hardware

I am not using a converter. I made my own. Note that coax is expecting RF signal. Im also not using the orange pi expansion board, I soldered mine to the orange pi pins (GND and pin 13)

If your TV does not currently have an OH binding, and your TV does not have a developer port, you can still automate PIP using an infrared remote module. I did this on my old TV in the garage using ESP8266 and some IR emitters.

Any questions, feel free to post


How big is your system? (NO HELP NEEDED) {CHAT}
How big is your system? (NO HELP NEEDED) {CHAT}
OrangeAssist - Google Assistant Integration
(Rune) #2

Quite a teaser :slight_smile:


How To: Integrate Your Home Phone with OpenHAB
(The Squid) #3

Wow…it must be a novel of a write up! :stuck_out_tongue_winking_eye:

Count me in as interested…when do you hope to have it posted?

Squid


(rud) #4

Great!

Me too …


(Arnaud) #5

Hello,

I’m interestested too

Regards


(The Squid) #6

@luckymallari

Any update on this???


(Salexes) #7

I would love to use this for my tv as well, hope the guide will be posted soon


(Marcus) #8

Any update on this???


(Skinah) #9

Not sure how lucky is doing it but maybe this link gives you some clues.

http://www.vrsho.com/doorbell-home-automation-kodi/


(Lucky) #10

Updated the HOW-TO. And @matt1, nope, no KODI here :slight_smile:


(Vincent Regaud) #11

I do. My KEY_PIP_ONOFF command only opens a dialog and I would love to access the PIP in one go.
Could you share that set-up, please?
I don’t mind a PM.
I have a spare ESP board
I have a TTL level converter
Would love to see more details, thanks


(Lucky) #12

Try this instead if KEY_PIP issue KEY_PIP_ONOFF

I’ll see if I can write the uart part how to but basically, you enable uart in the TV’s service menu (mine is mute 1-8-2-power while off). The pip command is actually a hex code you send to the uart.


(Vincent Regaud) #13

Sorry typo. Just gives me a dialog, then I have to press OK then DOWN then OK then 6 times DOWN then OK
to have the PIP. Same again to remove it