cast_lovelace_on_motion.yaml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. - variables:
  56. is_muted: "{{ is_state_attr(repeat.item, 'is_volume_muted', true) }}"
  57. - if: "{{ is_muted }}"
  58. then:
  59. - service: media_player.volume_mute
  60. data:
  61. is_volume_muted: true
  62. target:
  63. entity_id: "{{ repeat.item }}"
  64. - service: cast.show_lovelace_view
  65. data:
  66. entity_id: "{{ repeat.item }}"
  67. dashboard_path: "{{ dashboard_path }}"
  68. view_path: "{{ dashboard_view }}"
  69. - if: "{{ is_muted }}"
  70. then:
  71. - wait_template: >-
  72. {{ is_state_attr(repeat.item, 'app_name', 'Home Assistant Lovelace' ) }}
  73. - service: media_player.volume_mute
  74. data:
  75. is_volume_muted: false
  76. target:
  77. entity_id: "{{ repeat.item }}"
  78. else:
  79. - service: system_log.write
  80. data:
  81. level: warning
  82. message: >-
  83. Display {{ state_attr(repeat.item, "friendly_name") }} is playing «{{ state_attr(repeat.item, 'app_name') }}»,
  84. skipping launching «{{ dashboard_path }}/{{ dashboard_view }}».