cast_lovelace_on_motion.yaml 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. blueprint:
  2. domain: automation
  3. name: Cast lovelace on motion detection
  4. input:
  5. trigger_sensors:
  6. name: Trigger sensors
  7. selector:
  8. entity:
  9. multiple: true
  10. domain: binary_sensor
  11. media_devices:
  12. name: Media Devices
  13. selector:
  14. entity:
  15. integration: cast
  16. multiple: true
  17. dashboard_path:
  18. name: Dashboard path
  19. default: lovelace
  20. selector:
  21. text:
  22. suffix: "http://ha/dashboard-path/view-path"
  23. dashboard_view:
  24. name: View path
  25. selector:
  26. text:
  27. suffix: "http://ha/dashboard-path/view-path"
  28. mode: restart
  29. trigger:
  30. platform: state
  31. to: "on"
  32. entity_id: !input trigger_sensors
  33. variables:
  34. trigger_sensors: !input trigger_sensors
  35. media_devices: !input media_devices
  36. dashboard_path: !input dashboard_path
  37. dashboard_view: !input dashboard_view
  38. action:
  39. - service: system_log.write
  40. data:
  41. level: warning
  42. message: >-
  43. Triggered {{ trigger_sensors }}
  44. For {{ media_devices }}
  45. - repeat:
  46. for_each: "{{ media_devices }}"
  47. sequence:
  48. - if: "{{ not states(repeat.item) in ['idle', 'playing', 'paused'] }}"
  49. then:
  50. - service: system_log.write
  51. data:
  52. level: warning
  53. message: >-
  54. Display {{ state_attr(repeat.item, "friendly_name") }} is ready for Lovelace «{{ dashboard_path }}/{{ dashboard_view }}».
  55. - service: media_player.volume_mute
  56. data:
  57. is_volume_muted: true
  58. target:
  59. entity_id: "{{ repeat.item }}"
  60. - service: cast.show_lovelace_view
  61. data:
  62. entity_id: "{{ repeat.item }}"
  63. dashboard_path: "{{ dashboard_path }}"
  64. view_path: "{{ dashboard_view }}"
  65. - wait_template: >-
  66. {{ is_state_attr(repeat.item, 'app_name', 'Home Assistant Lovelace' ) }}
  67. - delay:
  68. seconds: 2
  69. - service: media_player.volume_mute
  70. data:
  71. is_volume_muted: false
  72. target:
  73. entity_id: "{{ repeat.item }}"
  74. else:
  75. - service: system_log.write
  76. data:
  77. level: warning
  78. message: >-
  79. Display {{ state_attr(repeat.item, "friendly_name") }} is playing «{{ state_attr(repeat.item, 'app_name') }}»,
  80. skipping launching «{{ dashboard_path }}/{{ dashboard_view }}».