For some reason I cannot explain the below automation does not work (error created by the condition under the action). The idea of the automation is that the house goes to sleep and only when a door is left open it also warns me about that open door.
The condition under the action is a working condition in my alarm automation so it is somehow related to the nesting of the condition under that action.
Error: 2017-06-27 09:40:57 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->action->2->condition. (See /home/hass/.homeassistant/configuration.yaml, line 260). Please check the docs at https://home-assistant.io/components/automation/
It’s not the solution but this workaround might be more interesting though as it allows you to get directly the name of the opened window (not sure about YAML syntax)
action:
- service: tts.google_say
entity_id: media_player.family_room_home
data_template:
message: >-
Goognight and sleep well
{ % if is_state('binary_sensor.YOURBINARYSENSOR', 'on') %}
Attention, the XXX window is open
{ % elif is_state('binary_sensor.YOURBINARYSENSOR', 'on') %}
Attention, the XXX window is open
{ % elif is_state('binary_sensor.YOURBINARYSENSOR', 'on') %}
Attention, the XXX window is open
{ % endif %}
cache: false
- service: input_boolean.turn_off
data:
entity_id: input_boolean.sfeeruit
- service: notify.mypushover
data_template:
message: "{{ trigger.to_state.attributes.friendly_name }}"
title: "Alarm"
As a bonus, I would also change the line > goodnight and sleep well to add more character to the tts
message: >-
{{ [
"Good night and sleep well. " ,
"See you soon. " ,
"Have a nice dream. " ,
"Hush baby don't say a word, and nevermind those words you heard, it's just the beast under your bed, in your closet, in your head... "
"Basically anything you want it to say when you go to sleep "
] |random }}
Like this solution so directly implented. However get an error. As I’m really bad in JINJA templating I’m not sure what is wrong:
017-06-27 12:51:32 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: unexpected '%') for dictionary value @ data['action'][0]['data_template']['message']. Got None. (See /home/hass/.homeassistant/configuration.yaml, line 260). Please check the docs at https://home-assistant.io/components/automation/
action:
- service: tts.google_say
entity_id: media_player.family_room_home
data_template:
message: >-
Goognight and sleep well
{{ % if is_state('binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_16_0', 'on') %}}
Attention, the door to the front garden is open
{{ % elif is_state('binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_19_0', 'on') %}}
Attention, the pantry door is open
{{ % elif is_state('binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_24_0', 'on') %}}
Attention, the main kitchen door is open
{{ % elif is_state('binary_sensor.fibaro_system_fgk101_door_opening_sensor_sensor_33_0', 'on') %}}
Attention, terras door in room Gitte is open
{{ % elif is_state('binary_sensor.sensative_strips_sensor_8_0', 'on') %}}
Attention, the door in TV room is open
{{ % elif is_state('binary_sensor.aeotec_zw112_door_window_sensor_6_sensor_24_0', 'on') %}}
Attention, the door in the office is open
{{ % elif is_state('binary_sensor.__sensor_25_0', 'on') %}}
Attention, the frontdoor is open
{{ % endif %}}
cache: false
My bad, try with only one pair of { } and not {{ … }}
Or try this, it think both solutions will do the trick
message: >-
Goognight and sleep well
{{ 'Attention, the door to the front garden is open' if is_state('binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_16_0', 'on') }}
{{ 'Attention, the pantry door is open' if is_state('binary_sensor.chromagic_technologies_corporation_hsm02_mini_doorwindow_detector_sensor_19_0', 'on') }}
cache: flase