📜 ⬆️ ⬇️

Detection of the included TV using a photodiode

I have a TV bought for 8 years, NOT a smart TV, it does not have USB and Ethernet. Sometimes I turn it on to watch TV. And it often happens that I started watching a program, when suddenly I had to leave the house, got dressed, I was standing in my shoes in the hallway, and the TV wasn’t turned off! You have to take off your shoes (there is no need for shoes to walk around the room), you go into the room, you find the remote on the sofa, turn off the TV, go about your business. This situation happens often, so I decided to put an end to this and still make the button to turn off the TV in the hallway.



Table of contents:


Description of the Z-Wave automation system used


My house is partially automated by Z-Wave devices, among them several Z-Wave.Me Dimmer for smooth lighting control, a pair of Fibaro Universal Sensor as motion sensors to turn on the light, switches on batteries and a few more devices. An iPhone is mounted in the corridor near the entrance door to the wall , which is the Smart House control panel. From this panel you can see the temperature in the house and on the street, the humidity in the room, traffic jams and turn off the lights in the rooms.
')

Fig. 1 - Smart home control panel from iPhone 4

For the TV, I assembled an IR transceiver connected to the Raspberry Pi. Thanks to this device, I can control the TV using HTTP requests: turn on / off, change channels, change the volume, etc. But I can’t find out if the TV is on or off.


Fig. 2 - IR transceiver to control TV

The task that I had to solve was how to find out what the TV is on and how to transfer this information to the controller of the smart home RaZberry to work with it already within the framework of my home automation system. Briefly about my home automation controller.

For communication with Z-Wave devices, I use the RaZberry board installed on the Raspberry Pi.


Fig. 3 - Z-Wave RaZberry board on Raspbberry Pi

In the kit to the board is software for automation - Z-Way. Z-Way has a modular structure. One part of it is a proprietary library for working with Z-Wave written in C, the second part is the OpenSource automation engine Z-Way Home Automation (Z-Way HA) written in JavaScript. In addition to Z-Wave devices, Z-Way HA also supports any HTTP device, i.e. devices with which you can communicate HTTP requests. For the Z-Wave automation engine, devices and HTTP devices are no different. You can easily create an HTTP device that takes the weather with OpenWeather, and create an automation rule: If it's 30 ° C outside, then turn on the Z-Wave relay that controls the electric window opening.


Fig. 4 - The rule of automation in the system Z-Way HA

Using an HTTP device, I can add a TV to my automation system. You just need to understand what signal from TV to transmit via HTTP.
There are several options for how to detect that the TV is on:
  1. Modern smart TVs on Ethernet will tell you what you want (My TV has no Ethernet)
  2. Many TVs support CEC technology over HDMI (My does not support CEC)
  3. Some TVs in the off state on the USB output do not have power (My TV does not have USB)
  4. You can power the TV through the Fibaro Wall Plug - Z-Wave Rosette Module with energy measurement. The most convenient option for me, since I stay within the Z-Wave system. Easy to install, easy to detect the state of the TV, there is power consumption - the TV is on, there is no energy consumption - the TV is off (3000 p. Per module)
  5. Detect the LED status of the TV, which is on when the TV is off and not on when the TV is on (My choice!)

BPW34 photodiode-based TV detecting device


I decided to detect the state of the TV using an LED on it. I have a Raspberry Pi in front of the TV to watch a movie, I planned to connect the LED directly to the GPIO and thereby find out the state of the TV, but for this I had to remove the TV from the wall and disassemble it. I decided to go the other way.

To detect that the LED is on, I used a BPW34 photodiode, which works like a photodetector. To connect it to the Raspberry Pi, I first amplified the signal using the LM358 Operational Amplifier and then I sent the signal from the op amp to the GPIO. The scheme turned out simple:


Fig. 5 - Digital output photodetector circuit

Assembled device:


Fig. 6 - Photo detector connected to the Raspberry Pi

On the Raspberry Pi, I have already installed an IR transceiver and a humidity sensor with a screen; I attached a photo detector to the screen:


Fig. 7 - Installed Photo Detector on Raspberry Pi

An opamp selects approximately 1.5 volts from a 3.3 volt power supply. When the LED is lit, the output is 2 V, when it is not lit, 0 V. The Raspberry Pi takes everything that is greater than 1 V as a logical unit, so everything works as planned. I connected the device to the Raspberry Pi, and the photodiode attached to the TV using a double-sided black tape.


Fig. 8 - Photodiode connected to TV

Embedding a photo detector in an automation system using an HTTP Device


With the help of a photodetector, I can find out the state of the TV, and with the help of an IR transceiver I can control it. To transfer the status and control of the TV, I raised Apache to the Raspberry Pi and wrote 2 small cgi scripts, one script accepts HTTP commands and redirects them to IR, another script returns TV off or on status:

xbian@xbian ~ $ cat /var/www/cgi-bin/tvstatus.cgi #!/bin/bash echo "Content-type: text/json" echo "" STATUS=`cat /sys/class/gpio/gpio27/value` if [ "$STATUS" -eq "1" ]; then echo "off" else echo "on" fi 


In the Z-Way Home Automation automation system, I created an HTTP Device that turns the TV on / off and actually shows its state, i.e. If you turn off the TV with the remote control or the button on it, then in Z-Way HA I will see the real state of the TV.


Fig. 9 - Creating an HTTP Device in the Z-Way HA system


Fig. 10 - TV Widget on Dashboard

Why do you need to know the state of the TV? Besides, the same IR command is used to turn the TV on and off, and I only need to send a shutdown command from the panel in the corridor, because if you send a command to the TV when it is turned off, it will turn on.

Now, when I leave home, I press one button in the corridor - “Turn off everything”, and the teams disperse on different devices.

Source: https://habr.com/ru/post/237475/


All Articles