minrenovasjon.yaml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. template:
  2. - trigger:
  3. platform: state
  4. attribute: start_time
  5. entity_id: binary_sensor.kirkegardsvegen_14_glass_metallemballasje
  6. sensor:
  7. - name: "{{ state_attr(trigger.entity_id, 'friendly_name') }}"
  8. unique_id: "kirkegardsvegen_14_glass_metallemballasje"
  9. state: >- # Set state (datetime) 6 hours ahead of midnigth (start_time)
  10. {{
  11. strptime(
  12. state_attr(trigger.entity_id, 'start_time'),
  13. '%Y-%m-%dT%H:%M:%S',
  14. default=now()
  15. ) - timedelta(hours=6)
  16. }}
  17. attributes:
  18. source_sensor: "{{ trigger.entity_id }}"
  19. start_time: "{{ state_attr(trigger.entity_id, 'start_time') }}"
  20. automation:
  21. - id: "trash_collection_glass_metal"
  22. alias: "Trash collection: Glass and metal"
  23. trigger_variables:
  24. entity_id: "sensor.kirkegardsvegen_14_glass_metallemballasje"
  25. trigger:
  26. platform: time
  27. at: sensor.kirkegardsvegen_14_glass_metallemballasje
  28. action:
  29. - variables:
  30. notify_devices: >-
  31. {{ state_attr('group.notify_user_devices', 'entity_id')|default([])|list }}
  32. # Set the default, so we can trigger it manually....
  33. binary_sensor: "{{ state_attr(entity_id, 'source_sensor') }}"
  34. date: >-
  35. {{ states(entity_id) }}
  36. - service: system_log.write
  37. data:
  38. level: warning
  39. message: >-
  40. Trigger:{{ trigger }}\n
  41. Entity_id: {{ entity_id }}, state: {{ states(entity_id)}}
  42. - repeat:
  43. for_each: "{{ notify_devices }}"
  44. sequence:
  45. - service: script.turn_on
  46. target:
  47. entity_id: script.notify_device # https://github.com/jmgiaever/home-assistant-public-config/blob/master/General/notify_device.yaml
  48. data:
  49. variables:
  50. notify_device: "{{ repeat.item }}"
  51. timeout:
  52. hours: 12
  53. data:
  54. title: "Trash collection day ♻"
  55. message: >-
  56. It's collection day for glass 🍾 and metal 🥫
  57. tomorrow {{ as_datetime(date).strftime('%A')}} the {{ as_datetime(date).day|string + {1: 'st', 2: 'nd', 3: 'rd'}.get(4 if 10 <= as_datetime(date).day|int % 100 < 20 else as_datetime(date).day|int % 10, 'th') }} of {{ as_datetime(date).strftime('%B') }}.
  58. \n\nHow about placing it next to the road tonight?
  59. data:
  60. persistent: true
  61. channel: "Trash"
  62. vibrationPattern: "100, 1000, 100000, 100, 1000, 100"
  63. notification_icon: "mdi:delete-restore"
  64. icon_url: "{{ state_attr(binary_sensor, 'icon_url')|default('/local/icons/notifications/glass_trash.png') }}"
  65. color: "#5bb59b"
  66. actions:
  67. - action: DONE_DISMISS_ALL
  68. title: "Done! ✔"
  69. - action: DISMISS
  70. title: "Dismiss ✖"