Date day and month in another language

Would it be possible to have the month and day in my language? pt-br?

- data_template:
      message: 'Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S").strftime("%A, em %d de %B") }}'
    entity_id: media_player.living_room_speaker

So, I’ve seen threads like this before. The all usually end up with a bunch of if statements or a mapper.

Below I have 2 lists, 1 for weekday and 1 for months. I put everything in english because I couldn’t find the weekdays/months in pt-br (I didn’t look that hard but you can replace the words).

Essentially what we are doing is using a datetime object to gather the months and days as integers. Then use those integers as indexes to pull from our list ‘mappers’.

weekday does not need to be offset by 1, month does.

data_template:
  message: >
    {% set weekday = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] %}
    {% set months = ["January", "February","March","April","May","June","July","August","September","October","November","December"] %}
    {% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}
    Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}
1 Like

Thank you! Perfect what you said
But when I try to implement in my automation I get error.

- delay: 00:00:07
  data_template:
  message: >
    {% set weekday = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] %}{% set months = ["January", "February","March","April","May","June","July","Agosto","September","October","November","December"] %}{% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}
  entity_id: media_player.living_room_speaker
  service: tts.google_say

Invalid config for [automation]: [data_template] is an invalid option for [automation]. Check: automation->data_template. (See /config/configuration.yaml, line 221). Please check the docs at https://home-assistant.io/components/automation/

My complete automation

- id: '1529625339241'
  alias: Acordando
  trigger:
  - at: 08:40:00
    platform: time
  condition: []
  action:
  - data_template:
      message: Bom dia! Voçê dormiu bem ?
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:05
  - data_template:
      message: A temperatura em Duque de Caxias é de {{states('sensor.yweather_temperature')}}graus.
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:07
  - data_template:
      message: Iniciei o preparo do seu café ás 8:11
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:07
  - condition: state
    entity_id: calendar.contacts
    state: 'off'
  - data_template:
      message: Hoje é  {{  states.calendar.contacts.attributes.message}}
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:07
  - condition: state
    entity_id: calendar.homeassistant
    state: 'off'
  - data_template:
      message: 'Você me pediu para te lembrar hoje de:  {{  states.calendar.homeassistant.attributes.message}}'
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:07
  data_template:
  message: >
    {% set weekday = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] %}{% set months = ["January", "February","March","April","May","June","July","Agosto","September","October","November","December"] %}{% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}
  entity_id: media_player.living_room_speaker
  service: tts.google_say

I was able to remove the error. But it does not enter the part of the code. That is, do not read the next holiday.

- id: '1529625339241'
  alias: Acordando
  trigger:
  - at: 08:40:00
platform: time
  condition: []
  action:
  - data_template:
  message: Bom dia! Voçê dormiu bem ?
entity_id: media_player.living_room_speaker
service: tts.google_say
  - delay: 00:00:05
  - data_template:
  message: A temperatura em Duque de Caxias é de {{states('sensor.yweather_temperature')}}graus.
entity_id: media_player.living_room_speaker
service: tts.google_say
  - delay: 00:00:07
  - data_template:
  message: Iniciei o preparo do seu café ás 8:11
entity_id: media_player.living_room_speaker
service: tts.google_say
  - delay: 00:00:07
  - condition: state
entity_id: calendar.contacts
state: 'off'
  - data_template:
  message: Hoje é  {{  states.calendar.contacts.attributes.message}}
entity_id: media_player.living_room_speaker
service: tts.google_say
  - delay: 00:00:07
  - condition: state
entity_id: calendar.homeassistant
state: 'off'
  - data_template:
  message: 'Você me pediu para te lembrar hoje de:  {{  states.calendar.homeassistant.attributes.message}}'
entity_id: media_player.living_room_speaker
service: tts.google_say
  - delay: 00:00:07
  - data_template:
  message: >
   '{% set months = ["Janeiro", "Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"] %}{% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}
   Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}'
entity_id: media_player.living_room_speaker
service: tts.google_say

I tried that. It’s all ok in the code. There is no criticism. Validated.

However, it does not enter into this action.

- data_template:
      message: '{% set months = ["Janeiro", "Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"] %}{% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}'
    entity_id: media_player.living_room_speaker
    service: tts.google_say

Because your spacing is bad:

- data_template:
    message: '{% set months = ["Janeiro", "Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"] %}{% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}'
    entity_id: media_player.living_room_speaker
  service: tts.google_say

Once again. Thanks for helping me.

But, I believe that the problem is not spaces … For simplicity I created a simple automation. to test and still not read anything. He’s speechless.
Remembering tss is ok. The other readings work …

- id: '1530655367021'
  alias: teste
  trigger:
  - at: '8:20'
    platform: time
  condition: []
  action:
  data_template:
  message: >
    '{% set weekday = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] %}
    {% set months = ["January", "February","March","April","May","June","July","August","September","October","November","December"] %}
    {% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}
    Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}'
  entity_id: media_player.living_room_speaker
  service: tts.google_say

Log.

Invalid config for [automation]: [data_template] is an invalid option for [automation]. Check: automation->data_template. (See /config/configuration.yaml, line 221). Please check the docs at https://home-assistant.io/components/automation/

Believe. I tried everything of my knowledge. I do not know how to solve it. I tried several options.
I look forward to your guidance.

Finally I left it this way. I have this error message

Invalid config for [automation]: [data_template] is an invalid option for [automation]. Check: automation->data_template. (See /config/configuration.yaml, line 221). Please check the docs at https://home-assistant.io/components/automation/

- id: '1530655367021'
  alias: teste
  trigger:
  - at: '7:00'
    platform: time
  condition: []
  action:
  data_template:
    message: >
      {% set weekday = ['Segunda','terça','Quarta','Quinta','Sexta','Sabado','Domingo'] %}{% set months = ["Janeiro", "February","March","April","May","June","July","Agosto","September","October","November","December"] %}{% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}
  service: tts.google_say
  entity_id: media_player.living_room_speaker

It’s your spacing…

yaml is very space dependent.

- id: '1530655367021'
  alias: teste
  trigger:
    - at: '07:00:00'
      platform: time
  action:
    - service: tts.google_say
      entity_id: media_player.living_room_speaker
      data_template:
        message: >
          {% set weekday = ['Segunda','terça','Quarta','Quinta','Sexta','Sabado','Domingo'] %}{% set months = ["Janeiro", "February","March","April","May","June","July","Agosto","September","October","November","December"] %}{% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time, "%Y-%m-%d  %H:%M:%S") %}Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1] }}
    
        
1 Like

Thank you so much for not leaving me !!
It’s working! Now I just need to do an if and else.
Well, I do not want to go into a reading if there’s nothing to be said. For example, this reading.

  - data_template:
      message: Hoje é  {{  states.calendar.contacts.attributes.message}}
    entity_id: media_player.living_room_speaker
    service: tts.google_say

This too, I would like to enter into it only if I have something to be said.

- data_template:
      message: 'Você me pediu para te lembrar hoje de:  {{  states.calendar.homeassistant.attributes.message}}'
    entity_id: media_player.living_room_speaker
    service: tts.google_say

If I work with condition. When it is not satisfied it does not execute the rest of the block.
Could you help me with this question?

- id: '1529625339241'
  alias: Acordando
  trigger:
  - at: 08:40:00
    platform: time
  condition: []
  action:
  - data_template:
      message: Bom dia!
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:05
  - data_template:
      message: A temperatura em Duque de Caxias é de {{states('sensor.yweather_temperature')}}graus.
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:07
  - data_template:
      message: Iniciei o preparo do seu café ás 8:11
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:07
  - condition: state
    entity_id: calendar.contacts
    state: 'off'
  - data_template:
      message: Hoje é  {{  states.calendar.contacts.attributes.message}}
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:07
  - condition: state
    entity_id: calendar.homeassistant
    state: 'on'
  - data_template:
      message: 'Você me pediu para te lembrar hoje de:  {{  states.calendar.homeassistant.attributes.message}}'
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:07
  - data_template:
      message: '{% set weekday = [''Segunda'',''terça'',''Quarta'',''Quinta'',''Sexta'',''Sabado'',''Domingo'']
        %}{% set months = ["Janeiro", "Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"]
        %}{% set dt = strptime (states.calendar.feriados_no_brasil.attributes.start_time,
        "%Y-%m-%d  %H:%M:%S") %}Próximo feriado {{ states.calendar.feriados_no_brasil.attributes.message
        }} cai {{ weekday[dt.weekday()] }}, em {{ dt.day }} de {{ months[dt.month-1]
        }}'
    entity_id: media_player.living_room_speaker
    service: tts.google_say

I figured out how to do the if and else. But I do not know how to enter in my automation.

    {% if is_state("calendar.contacts", "off")  -%}

true

    {%- else -%}

    falso 

    {%- endif %}

Was it that way?

(...)
- delay: 00:00:02
  - data_template:
      message: A temperatura em Duque de Caxias é de {{states('sensor.yweather_temperature')}}graus.
    entity_id: media_player.living_room_speaker
    service: tts.google_say
  - delay: 00:00:6
  - data_template:
      message: Iniciei o preparo do seu café ás 8:11
    entity_id: media_player.living_room_speaker
    service: tts.google_say

- data_template: # or - service_template 
   {% if is_state("calendar.contacts", "off")  -%}
- data_template:
      message: Hoje é  {{  states.calendar.contacts.attributes.message}}
    entity_id: media_player.living_room_speaker
    service: tts.google_say
{%- else -%}
- data_template:
      message: 'Você me pediu para te lembrar hoje de:  {{  states.calendar.homeassistant.attributes.message}}'
    entity_id: media_player.living_room_speaker
    service: tts.google_say

you want the whole automation to not do anything if calendar.contacts is off? Or just bits of the automation?

Only pieces …
Because I have read several calendars. Some may this on others not.

Do not feel like I read “Today is …” birthday. If there are no birthday members on this day. However, I just wanted to skip this tts and read the next ones.

then use a condition as a service line in your script. What you posted has them all over the place. Thats all you can really do if you want to turn off individual ones. But remember, if the condition fails, the whole automation will stop. You may want to investigate using a python script or something more advanced.

1 Like

Thank you for your support.

So. If I use a simple condition and it is not answered, all remaining code will be ignored.
I thought with if and else, I can check and sign in only if a condition is true.
Example if the calendar.contacts is “on” I read (by tts) … otherwise I’ll go to the next one.

So I can not do it for automation .... right?

summarizing I would like to skip an action if it is “off” and continue reading the automation … and jumping the calendars off and reading the rest.

A condition in a script does indeed cause all remaining steps of the script to be skipped if the condition evaluates to false. Also, the actions of an automation are effectively a script - they behave the same as the sequence of actions in a script.

If you want some pieces of a script to run and others to be skipped, the script component does not really provide that functionality. It’s just a limitation of the current HA script component implementation. There is no if/then/else construct available at the scripting level.

The best way I found to handle this is to have a script call other scripts. Then you can break your big script into smaller scripts, where each smaller script uses a unique condition for its corresponding steps/actions.

For example, you can do something like this:

script:
  script_a_part_1:
    sequence:
      # Use a condition that applies only to ALL the steps in this sub-script.
      - condition: ...
        ...
      # Run the following actions only if the above condition evaluates to true.
      - service: ...
  script_a_part_2:
    sequence:
      # Use a condition that applies only to ALL the steps in this sub-script.
      - condition: ...
        ...
      # Run the following actions only if the above condition evaluates to true.
      - service: ...
  script_a_part_3:
    sequence:
      # Use a condition that applies only to ALL the steps in this sub-script.
      - condition: ...
        ...
      # Run the following actions only if the above condition evaluates to true.
      - service: ...
  script_a:
    sequence:
      # Run all the individual parts.
      - service: script.script_a_part_1
      - service: script.script_a_part_2
      - service: script.script_a_part_3

In your automation you call script.script_a, and it will call the individual pieces.

One thing to be careful about if you use this technique: when script.script_a starts the other scripts, they will all run “in parallel.” If you need them to run sequentially, then it gets a bit more complex.

1 Like