Skip to content

Commit 43fc9c7

Browse files
committed
upgrading scripts to recent syntax changes - add state monitor
1 parent 3f7cbfa commit 43fc9c7

File tree

3 files changed

+167
-22
lines changed

3 files changed

+167
-22
lines changed

blueprints/automation/awtrix_indicator.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -358,32 +358,32 @@ variables:
358358
}
359359
360360
trigger:
361-
- platform: time_pattern
361+
- trigger: time_pattern
362362
seconds: /5
363363
id: temporal
364-
- platform: calendar
364+
- trigger: calendar
365365
event: start
366366
offset: "-0:10:0"
367367
entity_id: calendar.mitre
368368
id: 10_min
369-
- platform: calendar
369+
- trigger: calendar
370370
event: start
371371
offset: "-0:5:0"
372372
entity_id: calendar.mitre
373373
id: 5_min
374-
- platform: calendar
374+
- trigger: calendar
375375
event: start
376376
offset: "-0:1:0"
377377
entity_id: calendar.mitre
378378
id: 1_min
379-
- platform: calendar
379+
- trigger: calendar
380380
event: start
381381
offset: "-0:0:1"
382382
entity_id: calendar.mitre
383383
id: 0_min
384384

385385
action:
386-
- service: calendar.get_events
386+
- action: calendar.get_events
387387
data:
388388
duration:
389389
hours: 8
@@ -499,7 +499,7 @@ action:
499499
{%- set starts_in_10 = iif((0 < start_min) and (start_min <= 10),1,0) -%}
500500
{
501501
"summary": "{{event.summary}}"
502-
,"location":{{ ((event.location | replace('\n', ' ')) | to_json)}}
502+
,"location":{{ ((event.location | default('') | replace('\n', ' ')) | to_json)}}
503503
,"start_ts":{{start_ts}}
504504
,"end_ts":{{end_ts}}
505505
,"rel_start":"{{rel_start}}"
@@ -525,7 +525,7 @@ action:
525525
locations: >-
526526
{%- set ns = namespace(locations=[]) %}
527527
{%- for event in cal_events[calendar].events %}
528-
{% set loc = {"locations": ((event.location | replace('\n', ' ')) | to_json) } %}
528+
{% set loc = {"locations": ((event.location | default('') | replace('\n', ' ')) | to_json) } %}
529529
{%- set ns.locations = ns.locations + [loc] + [loc] %}
530530
{%- endfor -%}
531531
{{ns.locations}}
@@ -630,7 +630,7 @@ action:
630630
- repeat:
631631
for_each: "{{devices_topics}}"
632632
sequence:
633-
- service: mqtt.publish
633+
- action: mqtt.publish
634634
data:
635635
qos: 0
636636
retain: false
@@ -648,7 +648,7 @@ action:
648648
- repeat:
649649
for_each: "{{next_meeting_topics}}"
650650
sequence:
651-
- service: mqtt.publish
651+
- action: mqtt.publish
652652
data:
653653
qos: 0
654654
retain: false
@@ -662,7 +662,7 @@ action:
662662
- repeat:
663663
for_each: "{{sound_topics}}"
664664
sequence:
665-
- service: mqtt.publish
665+
- action: mqtt.publish
666666
data:
667667
qos: 0
668668
retain: false
@@ -674,7 +674,7 @@ action:
674674
- condition: template
675675
value_template: "{{trigger.id != 'temporal'}}"
676676
then:
677-
- service: mqtt.publish
677+
- action: mqtt.publish
678678
data:
679679
qos: 0
680680
topic: dev-test

blueprints/automation/awtrix_weatherflow.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ blueprint:
7979
description: Select the Awtrix light
8080
selector:
8181
device:
82-
integration: mqtt
83-
manufacturer: Blueforcer
84-
model: AWTRIX 3
82+
filter:
83+
integration: mqtt
84+
manufacturer: Blueforcer
85+
model: AWTRIX 3
8586
multiple: true
8687

8788
forecast_var:
@@ -170,8 +171,9 @@ blueprint:
170171
171172
selector:
172173
entity:
173-
domain:
174-
- sensor
174+
filter:
175+
domain:
176+
- sensor
175177
multiple: false
176178
default: sensor.weatherflow_air_temperature
177179

@@ -844,15 +846,15 @@ variables:
844846
{%- endif -%}
845847
846848
trigger:
847-
- platform: time_pattern
849+
- trigger: time_pattern
848850
seconds: /5
849-
- platform: state
851+
- trigger: state
850852
entity_id: !input forecast_var
851853
id: Changes
852854
enabled: true
853855
condition: []
854856
action:
855-
- service: weather.get_forecasts
857+
- action: weather.get_forecasts
856858
target:
857859
entity_id: "{{forecast_var}}"
858860
data:
@@ -862,7 +864,7 @@ action:
862864
- repeat:
863865
for_each: "{{ topics }}"
864866
sequence:
865-
- service: mqtt.publish
867+
- action: mqtt.publish
866868
data:
867869
topic: "{{repeat.item}}"
868870
payload: >-
@@ -959,7 +961,7 @@ action:
959961
"weather": "{{current_condition}}"
960962
}
961963
962-
- service: mqtt.publish
964+
- action: mqtt.publish
963965
data:
964966
qos: 0
965967
retain: false
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
blueprint:
2+
name: A State Monitor with Actionable Notifications
3+
description: >
4+
Send notifications to a mobile app at regular intervals when a device reaches a specified state.
5+
Includes actionable notifications to close covers if the entity is a cover.
6+
Messages will arrive in the form of "[ENTITY NAME] is [Condition Name] for X hrs".
7+
domain: automation
8+
input:
9+
monitored_entity:
10+
name: Monitored Entity
11+
description: The entity to monitor for state changes
12+
selector:
13+
entity:
14+
target_state:
15+
name: Target State
16+
description: >
17+
Leave this blank to use the default. The default states are as follows:
18+
- `cover`: **`open`**
19+
- `binary_sensor`: **`on`**
20+
selector:
21+
text:
22+
default: ""
23+
message_state:
24+
name: Condition Name
25+
description: The text to include in notifications (e.g., "Open" or "Still Open")
26+
selector:
27+
text:
28+
default: "Open"
29+
notify_device:
30+
name: Notification Device
31+
description: The mobile app device to send notifications to
32+
selector:
33+
device:
34+
filter:
35+
integration: mobile_app
36+
interval_minutes:
37+
name: Notification Interval (Minutes)
38+
description: How often to send notifications while in target state
39+
default: 30
40+
selector:
41+
number:
42+
min: 1
43+
max: 180
44+
unit_of_measurement: minutes
45+
46+
variables:
47+
interval_minutes: !input interval_minutes
48+
monitored_entity: !input monitored_entity
49+
notify_device: !input notify_device
50+
message_state: !input message_state
51+
entity_name: "{{ state_attr(monitored_entity, 'friendly_name') or monitored_entity.split('.')[1] | replace('_', ' ') | title }}"
52+
# Derive notify_service from device ID
53+
notify_service: >-
54+
{% set devices = device_entities(notify_device) | list %}
55+
notify.mobile_app_{{devices[0].split('.')[1]}}
56+
unique_tag: "{{ monitored_entity | replace('.', '_') }}_state_monitor"
57+
default_state: >-
58+
{% if monitored_entity.split('.')[0] == 'cover' %}
59+
open
60+
{% elif monitored_entity.split('.')[0] == 'binary_sensor' %}
61+
on
62+
{% else %}
63+
on
64+
{% endif %}
65+
ts: !input target_state
66+
target_state: >-
67+
{% if not ts or ts == '' %}
68+
{{ default_state | trim }}
69+
{% else %}
70+
{{ ts | trim }}
71+
{% endif %}
72+
is_cover: >-
73+
{% if monitored_entity.split('.')[0] == 'cover' %}
74+
true
75+
{% else %}
76+
false
77+
{% endif %}
78+
actions: >-
79+
{% if is_cover == 'true' %}
80+
[{"action": "CLOSE_{{ unique_tag }}",
81+
"title": "Close {{ entity_name }}",
82+
"service": "cover.close_cover",
83+
"service_data": {"entity_id": "{{ monitored_entity }}"}}]
84+
{% else %}
85+
[]
86+
{% endif %}
87+
88+
trigger:
89+
- trigger: state
90+
entity_id: !input monitored_entity
91+
- trigger: homeassistant
92+
event: start
93+
- trigger: event
94+
event_type: automation_reloaded
95+
96+
action:
97+
- choose:
98+
- conditions:
99+
- condition: state
100+
entity_id: !input monitored_entity
101+
state: "{{ target_state }}"
102+
sequence:
103+
- variables:
104+
message: "{{ entity_name }} is now {{ message_state }}"
105+
- action: "{{ notify_service }}"
106+
data:
107+
title: "{{ entity_name }}"
108+
message: "{{ message }}"
109+
data:
110+
tag: "{{ unique_tag }}"
111+
actions: "{{ actions }}"
112+
- repeat:
113+
while:
114+
- condition: state
115+
entity_id: !input monitored_entity
116+
state: "{{ target_state }}"
117+
sequence:
118+
- delay:
119+
minutes: "{{ interval_minutes }}"
120+
- variables:
121+
last_changed_str: >-
122+
{{ relative_time(states[monitored_entity].last_changed | default(0))
123+
| replace('hours', 'hr')
124+
| replace('hour', 'hr')
125+
| replace('seconds', 'sec')
126+
| replace('minutes', 'min')
127+
| replace('minute', 'min') }}
128+
message: "{{ entity_name }} is {{ message_state }} for {{ last_changed_str }}"
129+
- action: "{{ notify_service }}"
130+
data:
131+
title: "{{ entity_name }}"
132+
message: "{{ message }}"
133+
data:
134+
tag: "{{ unique_tag }}"
135+
actions: "{{ actions }}"
136+
default:
137+
- action: "{{ notify_service }}"
138+
data:
139+
message: "clear_notification"
140+
data:
141+
tag: "{{ unique_tag }}"
142+
143+
mode: restart

0 commit comments

Comments
 (0)