Skip to content

Commit 7173608

Browse files
authored
Merge pull request #23 from caiosweet/dev
Fixed Warnings for undefined variables in Templates
2 parents 456109c + 7b1eae7 commit 7173608

File tree

7 files changed

+69
-53
lines changed

7 files changed

+69
-53
lines changed

examples/hub_automations.yaml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ automation:
7171
Il sistema è operativo!.
7272
voice: Giorgio
7373
type: tts
74-
# google:
74+
google:
75+
message_tts: >-
76+
Il sistema è operativo!.
7577
# media_content_id: https://actions.google.com/sounds/v1/human_voices/human_fart.ogg
7678
# media_content_type: sound
7779
default:
@@ -476,16 +478,16 @@ automation:
476478
#----------------------------------------------------------------------------------------------------#
477479
# Test trigger event - Notifica location
478480
#----------------------------------------------------------------------------------------------------#
479-
- alias: Notifica location
481+
- alias: Notifica location hub
480482
initial_state: true
481483
trigger:
482484
- platform: event
483485
event_type: state_changed
484-
condition: # ??trigger.event.data.old_state is none
486+
condition: # and (trigger.event.data.old_state is none
485487
- "{{ trigger.event.data.entity_id.startswith('person') }}"
486488
- "{{ trigger.event.data.old_state is not none
487-
and (trigger.event.data.old_state is none
488-
or trigger.event.data.new_state.state != trigger.event.data.old_state.state) }}"
489+
and 'latitude' in trigger.event.data
490+
and trigger.event.data.new_state.state != trigger.event.data.old_state.state }}"
489491
action:
490492
- variables:
491493
lat: "{{trigger.event.data.new_state.attributes.latitude}}"
@@ -545,3 +547,16 @@ automation:
545547
# [Mappa](https://www.openstreetmap.org/?mlat={{lat}}&mlon={{long}}#map=8/{{lat}}/{{long}})
546548
# {% endif %}
547549

550+
- alias: Notifica Cambio Stagione hub
551+
initial_state: true
552+
trigger:
553+
- platform: state
554+
entity_id: sensor.stagioni
555+
condition:
556+
- condition: template
557+
value_template: '{{ trigger.from_state is defined and trigger.from_state.state | lower != "unknown" }}'
558+
action:
559+
- service: script.my_notify
560+
data:
561+
message: >
562+
Arrivederci {{ trigger.from_state.state }}, e Salutiamo la Stagione {{ trigger.to_state.state }}!

examples/script_test.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ script:
1616
media_player: media_player.studio, media_player.sala
1717
volume: 0.4
1818
google:
19-
media_player: media_player.red, media_player.black2
19+
media_player: media_player.red, media_player.black_due
2020
volume: 0.4
2121
title: >-
2222
M0 - {{now().time()}}
@@ -72,10 +72,8 @@ script:
7272
- service: script.my_notify
7373
data:
7474
call_no_annuncio: 1
75-
alexa:
76-
mode: true
77-
google:
78-
mode: true
75+
alexa: true
76+
google: true
7977
title: >-
8078
M4 - {{now().time()}}
8179
message: >-
@@ -85,10 +83,8 @@ script:
8583
- service: script.my_notify
8684
data:
8785
call_no_annuncio: 1
88-
alexa:
89-
mode: true
90-
google:
91-
mode: true
86+
alexa: true
87+
google: true
9288
title: >-
9389
M5 - {{now().time()}}
9490
message: >-
@@ -97,7 +93,7 @@ script:
9793
{% set alexa = 'Media player selezionato '
9894
+ states('input_select.notification_media_player_alexa')
9995
+ '. Tipo ' + states('input_select.default_alexa_type')
100-
+ '. Metodo ' + ('Nessuno' if states('input_select.default_alexa_method5') == 'unknown' else states('input_select.default_alexa_method5')) %}
96+
+ '. Metodo ' + ('Nessuno' if states('input_select.default_alexa_method') == 'unknown' else states('input_select.default_alexa_method')) %}
10197
{% endif %}
10298
{% if states('input_boolean.google_switch') == 'on' %}
10399
{% set google = '. Google media player selezionato ' + states('input_select.notification_media_player_google')
@@ -110,15 +106,20 @@ script:
110106
+', Notifiche vocali ' + states('input_boolean.speech_notifications')
111107
+', Notifiche testo ' + states('input_boolean.text_notifications')
112108
+', Notifiche persistenti ' + states('input_boolean.screen_notifications') %}
113-
{{(alexa ~ google ~ message)|replace(' off',' spento')|replace(' on',' acceso')}}
109+
{{(alexa|default ~ google|default ~ message)|replace(' off',' spento')|replace(' on',' acceso')}}
114110
115111
centro_notifiche_alexa_test:
116112
alias: 'Centro Notifiche Alexa Test'
117113
sequence:
114+
- variables:
115+
my_variable: >
116+
{% if is_state('alarm_control_panel.home_alarm', 'triggered')
117+
and is_state('input_boolean.allarme_silenzioso', 'off')-%}
118+
0 {% else -%} 1 {%- endif %}
118119
- service: script.my_notify
119120
data:
120-
call_no_annuncio: 1
121-
alexa:
121+
message: "Alert"
122+
"{{'alexa' if my_variable else ''}}":
122123
message: "Houston, we have a problem! "
123124
language: en-US
124125
voice: Matthew
@@ -135,8 +136,7 @@ script:
135136
data:
136137
alexa:
137138
message: >
138-
sono le {{now().strftime("%H:%M")}}
139-
e sogni d'oro.
139+
sono le {{now().strftime("%H:%M")}}, sogni d'oro.
140140
a ah, che bello!
141141
- delay: "00:01:00"
142142
- service: script.my_notify
@@ -152,4 +152,4 @@ script:
152152
# media_content_id: Alexa.SingASong.Play
153153
# media_content_id: Alexa.TellStory.Play
154154
# media_content_id: Alexa.Joke.Play
155-
# media_content_id: Alexa.ImHome.Play
155+
# media_content_id: Alexa.ImHome.Play

extra/my_lovelace_card.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,18 @@ cards:
220220
}
221221
entities:
222222
- type: custom:fold-entity-row
223+
cickable: true
223224
padding: 0
224225
head:
225-
# type: section
226-
# label: Interfono
227-
type: call-service
226+
type: button
227+
icon: mdi:bullhorn-outline
228228
name: Interfono
229-
icon: mdi:bullhorn-outline #mdi:repeat-once
230229
action_name: Last Message
231-
service: input_boolean.turn_on
232-
service_data:
233-
entity_id: input_boolean.last_message
230+
tap_action:
231+
action: call-service
232+
service: input_boolean.turn_on
233+
service_data:
234+
entity_id: input_boolean.last_message
234235
entities:
235236
- type: custom:lovelace-multiline-text-input-card
236237
card_mod:

packages/centro_notifiche/hub_alexa.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ homeassistant:
99
package: Centro Notifiche 🔔
1010
site: hassiohelp.eu 🌐
1111
author: Caio & Gianpi
12-
version: Alexa 3.2.0
12+
version: Alexa 3.2.1
1313

1414
expose: &expose
1515
<<: *customize

packages/centro_notifiche/hub_build_message.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
{# *************************************************************************** #}
4646
{# INIZIO SEQUENZIALE DELLA COSTRUZIONE DEL MESSAGGIO / NOTICIA #}
4747
{# *************************************************************************** #}
48-
{% if not call_no_annuncio %} {{ annuncio() }} {% endif %}
49-
{% if call_modo_ospite %} {{ modo_ospite() }} {% endif %}
48+
{% if not call_no_annuncio|default %} {{ annuncio() }} {% endif %}
49+
{% if call_modo_ospite|default %} {{ modo_ospite() }} {% endif %}
5050

5151
{# Esempio di come aggiungere altre variabili - Chiamata da Automazione di Benvenuto #}
52-
{{ benvenuto }}
52+
{{ benvenuto|default }}
5353

5454
{# + Contenuto del messaggio passato tramite automazioni/script + #}
55-
{{ message }}
55+
{{ message|default }}

packages/centro_notifiche/hub_google.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ homeassistant:
99
package: Centro Notifiche 🔔
1010
site: hassiohelp.eu 🌐
1111
author: Caio & Gianpi
12-
version: Google 3.2.0
12+
version: Google 3.2.1
1313

1414
expose: &expose
1515
<<: *customize

packages/centro_notifiche/hub_main.yaml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ homeassistant:
1616
package: Centro Notifiche 🔔
1717
site: hassiohelp.eu 🌐
1818
author: Caio & Gianpi
19-
version: Main 3.2.0
19+
version: Main 3.2.1
2020

2121
## AUTOMATION
2222
automation.auto_volume_hub:
2323
<<: *customize
2424
friendly_name: Volume Automatico Hub
25-
automation.hub_initialization_at_startup:
25+
automation.initialization_at_startup_hub:
2626
<<: *customize
2727
friendly_name: Startup HUB
2828
automation.guest_mode_hub:
@@ -423,31 +423,31 @@ script:
423423
# VARIABLES
424424
# --------------------------------------------- #
425425
alexa: >-
426-
{{alexa}}
426+
{{alexa|default}}
427427
called_number: >-
428-
{{called_number}}
428+
{{called_number|default}}
429429
caption: >-
430-
{{caption}}
430+
{{caption|default}}
431431
file: >-
432-
{{file}}
432+
{{file|default}}
433433
google: >-
434-
{{google}}
434+
{{google|default}}
435435
html: >-
436-
{{html}}
436+
{{html|default}}
437437
link: >-
438-
{{link}}
438+
{{link|default}}
439439
location: >-
440-
{{location}}
440+
{{location|default}}
441441
no_show: >-
442-
{{no_show}}
442+
{{no_show|default}}
443443
notify: >-
444-
{{notify}}
444+
{{notify|default}}
445445
priority: >-
446-
{{priority}}
446+
{{priority|default}}
447447
title: >-
448-
{{title}}
448+
{{title|default}}
449449
url: >-
450-
{{url}}
450+
{{url|default}}
451451
#-------------------------------------------------------------------------------#
452452
# FILE TO BE INCLUDED IF MACROS ARE USED - NOTE: DO NOT MODIFY THE .yml EXTENSION
453453
#-------------------------------------------------------------------------------#
@@ -468,7 +468,7 @@ automation:
468468
#----------------------------------------------------------------------------------------------------#
469469
# INITIALIZE
470470
#----------------------------------------------------------------------------------------------------#
471-
- alias: Hub initialization at startup
471+
- alias: Initialization At Startup Hub
472472
initial_state: true
473473
trigger:
474474
- platform: homeassistant
@@ -530,10 +530,10 @@ automation:
530530
data:
531531
object_id: "automations_notification_hub"
532532
entities: >
533-
{%for item in states.automation if ((item.attributes.id|lower).endswith('hub'))
534-
or ((item.attributes.friendly_name|lower).endswith('hub')) %}
533+
{%for item in states.automation if (item.attributes.id is defined
534+
and (item.attributes.id|lower).endswith('hub'))
535+
or (item.attributes.friendly_name|lower).endswith('hub') %}
535536
{{-item.entity_id}}{%if not loop.last%},{%endif-%}{%endfor%}
536-
537537
# Execute auto_volume_hub Automation.
538538
- service: automation.trigger
539539
entity_id: automation.auto_volume_hub

0 commit comments

Comments
 (0)