Как включить обычный телевизор через HA / How to turn on a regular TV through HA

Текст перевожу через Google переводчик.

I translate the text through Google translator.

  • Понадобится IR remote, я использую от компании Xiaomi.
  • You will need an IR remote, I use it from Xiaomi.
  • Zigbee розетка, ссылку прикреплю ниже. Если будете покупать по ссылке, покупайте оранжевую и нее монитор электроэнергии считывает показания каждые 5 секунд.
  • Zigbee socket, I’ll attach the link below. If you buy from the link, buy the orange one and the energy monitor reads it every 5 seconds.
    Розетка/Socket

Нужно записать команду с пульта телевизора включения и выключения.

You need to record a command from the TV remote control to turn on and off.

  script:
# On/off TV
    hall_tv_on_off:              
        sequence:
        - service: remote.send_command
          entity_id: remote.xiaomi_miio_192_168_1_111
          data:
            command:
              - 'Z6UrAW0BAAD6AQAAVQUAAAoHAAA7DQAAaCMBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0ECAQEBAQEBAQEBAQECAQEBAQEBAQEBAgEBAQEBAQEBAgECAgICAQECAQICAgIBAgUDQQIBAQEBAQEBAQEBAQIBAQEBAQEBAQECAQEBAQEBAQECAQICAgIBAQIBAgICAgECBQNBAgEBAQEBAQEBAQEBAgEBAQEBAQEBAQIBAQEBAQEBAQIBAgICAgEBAgECAgICAQIAA='  

Нужно сделать сенсор который будет определять, включен телевизор или нет. Потребляемую мощность подберите самостоятельно, у меня 15 Вт.
P.S. Если у вас есть ночной режим, то на нем тоже проверьте потребляемую мощность.

You need to make a sensor that will determine whether the TV is on or not. Choose the power consumption yourself, I have 15 watts.
P.S. If you have a night mode, then check the power consumption on it too.

  binary_sensor:      
  - platform: template
    sensors:  
      hall_tv:
        value_template: >-
         {{ states('sensor.0xa4c1383f073a6487_power')|float > 15 }}   
        icon_template: >-
          {% if is_state("binary_sensor.hall_tv", "on") %}
          mdi:television
          {% else %}
          mdi:television-off
          {% endif %}

Теперь нужно сделать еще два сценария для выключателя которым будете включать телевизор.

Now you need to make two more scripts for the switch that will turn on the TV.

script:
# Включить телевизор / TV on
    hall_tv_on:                 
      sequence:
      - service: switch.turn_on 
        entity_id: switch.0xa4c1383f073a6487 # розетка
      - delay: "00:00:02"       
      - service: script.turn_on 
        entity_id: script.hall_tv_on_off

# Включить телевизор /  TV off
    hall_tv_off: 
      sequence:
      - service: script.turn_on
        entity_id: script.hall_tv_on_off

Теперь можно сделать выключатель которым будете включать телевизор. В моем коде присутствует интеграция для голосового ассистента Yandex, если она Вам не нужна, то можете удалить. В конце вставлю скрипт, подтверждающий что телевизор включен.

Now you can make a switch that will turn on the TV. In my code there is an integration for the Yandex voice assistant, if you don’t need it, you can delete it. At the end I will insert a script confirming that the TV is turned on.

  switch:
            
# Кнопка для включения и выключение телевизор / Switch On/Off TV
    - platform: template
      switches:
        hall_tv:
          value_template: >-
            {% if is_state('binary_sensor.hall_tv', 'on') %}           
              on
            {% else %}
              off
            {% endif %} 
          ## Включает телевизор  / ON TV
          turn_on:
            service: >
              {% if is_state('binary_sensor.hall_tv', 'off') %} 
               script.turn_on
              {% else %}
                script.hall_yandex_tv_on
              {% endif %}
            entity_id: script.hall_tv_on
          ## Выключает телевизор  / OFF TV
          turn_off:
            service: >
              {% if is_state('binary_sensor.hall_tv', 'on') %} 
               script.turn_on
              {% else %}
                script.hall_yandex_tv_off
              {% endif %}
            entity_id: script.hall_tv_off 
          icon_template: >-
            {% if is_state('switch.hall_tv', 'on') %}
              mdi:television
            {% else %}
              mdi:television-off
            {% endif %}   

Это скрипт подтверждающий что телевизор включен или выключен.

This is a script that confirms that the TV is on or off.

script:
# Предупреждение о том что телевизор включен / TV on warning
    hall_yandex_tv_on:
      sequence:
      - service: tts.yandex_station_say
        entity_id: media_player.yandex_station_24107894c120441e0510  
        data_template:
          message: Телевизор уже включен #The TV is already on
# Предупреждение о том что телевизор выключен   / TV off warning       
    hall_yandex_tv_off:
      sequence:
      - service: tts.yandex_station_say
        entity_id: media_player.yandex_station_24107894c120441e0510  
        data_template:
          message: Телевизор уже выключен # The TV is already off

Всю автоматизацию делал для себя, надеюсь вы найдете подходящий фрагмент кода.
Спасибо =)

I did all the automation for myself, I hope you find a suitable code snippet.
Thanks =)