Determine power state via Device IP presence and then sync with homebridge

Hi guys,

I have a really crazy idea that seems straightforward in theory, but possibly not.

I have a dumb “smart tv” from Hisense running googleTV (worst decision ever) which has no CEC capabilities. I’m new to home assistant and running a straight Hass.io image on a Pi 2 - no VMs or the like.

I’m very excited by the homebridge integration have having Siri turn on my TV with my Broadlink RM mini 3. That part works well.

I’m wondering if there is a way that I could poll my network and if a specific IP address is found (that correlates to my TV), then mark the TV as being powered on. The desired end result would be that when I switch on the tv via remote then ask Siri or other to turn it off from it’s HA known on state.

I have just straight up commands for ‘tv off’ but I’m wondering if I can make it smarter.

(This also assumes there is no network connection while in standby).

Similarly, the CEC scan will tell me the power state of my connected Apple TV 4 - is there a way to sync this with the switch/homebridge power status. I currently use a play IR code to turn on the Apple TV.

Please excuse any ignorances - very new to this work and coding skills are mild.

Thank you :slight_smile:

Lint

This might work

thanks @RobDYI, that triggered my memory that I could possibly use the known devices from my router which is now setup.

So I think I can now rephrase my question - perhaps I should start a new thread but hopefully someone can help.

I can tell when tv is on or off by using known devices presence detection. The dashboard will show Home/Away.

So, how can I toggle my switch status from the home/away status of a device without actually firing the switch?

My very basic switch looks like this:

switch:

  • platform: broadlink
    host: xxxxx
    mac: ‘xxxxxx’
    timeout: 30
    switches:
    tv_power:
    friendly_name: “TV”
    command_on: ‘JgBYAAABJ5MVERQRFBASExMSFBAVEBUPFTYTNhU1FTUUNhU1ExEUNhU1FRAUNhE4FRAVEBQRFBASExQ2FBEUERM2FTUUNRU1FgAFigABJ0oSAAyKAAEnShIADQU=’
    command_off: ‘JgBYAAABJ5MVERQRFBASExMSFBAVEBUPFTYTNhU1FTUUNhU1ExEUNhU1FRAUNhE4FRAVEBQRFBASExQ2FBEUERM2FTUUNRU1FgAFigABJ0oSAAyKAAEnShIADQU=’

My Known device has these properties:

android2b5bffd25dce6c48:
hide_if_away: false
icon:
mac: xx:xx:xx:xx:xx:xx
name: HISENSETV
picture:
track: true
vendor: Liteon Technology Corporation

Thank you :slight_smile:

1 Like

I did basically the same thing that you’re looking to do. I’m using the device_tracker component with my Unifi controller, so the Nmap link from above may be a good option for you.

Then, once you have your device tracker set up, you can use a switch template like below. I had to do this because the Apple TV has it’s quirks with integrating well.

switch hisense:
  - platform: template
switches:
  lrtv:
    friendly_name: "Living Room TV"
    value_template: "{{ is_state('device_tracker.784561a469e2', 'home') }}"
    turn_on:
      service: remote.send_command
      data:
        entity_id: remote.atvlivingroom
        command:
          - top_menu
    turn_off:
      service: remote.send_command
      data:
        entity_id: remote.atvlivingroom
        command:
          - top_menu
          - top_menu
          - top_menu

https://home-assistant.io/components/switch.template/

If you’d rather not use Nmap, doing a ping sensor works pretty well, too. But I like the tracker better myself. You’d just need to change the switch template’s value template to reference the state of the binary sensor.

binary_sensor ping:
  - platform: command_line
    command: ping -c 5 10.10.11.50 &> /dev/null && echo success || echo fail
    device_class: connectivity
    name: HisensePing
    payload_on: "success"
    payload_off: "fail"
    scan_interval: 45

I’m looking to do a similar thing here. I am using a Broadlink pro to create a switch that blasts IR codes to turn my TV on and off. I am using the Netgear presence detection to determine whether my TV is considered on / off (e.g. home / away). However, I am having trouble understanding how to create the markup using the data template as suggested.

My original switch that turns the TV on / off is as follows:
switch:

  • platform: broadlink
    host: 192.168.0.13
    mac: ‘34:EA:34:8E:F8:53’
    timeout: 15
    switches:
    lv_ac_power:
    friendly_name: “Living Room AC”
    command_on: ‘JgD2AGw1DgwPDA8nDgwPJw4NDgwPDA8nDicPDA4NDgwPJw8nDgwPDA8MDg0ODA8MDwwODQ4MDwwPDA4NDgwPJw4NDgwPDA8MDwwODA8MDycODA8MDwwPDA4NDicPJw4nDycOJw8nDgwPDA8MDycODA8MDwkRDQ4MDwwPDA4NDicPJw4MDwwPJw4MDwwPDA8nDicPJw4MDycODQ4MDwwPDA4NDgwPDA8MDwwODQ4MDwwPDA4NDgwPDA8MDg0ODA8MDwwODQ4MDwwPDA4NDg0ODA8MDwwODQ4MDwwPDA4NDgwPDA8MDgoRDA8nDigOJw4oDgwPJw4NDgANBQAA==’
    command_off: ‘JgBmAGw1Dg0ODQ0oDg0OJw4NDg0ODQ4nDCoODQ0NDg0OKA0oDg0ODQ0NDg0ODQ4NDgwODQwPDg0ODA4NDg0OKAwODg0ODQ4NDQ0ODQ4NDicNDg4NDg0MDg4oDg0ODA4NDg0ODQ4NDQANBQAA==’

    tv:
    friendly_name: “TV”

    command_on: 'JgBIAAABKZIUEhMSEhMSEhMSExITEhMRFDcTNxM3EzcTNhQ3ExITNhM3FBEUNxI3ExMSExISEBUTEhM2FBISExM2EzgTNhM3FAANBQ=='
    command_off: 'JgBIAAABKJQTEhMSEhMQFBMSFBETEhMSEzcTNxM3EzcTNxM3EhMTNhQ3ExEUNxI3FBISExISEBUSExM2FBISExA5FDcTNhM3FAANBQ=='
    

I have tried adding the following data template but no longer actually triggers the IR code. Any help or suggestions:

  - platform: template
switches:
  tv:
    friendly_name: "TV Auto"
    value_template: "{{ is_state('device_tracker.android8a5c0356b935db84', 'home') }}"
    turn_on:
      service: switch.turn_on
      data:
        entity_id: switch.tv            
    turn_off:
      service: switch.turn_off
      data:
        entity_id: switch.tv

@mattinatux

as it is a rf switch. so it don’t display the actual state of the switch whether on or off. Especially, when you physically turn on/off the switch manually.

If you turn on/off through HA, this show from frontend, however if you restart HA or physically turn off from switch manually you lost the original status of the switch again. So if you want to track the status, template switch doesn’t give you what you want as well.

Presence detection is worth doing to track device with ip address or mac address but RF switch or RF device doesn’t have ip and mac address. So we cannot use their status home or not_home to detect.

I struggled for a few hours to get this setup, I wish I had found this post earlier. I using the presence detection to track the state of my hisense fake smart tv (never buy hisense). Using the template it took awhile for me to figure out that you can change the home not_home state to on off. I had wireless wake on lan enabled on the hisense fake smart tv so the tv would not change state. Once this was disabled it works as expected. I am using unifi for presence and the updates are pretty fast.

  • platform: broadlink
    host: IP
    mac: mac
    type: rm_mini
    friendly_name: “RM”
    switches:
    tv_hisense:
    friendly_name: “Hisense Toggle”
    command_on: ‘JgBYAAABK48WDxMSEzYTEhYPExEYDRYPEzYTNxMSFTQTNhM3EzYTNxISExITEhM2ExIWDxMSEhIWNBI3EzYWDxY0FTQXMhM3EwAFLQABKkcTAAxaAAErRhIADQU=’
    command_off: ‘JgBYAAABK48WDxMSEzYTEhYPExEYDRYPEzYTNxMSFTQTNhM3EzYTNxISExITEhM2ExIWDxMSEhIWNBI3EzYWDxY0FTQXMhM3EwAFLQABKkcTAAxaAAErRhIADQU=’

  • platform: template
    switches:
    basement_tv:
    friendly_name: “TV”
    value_template: >
    {% if is_state(‘device_tracker.hisensetv’, ‘home’) %}
    on
    {% else %}
    off
    {% endif %}
    turn_on:
    service: switch.turn_on
    data:
    entity_id: switch.tv_hisense
    turn_off:
    service: switch.turn_off
    data:
    entity_id: switch.tv_hisense