Skip to main content

Home Assistant, ESP 8266 and Ultrasonic Sensor to Pause & Play TV

I have two kids (dragon!) in my home. With a lot of fun, I have a lot of stress too. One particular area of concern is their screen time. 
In many cases I found my kids goes near to the TV and with the excessive joy they have, they don’t know they are very close to it. 
As a modern day’s parent, I must tackle this issue and I did that using home assistant.

Objective:

To pause the TV playback while someone is near to the TV. Resume the playback while no-one is too close to the TV.
This case my kids shall not watch the TV while they are near to it. So once they are near, it will pause the playback and will resume while they are a bit far from the TV.

List of tools I used

  1.  NODE MCU ESP8266 (Link)
  2.  Node MCU Development Kit V3 (Link)
  3.  Ultrasonic Sensor (HC-SR04) (Link)
  4.  BroadLink RM Pro (Link)
  5.  Home Assistant (Link)
  6.  ESP home (Link)

 
Process Followed:
  1.  Use ESP8266 on NodeMCU board with power adapter
  2.  Use ESP Home to configure ESP8266 for Ultrasonic Sensor
  3.  Learn RF code for play and pause from remote on Broadlink RM Pro and convert those         code to BASE64 for home assistant
  4.  Write an automation code for Play/Pause based on the Ultrasonic Sensor Data
  5.  Testing and fixing the sensor on TV unit

ESP Home Code

sensor:
  - platform: ultrasonic
    trigger_pin: D1
    echo_pin: D2
    name: "Ultrasonic Sensor"
    pulse_time: 10us
    timeout: 20m
    update_interval: 2s


Home Assistant Automation Code:

alias'TV to Human Distance is Low'
  trigger:
    - platformnumeric_state
      entity_idsensor.ultrasonic_sensor
      below1.2
      for:
        seconds3
  action:
    - serviceswitch.turn_on
      entity_idswitch.tv_pause
    - delay'00:00:01'  
    - servicetts.google_say
      data_template:
        cachetrue
        entity_idmedia_player.googlehome0666
        message"Hei kids, don't stand infront of the TV. Go back to Sofa"        
    - delay'00:00:15'
    - serviceswitch.turn_on
      entity_idswitch.tv_play


Home Assistant Switch for Broadlink:

      tv_play:
        friendly_name: "TV Play"
        command_on: 'JgBmAE4UFBQoExQUnFBQTQoExQTKBQUExQUJwANBQAA'

      tv_pause:
        friendly_name: "TV Pause"
        command_on: 'JgBmAE8UKBBMoFCgTFBMUFCgTKBMoExQxUTKAANBQAA'






Comments