minrenovasjon.yaml 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. from_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:
  24. platform: time
  25. at: sensor.kirkegardsvegen_14_glass_metallemballasje
  26. action:
  27. - variables:
  28. notify_devices: >-
  29. {{ state_attr('group.notify_user_devices', 'entity_id')|default([])|list }}
  30. # Set the default, so we can trigger it manually....
  31. entity_id: "{{ trigger.entity_id|default('sensor.template_kirkegardsvegen_14_glass_metallemballasje') }}"
  32. binary_sensor: "{{ state_attr(entity_id, 'from_sensor') }}"
  33. date: >-
  34. {{ states(entity_id) }}
  35. - service: system_log.write
  36. data:
  37. level: warning
  38. message: >-
  39. Trigger:{{ trigger }}\n
  40. Entity_id: {{entity_id}}, state: {{ states(entity_id)}}
  41. - repeat:
  42. for_each: "{{ notify_devices }}"
  43. sequence:
  44. - service: script.turn_on
  45. target:
  46. entity_id: script.notify_device # https://github.com/jmgiaever/home-assistant-public-config/blob/master/General/notify_device.yaml
  47. data:
  48. variables:
  49. notify_device: "{{ repeat.item }}"
  50. timeout:
  51. hours: 12
  52. data:
  53. title: "Trash collection day ♻"
  54. message: >-
  55. It's collection day for glass 🍾 and metal 🥫
  56. 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') }}.
  57. \n\nHow about placing it next to the road tonight?
  58. data:
  59. persistent: true
  60. channel: "Trash"
  61. vibrationPattern: "100, 1000, 100000, 100, 1000, 100"
  62. notification_icon: "mdi:delete-restore"
  63. icon_url: "{{ state_attr(binary_sensor, 'icon_url')|default('/local/icons/notifications/glass_trash.png') }}"
  64. color: "#5bb59b"
  65. actions:
  66. - action: DONE_DISMISS_ALL
  67. title: "Done! ✔"
  68. - action: DISMISS
  69. title: "Dismiss ✖"