Skip to content

Instantly share code, notes, and snippets.

@willwhui
Last active November 27, 2017 04:06
Show Gist options
  • Save willwhui/22e6ecc5aee88344d3a954962ef7c938 to your computer and use it in GitHub Desktop.
Save willwhui/22e6ecc5aee88344d3a954962ef7c938 to your computer and use it in GitHub Desktop.
在Hass上利用Chromecast state Event开关电视
@willwhui
Copy link
Author

willwhui commented Nov 27, 2017

准备工作已做好,整理一下思路

trigger:
检查chromecast的状态,它是个mediaplayer
condition:
检查电视机的ip状态,它是个sensor
action:
向智能红外遥控器发送打开电视的指令,它是个switch

在配置文件中添加automation如下:

- alias: 'TV power on when Chromecast playing'
  trigger:
    - platform: state
      entity_id: media_player.living_room_tv
      from: 'off'
      to: 'idle' # start to play video. The next state change will be "idle to playing"
    - platform: state
      entity_id: media_player.living_room_tv
      from: 'off'
      to: 'playing' # maybe sometime state will directly be changed from "off" to "playing" ? i don't know
  condition:
    condition: state
    entity_id: binary_sensor.skyworth_tv
    state: 'off' # tv ip address not detected
  action:
    - service: media_player.media_pause # waiting for tv power on
      entity_id: media_player.living_room_tv
    - service: switch.turn_on
      entity_id: switch.skyworth_tv_power
    - delay: '00:00:30' # left some seconds for tv power on
    - service: media_player.media_play # continue playing
      entity_id: media_player.living_room_tv

这样就好了。
重启hass。
对google home说 “play movie on tv”,就可以自动启动电视了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment