Skip to content

Instantly share code, notes, and snippets.

@ignacio82
Forked from rokam/tts-door-opening.yaml
Last active August 31, 2022 03:35
Show Gist options
  • Save ignacio82/d0271f98a14f28a60b9149a7594d2acf to your computer and use it in GitHub Desktop.
Save ignacio82/d0271f98a14f28a60b9149a7594d2acf to your computer and use it in GitHub Desktop.

Revisions

  1. ignacio82 revised this gist Aug 31, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -92,6 +92,8 @@ trigger:
    entity_id: !input 'door_sensor'
    to: 'on'
    action:
    - condition: template
    value_template: "{{ (now() | as_timestamp) - (trigger.from_state.last_changed | as_timestamp) > 5 }}"
    - condition: state
    entity_id: !input 'condition'
    state: "on"
  2. ignacio82 revised this gist Aug 30, 2022. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -58,11 +58,11 @@ blueprint:
    entity:
    domain: media_player
    condition:
    name: Condition to run
    description: 'Add a value_template value for major condition to execute the automation'
    default: 'True'
    name: Condition
    description: 'A binary sensor for the condition. The automation will run if the switch state is on'
    selector:
    text:
    entity:
    domain: binary_sensor
    actions:
    name: Additional actions
    description: 'After the execution of the automation, run those actions.'
    @@ -92,8 +92,9 @@ trigger:
    entity_id: !input 'door_sensor'
    to: 'on'
    action:
    - condition: template
    value_template: !input 'condition'
    - condition: state
    entity_id: !input 'condition'
    state: "on"
    - condition: template
    value_template: "{{ persons_count|length > 0 }}"
    - service: tts.google_say
  3. ignacio82 revised this gist Aug 27, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    blueprint:
    name: TTS on door opening with persons at home
    name: Welcome on door opening with persons at home
    description: Sends TTS message to a media_player when door is oppened with the person
    at home
    domain: automation
    @@ -96,7 +96,7 @@ action:
    value_template: !input 'condition'
    - condition: template
    value_template: "{{ persons_count|length > 0 }}"
    - service: tts.google_translate_say
    - service: tts.google_say
    data:
    entity_id: !input 'target'
    message: "{%- set single_lst = single_msg.split('\\n') -%}\n{%- set multiple_lst\
  4. @rokam rokam revised this gist Jun 23, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -96,7 +96,7 @@ action:
    value_template: !input 'condition'
    - condition: template
    value_template: "{{ persons_count|length > 0 }}"
    - service: tts.google_say
    - service: tts.google_translate_say
    data:
    entity_id: !input 'target'
    message: "{%- set single_lst = single_msg.split('\\n') -%}\n{%- set multiple_lst\
  5. @rokam rokam revised this gist Jul 17, 2021. 1 changed file with 46 additions and 29 deletions.
    75 changes: 46 additions & 29 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -49,46 +49,63 @@ blueprint:
    description: String to be used as concatenate between names
    default: ' and '
    selector:
    text: {}
    text:
    multiline: false
    target:
    name: Target devices
    description: Target devices to play the TTS message
    selector:
    entity:
    domain: media_player
    condition:
    name: Condition to run
    description: 'Add a value_template value for major condition to execute the automation'
    default: 'True'
    selector:
    text:
    actions:
    name: Additional actions
    description: 'After the execution of the automation, run those actions.'
    default: []
    selector:
    action: {}
    source_url: https://gist.github.com/rokam/22fd6e497fbe61478fda4d0fc8215abf
    variables:
    persons_str: !input persons
    persons_list: "{{ persons_str.split(',') | map('trim') | list }}"
    timeout: !input minutes
    concat_str: !input persons-concat
    persons_count: >
    {%- set first = true -%}
    {%- set data = namespace(nomes=[]) -%}
    {%- for person in persons_list -%}
    {%- if is_state(person, 'home') and (now() - states[person].last_changed).total_seconds() < timeout*60 -%}
    {%- set data.nomes = data.nomes + [states[person].name] -%}
    {%- endif -%}
    {%- endfor -%}
    {{ data.nomes }}
    persons_names: >
    {%- set finalstr = ', '.join(persons_count) -%}
    {{ concat_str.join(finalstr.rsplit(', ',1)) }}
    single_msg: !input message-single
    multiple_msg: !input message-multiple
    persons_str: !input 'persons'
    persons_list: '{{ persons_str.split('','') | map(''trim'') | list }}'
    timeout: !input 'minutes'
    concat_str: !input 'persons-concat'
    addactions: !input actions
    persons_count: "{%- set first = true -%} {%- set data = namespace(nomes=[]) -%}\
    \ {%- for person in persons_list -%}\n {%- if is_state(person, 'home') and (now()\
    \ - states[person].last_changed).total_seconds() < timeout*60 -%}\n {%- set\
    \ data.nomes = data.nomes + [states[person].name] -%}\n {%- endif -%}\n{%- endfor\
    \ -%} {{ data.nomes }}\n"
    persons_names: '{%- set finalstr = '', ''.join(persons_count) -%} {{ concat_str.join(finalstr.rsplit('',
    '',1)) }}
    '
    single_msg: !input 'message-single'
    multiple_msg: !input 'message-multiple'
    trigger:
    - platform: state
    entity_id: !input door_sensor
    entity_id: !input 'door_sensor'
    to: 'on'
    action:
    - condition: template
    value_template: !input 'condition'
    - condition: template
    value_template: "{{ persons_count|length > 0 }}"
    - service: tts.google_say
    data:
    entity_id: !input 'target'
    message: |
    {%- set single_lst = single_msg.split('\n') -%}
    {%- set multiple_lst = multiple_msg.split('\n') -%}
    {%- if persons_count|length > 1 -%}
    {{ multiple_lst | random | replace('<persons>', persons_names) }}
    {%- else -%}
    {{ single_lst | random | replace('<person>', persons_names) }}
    {%- endif -%}
    mode: single
    message: "{%- set single_lst = single_msg.split('\\n') -%}\n{%- set multiple_lst\
    \ = multiple_msg.split('\\n') -%}\n{%- if persons_count|length > 1 -%}\n {{\
    \ multiple_lst | random | replace('<persons>', persons_names) }}\n{%- elif persons_count|length > 0 -%}\n\
    \ {{ single_lst | random | replace('<person>', persons_names) }}\n{%- endif\
    \ -%}\n"
    - condition: template
    value_template: "{{ addactions|length > 0 }}"
    - choose: []
    default: !input 'actions'
    mode: single
  6. @rokam rokam revised this gist Jul 16, 2021. 1 changed file with 58 additions and 32 deletions.
    90 changes: 58 additions & 32 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -1,68 +1,94 @@
    blueprint:
    name: TTS on door opening with persons at home
    description: Sends TTS message to a media_player when door is oppened with the person at home
    description: Sends TTS message to a media_player when door is oppened with the person
    at home
    domain: automation
    input:
    door_sensor:
    name: Door sensors
    name: Door sensor
    selector:
    target:
    entity:
    domain: binary_sensor
    device_class: door
    entity:
    domain: binary_sensor
    device_class: door
    persons:
    name: Persons
    selector:
    target:
    entity:
    domain: person
    entity:
    domain: person
    minutes:
    name: Minutes
    description: Minutes between person at home and door trigged
    default: 5
    selector:
    number:
    min: 1
    max: 30
    step: 1
    unit_of_measurement: 'min'
    number:
    min: 1.0
    max: 30.0
    step: 1.0
    unit_of_measurement: min
    mode: slider
    message-single:
    name: Message single person
    description: >
    Message to salute single person. One possible message per line.
    description: 'Message to salute single person. One possible message per line.
    Use <person> tag to be replaced by person name.
    '
    selector:
    text:
    text:
    multiline: true
    message-multiple:
    name: Message multiple persons
    description: >
    Message multiple persons. One possible message per line.
    Use <persons> tag to be replaced by person name.
    description: 'Message multiple persons. One possible message per line. Use <persons>
    tag to be replaced by person name.
    '
    selector:
    text:
    multiline: true
    persons-concat:
    name: Text to concatenate the persons name
    description: String to be used as concatenate between names
    default: and
    default: ' and '
    selector:
    text:
    text: {}
    target:
    name: Target devices
    description: Target devices to play the TTS message
    selector:
    target:
    entity:
    domain: media_player
    entity:
    domain: media_player
    variables:
    persons_str: !input persons
    persons_list: "{{ persons_str.split(',') | map('trim') | list }}"
    timeout: !input minutes
    concat_str: !input persons-concat
    persons_count: >
    {%- set first = true -%}
    {%- set data = namespace(nomes=[]) -%}
    {%- for person in persons_list -%}
    {%- if is_state(person, 'home') and (now() - states[person].last_changed).total_seconds() < timeout*60 -%}
    {%- set data.nomes = data.nomes + [states[person].name] -%}
    {%- endif -%}
    {%- endfor -%}
    {{ data.nomes }}
    persons_names: >
    {%- set finalstr = ', '.join(persons_count) -%}
    {{ concat_str.join(finalstr.rsplit(', ',1)) }}
    single_msg: !input message-single
    multiple_msg: !input message-multiple
    trigger:
    - platform: state
    entity_id: !input 'door_sensor'
    to: 'on'
    - platform: state
    entity_id: !input door_sensor
    to: 'on'
    action:
    - service: tts.google_say
    data:
    entity_id: !input 'target'
    message: Em casa
    - service: tts.google_say
    data:
    entity_id: !input 'target'
    message: |
    {%- set single_lst = single_msg.split('\n') -%}
    {%- set multiple_lst = multiple_msg.split('\n') -%}
    {%- if persons_count|length > 1 -%}
    {{ multiple_lst | random | replace('<persons>', persons_names) }}
    {%- else -%}
    {{ single_lst | random | replace('<person>', persons_names) }}
    {%- endif -%}
    mode: single
  7. @rokam rokam revised this gist Jul 16, 2021. 1 changed file with 15 additions and 11 deletions.
    26 changes: 15 additions & 11 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -4,11 +4,18 @@ blueprint:
    domain: automation
    input:
    door_sensor:
    name: Door sensor
    name: Door sensors
    selector:
    entity:
    domain: binary_sensor
    device_class: door
    target:
    entity:
    domain: binary_sensor
    device_class: door
    persons:
    name: Persons
    selector:
    target:
    entity:
    domain: person
    minutes:
    name: Minutes
    description: Minutes between person at home and door trigged
    @@ -54,11 +61,8 @@ trigger:
    entity_id: !input 'door_sensor'
    to: 'on'
    action:
    - >
    {% for player in target %}
    - service: tts.google_say
    data:
    entity_id: {{ player }}
    message: Em casa
    {% endfor %}
    - service: tts.google_say
    data:
    entity_id: !input 'target'
    message: Em casa
    mode: single
  8. @rokam rokam revised this gist Jul 16, 2021. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -54,10 +54,11 @@ trigger:
    entity_id: !input 'door_sensor'
    to: 'on'
    action:
    {% for player in target %}
    - service: tts.google_say
    data:
    entity_id: {{ player }}
    message: Em casa
    {% endfor %}
    - >
    {% for player in target %}
    - service: tts.google_say
    data:
    entity_id: {{ player }}
    message: Em casa
    {% endfor %}
    mode: single
  9. @rokam rokam revised this gist Jul 16, 2021. 1 changed file with 25 additions and 18 deletions.
    43 changes: 25 additions & 18 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -1,39 +1,41 @@
    blueprint:
    name: TTS on door opening with persons at home
    description: Sends notification on low battery for DW2-Wifi
    description: Sends TTS message to a media_player when door is oppened with the person at home
    domain: automation
    input:
    door_sensors:
    name: Door sensors
    door_sensor:
    name: Door sensor
    selector:
    entity:
    domain: binary_sensor
    device_class: door
    persons:
    name: Persons
    selector:
    entity:
    domain: person
    minutes:
    name: Minutes
    description: Minutes between person at home and door trigged
    default: '12:00:00'
    default: 5
    selector:
    time: {}
    number:
    min: 1
    max: 30
    step: 1
    unit_of_measurement: 'min'
    mode: slider
    message-single:
    name: Message single person
    description: >
    Message to salute single person.
    Message to salute single person. One possible message per line.
    Use <person> tag to be replaced by person name.
    selector:
    text: {}
    text:
    multiline: true
    message-multiple:
    name: Message multiple persons
    description: >
    Message multiple persons.
    Message multiple persons. One possible message per line.
    Use <persons> tag to be replaced by person name.
    selector:
    text: {}
    text:
    multiline: true
    persons-concat:
    name: Text to concatenate the persons name
    description: String to be used as concatenate between names
    @@ -48,9 +50,14 @@ blueprint:
    entity:
    domain: media_player
    trigger:
    - platform: state
    entity_id: !input 'door_sensors'
    to: 'on'
    - platform: state
    entity_id: !input 'door_sensor'
    to: 'on'
    action:
    - choose: []
    {% for player in target %}
    - service: tts.google_say
    data:
    entity_id: {{ player }}
    message: Em casa
    {% endfor %}
    mode: single
  10. @rokam rokam revised this gist Jul 16, 2021. 1 changed file with 0 additions and 6 deletions.
    6 changes: 0 additions & 6 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -51,12 +51,6 @@ trigger:
    - platform: state
    entity_id: !input 'door_sensors'
    to: 'on'
    condition:
    - condition: numeric_state
    entity_id: !input 'door_sensor'
    attribute: battery_level
    below: !input 'threshold'
    action:
    - choose: []
    default: !input 'actions'
    mode: single
  11. @rokam rokam revised this gist Jul 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ blueprint:
    trigger:
    - platform: state
    entity_id: !input 'door_sensors'
    to: 'on'
    to: 'on'
    condition:
    - condition: numeric_state
    entity_id: !input 'door_sensor'
  12. @rokam rokam revised this gist Jul 16, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ blueprint:
    persons:
    name: Persons
    selector:
    entity: {}
    entity:
    domain: person
    minutes:
    name: Minutes
  13. @rokam rokam created this gist Jul 16, 2021.
    62 changes: 62 additions & 0 deletions tts-door-opening.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    blueprint:
    name: TTS on door opening with persons at home
    description: Sends notification on low battery for DW2-Wifi
    domain: automation
    input:
    door_sensors:
    name: Door sensors
    selector:
    entity:
    domain: binary_sensor
    device_class: door
    persons:
    name: Persons
    selector:
    entity: {}
    domain: person
    minutes:
    name: Minutes
    description: Minutes between person at home and door trigged
    default: '12:00:00'
    selector:
    time: {}
    message-single:
    name: Message single person
    description: >
    Message to salute single person.
    Use <person> tag to be replaced by person name.
    selector:
    text: {}
    message-multiple:
    name: Message multiple persons
    description: >
    Message multiple persons.
    Use <persons> tag to be replaced by person name.
    selector:
    text: {}
    persons-concat:
    name: Text to concatenate the persons name
    description: String to be used as concatenate between names
    default: and
    selector:
    text:
    target:
    name: Target devices
    description: Target devices to play the TTS message
    selector:
    target:
    entity:
    domain: media_player
    trigger:
    - platform: state
    entity_id: !input 'door_sensors'
    to: 'on'
    condition:
    - condition: numeric_state
    entity_id: !input 'door_sensor'
    attribute: battery_level
    below: !input 'threshold'
    action:
    - choose: []
    default: !input 'actions'
    mode: single