Automation Socket > TV

Hi together,

i hope someone can help me. I am from Germany, so I apologize for my bad english :wink:

I want to create an automation which turns on my Sony TV after a smart socket has been turned on before. A 1 minute delay is also built in.

My current automation looks like this:

id: '1640497379567'
alias: TV-Steckdose an > Sony an
description: ''
trigger:
  - platform: state
    entity_id: switch.tv_socket_1
    from: 'off'
    to: 'on'
condition: []
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: media_player.turn_on
    target:
      device_id: c30c9d46d9aa8a042adadd6dffac9599
      entity_id: media_player.sony
mode: single

The trigger is detected, but the Sony is not switched on.

Anyone have any idea what I am doing wrong?

Thanks in advance.

try this:

Remove the following from your code

device_id: c30c9d46d9aa8a042adadd6dffac9599

then try again, you will need to reload automation or restart home assistant.

I have deleted the device id and restart the docker container.

There is a ā€œproblemā€ in the overview see below.

image

Status changed if i turn the Sony on.

So i think this automation doesnt work, if the Sony is not turned on, correct?

From my understanding you want to turn on the tv switch, wait one minute and then turn on the sony tv. is this correct. If so the problem is turning on the TV.

The sony tv already has power at this point and should turn on automatically, if not you may want to use a service like DirectTV if your TV supports it instead of media_player.turn_on.

I dont know if you have Direct TV as an integration, might be worth looking into.

i changed the trigger here need at add the device ID for switch.tv in

- id: '1640497379567'
 alias: TV-Steckdose an > Sony an
 description: ''
 mode: single
 trigger:
   - platform: device
     type: turned_on
     device_id: (put device id in for switch.tv_socket_1 here)
     entity_id: switch.tv_socket_1
     domain: switch
 condition: []
 action:
   - delay:
       hours: 0
       minutes: 1
       seconds: 0
       milliseconds: 0
   - service: media_player.turn_on
     target:
       entity_id: media_player.living_room_tv

Another alternative is to use input_select to tell the tv when turned on to go to play some sort of media content such as an audio file or media file. This is a little more involved and complex.

What does the error log say? please post.

also why the one minute delay?

My Sony TV is connected to the smart socket. The Sony TV needs a lot of power in standby, so I disconnect it completely from the power.

The Sony TV takes a moment to turn on, therefore the 1 minute delay.

I want to turn on the TV when the power outlet is turned on, without pressing the remote control again separately.

Do you understand what I mean?

Yes, i understand, I have a similar setup.

i have a button that turns on a power outlet for my tv, however, my tv turns on as soon as the power is provided to it, I donā€™t have to add a delay, I just have to wait for it to load everything.

maybe there is a setting on your tv you can adjust. some sort of power option.

Im thinking the issue you have is with the tv not the automation.

Most TVs allow you to configure how they react when power is restored. If you set your TV to turn on when power is restored then you donā€™t need your automation. Just a thought.

2 Likes

Alright i will Check this After Christmas meal :grinning_face_with_smiling_eyes:

Does someone know, if there is a option on a android tv?

Currently i doesnt find something like this.

hm something happens but the TV doenst still turn on.

Executed: 26. Dezember 2021, 17:18:52
Result:
params:
  domain: media_player
  service: turn_on
  service_data: {}
  target:
    device_id:
      - c30c9d46d9aa8a042adadd6dffac9599
running_script: false
limit: 10

Itā€™s frustrating. On Android TV there is no power setting that would helped me

whats the make and model of the tv, same for android tv if different.

In germany its called Sony XH95 in US i think X950H.

google says your tv has
CHROMECAST BUILT-IN
APPLE AIRPLAY
APPLE HOMEKIT
ANDROID TV **
** HDMI CEC

This is good it means you have options. Itā€™s difficult to test as I donā€™t have this tv.

This is what I need you to do, this method is the ADB server method.

On android tv go to SETTINGS, then SYSTEM, then ABOUT, then look for the BUILD NUMBER, click on this 8 or 9 times to enable the developer options. it will let you know.

Make a note of your IP address at this point, will need it for later.

Now go back once and click on ADVANCED, then DEVELOPER OPTIONS, look in there to see if you can enable ADB connection, your tv may have this enabled by default. so dont worry if its not there.

at this point we are done with the tv so you can just leave it on the home page.

go into home assistant and add the following to config.yaml

media player:
  - platform: androidtv
    host: yourIPaddress_that_you_made_a_note_of_from_the_tv_goes_here
    name: Sony Android TV

check the config make sure there are no errors and restart.

Once itā€™s restarted go into developer tools, then states and search for Sony Android TV, if itā€™s there, take a screenshot of the attributes and post to help others that might read this post and to see how you can add this to automation to get it to turn on.

we just have the automation part left to do, after this.

Try this, itā€™s working for me couple years already:

 - id: Sony_TV_On
    alias: 'Sony TV On'
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: switch.tv_socket_1
        to: 'on'
    action:
      - service: media_player.turn_on
        target:
          entity_id: media_player.sony

Can you tell how and where i put this code in?

Add new automation > Configure as YAML?

i got a error message see below

Message malformed: invalid boolean value None for dictionary value @ data['initial_state']

They are my first steps with Home Assistant, so please be patient :smiley:

There was a blank too much, but now there is another error message:

Message malformed: expected dictionary

Code is the same that @Vlad posted:

- id: Sony_TV_On
    alias: 'Sony TV On'
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: switch.tv_socket_1
        to: 'on'
    action:
      - service: media_player.turn_on
        target:
          entity_id: media_player.sony

thatā€™s crazy because iā€™m not a devOps engineer :smiley:

Can you help me? :smiley:

this needs to go in your automations.yaml file

- id: '1640497379567'
  alias: Sony TV On
  mode: single
  trigger:
    - platform: state
      entity_id: switch.tv_socket_1
      to: on
  action:
    - service: media_player.turn_on
      target:
        entity_id: media_player.living_room_tv

I still think that you are trying to do this the hard way. You should be able to go to a Settings or Menu option using your TV remote control and then find an option that allows the TV to auto turn on after a power outage. No HA automation needed.

There is just one option in the settings that contains something like that.

See here

Nothing more about power outage :frowning: