Browse Source

Move to new integration and add time of day

Joachim M. Giæver 1 year ago
parent
commit
4f92d5dd5e
4 changed files with 105 additions and 87 deletions
  1. 0 12
      General/min_renovasjon.yaml
  2. 70 0
      General/minrenovasjon.yaml
  3. 0 75
      General/remiks_renovasjon.yaml
  4. 35 0
      General/time_of_day.yaml

+ 0 - 12
General/min_renovasjon.yaml

@@ -1,12 +0,0 @@
-min_renovasjon:
-  street_name: "Kirkegårdsvegen"
-  house_no: "14"
-  street_code: "19500"
-  county_id: "5401"
-  date_format: "None"
-
-sensor:
-  - platform: min_renovasjon
-    fraction_id:
-      - 4
-      - 23

+ 70 - 0
General/minrenovasjon.yaml

@@ -0,0 +1,70 @@
+template:
+  - trigger: 
+      platform: state
+      attribute: start_time
+      entity_id: binary_sensor.kirkegardsvegen_14_glass_metallemballasje
+    sensor:
+      - name: "{{ state_attr(trigger.entity_id, 'friendly_name') }}"
+        unique_id: "kirkegardsvegen_14_glass_metallemballasje"
+        state: >- # Set state (datetime) 6 hours ahead of midnigth (start_time)
+          {{ 
+            strptime(
+              state_attr(trigger.entity_id, 'start_time'), 
+              '%Y-%m-%dT%H:%M:%S', 
+              default=now()
+            ) - timedelta(hours=6)
+          }}
+        attributes:
+          from_sensor: "{{ trigger.entity_id }}"
+          start_time: "{{ state_attr(trigger.entity_id, 'start_time') }}"
+
+automation:
+  - id: "trash_collection_glass_metal"
+    alias: "Trash collection: Glass and metal"
+    trigger:
+      platform: time
+      at: sensor.kirkegardsvegen_14_glass_metallemballasje
+    action:
+      - variables:
+          notify_devices: >-
+            {{ state_attr('group.notify_user_devices', 'entity_id')|default([])|list }}
+          # Set the default, so we can trigger it manually....
+          entity_id: "{{ trigger.entity_id|default('sensor.template_kirkegardsvegen_14_glass_metallemballasje') }}"
+          binary_sensor: "{{ state_attr(entity_id, 'from_sensor') }}"
+          date: >-
+            {{ states(entity_id) }}
+      - service: system_log.write
+        data:
+          level: warning
+          message: >-
+            Trigger:{{ trigger }}\n
+            Entity_id: {{entity_id}}, state: {{ states(entity_id)}}
+      - repeat:
+          for_each: "{{ notify_devices }}"
+          sequence:
+            - service: script.turn_on
+              target:
+                entity_id: script.notify_device # https://github.com/jmgiaever/home-assistant-public-config/blob/master/General/notify_device.yaml
+              data:
+                variables:
+                  notify_device: "{{ repeat.item }}"
+                  timeout:
+                    hours: 12
+                  data:
+                    title: "Trash collection day ♻"
+                    message: >-
+                      It's collection day for glass 🍾 and metal 🥫
+                      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') }}.
+                      \n\nHow about placing it next to the road tonight?
+                    data:
+                      persistent: true
+                      channel: "Trash"
+                      vibrationPattern: "100, 1000, 100000, 100, 1000, 100"
+                      notification_icon: "mdi:delete-restore"
+                      icon_url: "{{ state_attr(binary_sensor, 'icon_url')|default('/local/icons/notifications/glass_trash.png') }}"
+                      color: "#5bb59b"
+                      actions:
+                        - action: DONE_DISMISS_ALL
+                          title: "Done! ✔"
+                        - action: DISMISS
+                          title: "Dismiss ✖"

+ 0 - 75
General/remiks_renovasjon.yaml

@@ -1,75 +0,0 @@
-# Require: https://github.com/remimikalsen/hacs_remiks_renovasjon
-remiks_renovasjon:
-  streets: ["kirkegardsvegen-14"]
-  following: ["Glass og metallemballasje"]
-  days_notice: 1
-
-binary_sensor:
-  - platform: remiks_renovasjon
-
-sensor:
-  - platform: remiks_renovasjon
-
-# Require: https://github.com/gadgetchnnel/entities_calendar
-calendar:
-  - platform: entities_calendar
-    calendars:
-      - name: "Trash collection: Glass and metal"
-        entities:
-          - entity: sensor.remiks_glass_og_metallemballasje_kirkegardsvegen_14
-            name: "Glass and metal"
-            start_time:
-              timestamp_attribute: start_time
-            all_day: true
-
-# Require: https://github.com/jmgiaever/home-assistant-public-config/blob/master/General/notify_device.yaml
-# Uses: https://github.com/tybritten/ical-sensor-homeassistant
-automation:
-  - id: "trash_collection_glass_metal"
-    alias: "Trash collection: Glass and metal"
-    trigger:
-      platform: calendar
-      event: start
-      entity_id: calendar.trash_collection_glass_and_metal
-      offset: "-06:00:00"
-    action:
-      - service: system_log.write
-        data:
-          level: warning
-          message: "{{ trigger }}"
-      - variables:
-          notify_devices: >-
-            {{ state_attr('group.owners_notify_devices', 'entity_id')|list }}
-          entity_id: "{{ trigger.entity_id|default('calendar.trash_collection_glass_and_metal') }}"
-          date: >-
-            {{ state_attr(entity_id, 'start_time') }}
-      - repeat:
-          for_each: "{{ notify_devices }}"
-          sequence:
-            - service: script.turn_on
-              target:
-                entity_id: script.notify_device
-              data:
-                variables:
-                  notify_device: "{{ repeat.item }}"
-                  timeout:
-                    hours: 12
-                  data:
-                    title: "Trash collection day ♻"
-                    message: >-
-                      It's collection day for glass 🍾 and metal 🥫
-                      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') }}.
-                      \n\nHow about placing it next to the road tonight?
-                    data:
-                      persistent: true
-                      channel: "Trash"
-                      vibrationPattern: "100, 1000, 100000, 100, 1000, 100"
-                      notification_icon: "mdi:delete-restore"
-                      icon_url: /local/icons/notifications/glass_trash.png
-                      color: "#5bb59b"
-                      actions:
-                        - action: DONE_DISMISS_ALL
-                          title: "Done! ✔"
-                        - action: DISMISS
-                          title: "Dismiss ✖"
-                      

+ 35 - 0
General/time_of_day.yaml

@@ -0,0 +1,35 @@
+automation:
+  - mode: restart
+    id: "period_of_day_notify"
+    alias: "Period of day: Notify"
+    trigger: 
+      platform: state
+      entity_id:
+        - sensor.period_of_day
+    action: 
+      - service: script.turn_on
+        target:
+          entity_id: script.notify_device
+        data:
+          variables:
+            notify_device: notify.mobile_app_pixel_7_pro
+            data:
+              message: >-
+                It is {{ states(trigger.entity_id) }}. {% if states(trigger.entity_id) not in ['day', 'night'] %} 
+                  {{ state_attr(trigger.entity_id, 'twilight')|title }} twilight
+                {% endif %}
+                {% if state_attr(trigger.entity_id, 'dusk_dawn') != false %} 
+                  {{ state_attr(trigger.entity_id, 'dusk_dawn')|title }} dusk
+                {% endif %}
+              data:
+                notification_icon: "{{ state_attr(trigger.entity_id, 'icon') }}"
+                color: '#ebb1bb'
+                actions:
+                  - action: DISMISS_PERIOD_OF_DAY
+                    title: "Dismiss"
+                channel: "Tests"
+                group: "period-of-day"
+                tag: "period-of-day"
+                timeout: "{{ 60 * 2 }}"
+                persistent: true
+                importance: high