Skip to content

Commit

Permalink
Merge pull request #23 from caiosweet/dev
Browse files Browse the repository at this point in the history
Fixed Warnings for undefined variables in Templates
  • Loading branch information
caiosweet authored Apr 8, 2021
2 parents 456109c + 7b1eae7 commit 7173608
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 53 deletions.
25 changes: 20 additions & 5 deletions examples/hub_automations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ automation:
Il sistema è operativo!.
voice: Giorgio
type: tts
# google:
google:
message_tts: >-
Il sistema è operativo!.
# media_content_id: https://actions.google.com/sounds/v1/human_voices/human_fart.ogg
# media_content_type: sound
default:
Expand Down Expand Up @@ -476,16 +478,16 @@ automation:
#----------------------------------------------------------------------------------------------------#
# Test trigger event - Notifica location
#----------------------------------------------------------------------------------------------------#
- alias: Notifica location
- alias: Notifica location hub
initial_state: true
trigger:
- platform: event
event_type: state_changed
condition: # ??trigger.event.data.old_state is none
condition: # and (trigger.event.data.old_state is none
- "{{ trigger.event.data.entity_id.startswith('person') }}"
- "{{ trigger.event.data.old_state is not none
and (trigger.event.data.old_state is none
or trigger.event.data.new_state.state != trigger.event.data.old_state.state) }}"
and 'latitude' in trigger.event.data
and trigger.event.data.new_state.state != trigger.event.data.old_state.state }}"
action:
- variables:
lat: "{{trigger.event.data.new_state.attributes.latitude}}"
Expand Down Expand Up @@ -545,3 +547,16 @@ automation:
# [Mappa](https://www.openstreetmap.org/?mlat={{lat}}&mlon={{long}}#map=8/{{lat}}/{{long}})
# {% endif %}

- alias: Notifica Cambio Stagione hub
initial_state: true
trigger:
- platform: state
entity_id: sensor.stagioni
condition:
- condition: template
value_template: '{{ trigger.from_state is defined and trigger.from_state.state | lower != "unknown" }}'
action:
- service: script.my_notify
data:
message: >
Arrivederci {{ trigger.from_state.state }}, e Salutiamo la Stagione {{ trigger.to_state.state }}!
32 changes: 16 additions & 16 deletions examples/script_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ script:
media_player: media_player.studio, media_player.sala
volume: 0.4
google:
media_player: media_player.red, media_player.black2
media_player: media_player.red, media_player.black_due
volume: 0.4
title: >-
M0 - {{now().time()}}
Expand Down Expand Up @@ -72,10 +72,8 @@ script:
- service: script.my_notify
data:
call_no_annuncio: 1
alexa:
mode: true
google:
mode: true
alexa: true
google: true
title: >-
M4 - {{now().time()}}
message: >-
Expand All @@ -85,10 +83,8 @@ script:
- service: script.my_notify
data:
call_no_annuncio: 1
alexa:
mode: true
google:
mode: true
alexa: true
google: true
title: >-
M5 - {{now().time()}}
message: >-
Expand All @@ -97,7 +93,7 @@ script:
{% set alexa = 'Media player selezionato '
+ states('input_select.notification_media_player_alexa')
+ '. Tipo ' + states('input_select.default_alexa_type')
+ '. Metodo ' + ('Nessuno' if states('input_select.default_alexa_method5') == 'unknown' else states('input_select.default_alexa_method5')) %}
+ '. Metodo ' + ('Nessuno' if states('input_select.default_alexa_method') == 'unknown' else states('input_select.default_alexa_method')) %}
{% endif %}
{% if states('input_boolean.google_switch') == 'on' %}
{% set google = '. Google media player selezionato ' + states('input_select.notification_media_player_google')
Expand All @@ -110,15 +106,20 @@ script:
+', Notifiche vocali ' + states('input_boolean.speech_notifications')
+', Notifiche testo ' + states('input_boolean.text_notifications')
+', Notifiche persistenti ' + states('input_boolean.screen_notifications') %}
{{(alexa ~ google ~ message)|replace(' off',' spento')|replace(' on',' acceso')}}
{{(alexa|default ~ google|default ~ message)|replace(' off',' spento')|replace(' on',' acceso')}}
centro_notifiche_alexa_test:
alias: 'Centro Notifiche Alexa Test'
sequence:
- variables:
my_variable: >
{% if is_state('alarm_control_panel.home_alarm', 'triggered')
and is_state('input_boolean.allarme_silenzioso', 'off')-%}
0 {% else -%} 1 {%- endif %}
- service: script.my_notify
data:
call_no_annuncio: 1
alexa:
message: "Alert"
"{{'alexa' if my_variable else ''}}":
message: "Houston, we have a problem! "
language: en-US
voice: Matthew
Expand All @@ -135,8 +136,7 @@ script:
data:
alexa:
message: >
sono le {{now().strftime("%H:%M")}}
e sogni d'oro.
sono le {{now().strftime("%H:%M")}}, sogni d'oro.
a ah, che bello!
- delay: "00:01:00"
- service: script.my_notify
Expand All @@ -152,4 +152,4 @@ script:
# media_content_id: Alexa.SingASong.Play
# media_content_id: Alexa.TellStory.Play
# media_content_id: Alexa.Joke.Play
# media_content_id: Alexa.ImHome.Play
# media_content_id: Alexa.ImHome.Play
15 changes: 8 additions & 7 deletions extra/my_lovelace_card.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,18 @@ cards:
}
entities:
- type: custom:fold-entity-row
cickable: true
padding: 0
head:
# type: section
# label: Interfono
type: call-service
type: button
icon: mdi:bullhorn-outline
name: Interfono
icon: mdi:bullhorn-outline #mdi:repeat-once
action_name: Last Message
service: input_boolean.turn_on
service_data:
entity_id: input_boolean.last_message
tap_action:
action: call-service
service: input_boolean.turn_on
service_data:
entity_id: input_boolean.last_message
entities:
- type: custom:lovelace-multiline-text-input-card
card_mod:
Expand Down
2 changes: 1 addition & 1 deletion packages/centro_notifiche/hub_alexa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homeassistant:
package: Centro Notifiche 🔔
site: hassiohelp.eu 🌐
author: Caio & Gianpi
version: Alexa 3.2.0
version: Alexa 3.2.1

expose: &expose
<<: *customize
Expand Down
8 changes: 4 additions & 4 deletions packages/centro_notifiche/hub_build_message.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
{# *************************************************************************** #}
{# INIZIO SEQUENZIALE DELLA COSTRUZIONE DEL MESSAGGIO / NOTICIA #}
{# *************************************************************************** #}
{% if not call_no_annuncio %} {{ annuncio() }} {% endif %}
{% if call_modo_ospite %} {{ modo_ospite() }} {% endif %}
{% if not call_no_annuncio|default %} {{ annuncio() }} {% endif %}
{% if call_modo_ospite|default %} {{ modo_ospite() }} {% endif %}

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

{# + Contenuto del messaggio passato tramite automazioni/script + #}
{{ message }}
{{ message|default }}
2 changes: 1 addition & 1 deletion packages/centro_notifiche/hub_google.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homeassistant:
package: Centro Notifiche 🔔
site: hassiohelp.eu 🌐
author: Caio & Gianpi
version: Google 3.2.0
version: Google 3.2.1

expose: &expose
<<: *customize
Expand Down
38 changes: 19 additions & 19 deletions packages/centro_notifiche/hub_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ homeassistant:
package: Centro Notifiche 🔔
site: hassiohelp.eu 🌐
author: Caio & Gianpi
version: Main 3.2.0
version: Main 3.2.1

## AUTOMATION
automation.auto_volume_hub:
<<: *customize
friendly_name: Volume Automatico Hub
automation.hub_initialization_at_startup:
automation.initialization_at_startup_hub:
<<: *customize
friendly_name: Startup HUB
automation.guest_mode_hub:
Expand Down Expand Up @@ -423,31 +423,31 @@ script:
# VARIABLES
# --------------------------------------------- #
alexa: >-
{{alexa}}
{{alexa|default}}
called_number: >-
{{called_number}}
{{called_number|default}}
caption: >-
{{caption}}
{{caption|default}}
file: >-
{{file}}
{{file|default}}
google: >-
{{google}}
{{google|default}}
html: >-
{{html}}
{{html|default}}
link: >-
{{link}}
{{link|default}}
location: >-
{{location}}
{{location|default}}
no_show: >-
{{no_show}}
{{no_show|default}}
notify: >-
{{notify}}
{{notify|default}}
priority: >-
{{priority}}
{{priority|default}}
title: >-
{{title}}
{{title|default}}
url: >-
{{url}}
{{url|default}}
#-------------------------------------------------------------------------------#
# FILE TO BE INCLUDED IF MACROS ARE USED - NOTE: DO NOT MODIFY THE .yml EXTENSION
#-------------------------------------------------------------------------------#
Expand All @@ -468,7 +468,7 @@ automation:
#----------------------------------------------------------------------------------------------------#
# INITIALIZE
#----------------------------------------------------------------------------------------------------#
- alias: Hub initialization at startup
- alias: Initialization At Startup Hub
initial_state: true
trigger:
- platform: homeassistant
Expand Down Expand Up @@ -530,10 +530,10 @@ automation:
data:
object_id: "automations_notification_hub"
entities: >
{%for item in states.automation if ((item.attributes.id|lower).endswith('hub'))
or ((item.attributes.friendly_name|lower).endswith('hub')) %}
{%for item in states.automation if (item.attributes.id is defined
and (item.attributes.id|lower).endswith('hub'))
or (item.attributes.friendly_name|lower).endswith('hub') %}
{{-item.entity_id}}{%if not loop.last%},{%endif-%}{%endfor%}
# Execute auto_volume_hub Automation.
- service: automation.trigger
entity_id: automation.auto_volume_hub
Expand Down

0 comments on commit 7173608

Please sign in to comment.