master_bathroom_lights.yaml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. switch:
  2. - platform: template
  3. switches:
  4. master_bathroom_light_automation:
  5. friendly_name: "Master bathroom: Light automation"
  6. value_template: "{{ is_state('automation.master_bathroom_motion_active_lights', 'on') }}"
  7. turn_on:
  8. service: automation.turn_on
  9. target:
  10. entity_id: automation.master_bathroom_motion_active_lights
  11. turn_off:
  12. service: automation.turn_off
  13. target:
  14. entity_id: automation.master_bathroom_motion_active_lights
  15. icon_template: >-
  16. {% if is_state('automation.master_bathroom_motion_active_lights', 'on') %}
  17. mdi:motion-sensor
  18. {% else %}
  19. mdi:motion-sensor-off
  20. {% endif %}
  21. # Require: https://github.com/jmgiaever/home-assistant-blueprints/blob/master/automation/motion_detected_lights.yaml
  22. automation:
  23. - id: 'master_bathroom_motion_active_lights'
  24. alias: "Master bathroom: Motion active lights"
  25. use_blueprint:
  26. path: motion_detected_lights.yaml
  27. input:
  28. trigger_sensors:
  29. - binary_sensor.master_bathroom_motion_sensor_home_security_motion_detection
  30. synced_lights:
  31. - light.master_bathroom_ceiling_lights
  32. after_wait_actions:
  33. - wait_template: "{{ is_state('input_boolean.housekeeping_mode', 'off') }}"
  34. - if: "{{ not states('sensor.master_bathroom_humidity_change') in ['unavailable', 'unknown'] }}"
  35. then:
  36. wait_template: "{{ states('sensor.master_bathroom_humidity_change')|int < 0 }}"
  37. - choose:
  38. - conditions: >
  39. {{ states('media_player.master_bathroom_speaker') in ['playing', 'paused', 'idle'] }}
  40. sequence:
  41. # Wait for media_player to stop before cutting lights
  42. - wait_template: >-
  43. {{ is_state('media_player.master_bathroom_speaker', 'playing') }}
  44. timeout: 30
  45. - choose:
  46. - conditions: >-
  47. {{ wait.completed }}
  48. sequence:
  49. - wait_for_trigger:
  50. - platform: state
  51. entity_id: media_player.master_bathroom_speaker
  52. to: "off"
  53. for: 30
  54. - platform: state
  55. entity_id: media_player.master_bathroom_speaker
  56. to: "unavailable"
  57. for: 30
  58. - platform: state
  59. entity_id: media_player.master_bathroom_speaker
  60. to: "paused"
  61. for: 60
  62. - platform: state
  63. entity_id: media_player.master_bathroom_speaker
  64. to: "idle"
  65. for: 60